Skip to content

Commit

Permalink
Setuptools will install licenses if included in setup.cfg
Browse files Browse the repository at this point in the history
Addressing pypa#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 <[email protected]>
  • Loading branch information
dtaneli and poyzannur committed Oct 27, 2018
1 parent 1fb56a3 commit 930f20f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def _should_suppress_warning(msg):

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())
Expand Down
25 changes: 25 additions & 0 deletions setuptools/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,28 @@ def read_manifest(self):
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'.
"""

from configparser import ConfigParser
cfg_file = 'setup.cfg'
log.debug("Reading configuration from %s", cfg_file)
parser = ConfigParser()
parser.read(cfg_file)
license_file = parser.get('metadata', 'license_file', fallback=None)

if not license_file:
log.debug("license_file attribute is not defined in setup.cfg")
return

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)

0 comments on commit 930f20f

Please sign in to comment.