diff options
author | Deniz Taneli <7292227+dtaneli@users.noreply.github.com> | 2018-10-27 13:19:22 +0100 |
---|---|---|
committer | Deniz Taneli <7292227+dtaneli@users.noreply.github.com> | 2018-10-27 15:31:05 +0100 |
commit | ca0760af2071c333cda28d18279db95455ffa2de (patch) | |
tree | 9ccbd66c5cecbfa38981cdc29544fd72f2827921 /setuptools/command/sdist.py | |
parent | 1fb56a315f92e09d930ab7c2c787adbaead64d76 (diff) | |
download | python-setuptools-git-ca0760af2071c333cda28d18279db95455ffa2de.tar.gz |
Setuptools will install licenses if included in setup.cfg
Addressing #357
`python setup.py sdist` now includes the license file if `license_file`
is included in `setup.cfg` unless it is explicitly excluded in `MANIFEST.in`.
Co-Authored-By: Poyzan Nur Taneli <31743851+ptaneli@users.noreply.github.com>
Diffstat (limited to 'setuptools/command/sdist.py')
-rw-r--r-- | setuptools/command/sdist.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index bcfae4d8..a1b20733 100644 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -6,6 +6,7 @@ import io import contextlib from setuptools.extern import six +from setuptools.extern.six.moves import configparser from .py36compat import sdist_add_defaults @@ -198,3 +199,27 @@ class sdist(sdist_add_defaults, orig.sdist): continue self.filelist.append(line) manifest.close() + + def check_license(self): + """Read the setup configuration file ('setup.cfg') and use it to find + if a license is defined with the 'license_file' attribute. + If the license is declared and exists, it will be added to + 'self.filelist'. + """ + + cfg_file = 'setup.cfg' + log.debug("Reading configuration from %s", cfg_file) + parser = configparser.RawConfigParser() + parser.read(cfg_file) + try: + license_file = parser.get('metadata', 'license_file') + + if not os.path.exists(license_file): + log.warn("warning: Failed to find license file '%s' in setup.cfg", + license_file) + return + + self.filelist.append(license_file) + except configparser.Error: + log.debug("license_file attribute is not defined in setup.cfg") + return |