summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setuptools/command/egg_info.py1
-rw-r--r--setuptools/command/sdist.py25
2 files changed, 26 insertions, 0 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index bd116e1f..93100ab9 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -568,6 +568,7 @@ class manifest_maker(sdist):
def add_defaults(self):
sdist.add_defaults(self)
+ self.check_license()
self.filelist.append(self.template)
self.filelist.append(self.manifest)
rcfiles = list(walk_revctrl())
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