Since setuptools
42.0.0 you can use the license_files
key to specify a list of license files to be included into a distribution. Since version 56.0.0 it supports pattern matching and defaults to ('LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*')
.
Note that due to implementation details there's actually no need to put this key into setup.cfg
file (as another answer suggests). You could supply it as an argument to setup()
function instead:
(documentation was unclear on this at the time of writing)
from setuptools import setup
setup(
...
license_files = ('LICENSE.txt',),
...
)
Also note that while these files will be included in both binary (wheel) and source distributions, they won't be installed with your package from setup.py
-style source distribution if the user doesn't have a wheel
package installed!
To ensure the license files will be installed along with your package you need to make some additional modifications to your setup script:
from setuptools import setup
from setuptools.command.egg_info import egg_info
class egg_info_ex(egg_info):
"""Includes license file into `.egg-info` folder."""
def run(self):
# don't duplicate license into `.egg-info` when building a distribution
if not self.distribution.have_run.get('install', True):
# `install` command is in progress, copy license
self.mkpath(self.egg_info)
self.copy_file('LICENSE.txt', self.egg_info)
egg_info.run(self)
setup(
...
license_files = ('LICENSE.txt',),
cmdclass = {'egg_info': egg_info_ex},
...
)
If your project is a pyproject.toml
-style project and you think it will be installed by PEP 517-compatible frontend (e.g. pip>=19
), a wheel will be forcibly built from your sources and the license files will be installed into .dist-info
folder automatically.
Since version 61.0.0 you could specify project metadata and other configuration options in pyproject.toml
file instead.