Skip to content

Commit

Permalink
Fix parsing of named setup.py extras
Browse files Browse the repository at this point in the history
- Fixes #3230

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Nov 19, 2018
1 parent 324af26 commit dc89130
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/3230.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue which prevented the parsing of named extras sections from certain ``setup.py`` files.
36 changes: 30 additions & 6 deletions pipenv/vendor/requirementslib/models/setup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,41 @@ def get_metadata(path, pkg_name=None):
None,
)
if dist:
requires = dist.requires()
dep_map = dist._build_dep_map()
try:
requires = dist.requires()
except exception:
requires = []
try:
dep_map = dist._build_dep_map()
except Exception:
dep_map = {}
deps = []
extras = {}
for k in dep_map.keys():
if k is None:
deps.extend(dep_map.get(k))
continue
else:
extra = None
_deps = dep_map.get(k)
k = k.replace(":", "; ")
if k.startswith(":python_version"):
marker = k.replace(":", "; ")
else:
marker = ""
extra = "{0}".format(k)
_deps = [
pkg_resources.Requirement.parse("{0}{1}".format(str(req), k))
pkg_resources.Requirement.parse("{0}{1}".format(str(req), marker))
for req in _deps
]
deps.extend(_deps)
if extra:
extras[extra] = _deps
else:
deps.extend(_deps)
return {
"name": dist.project_name,
"version": dist.version,
"requires": requires,
"extras": extras
}


Expand All @@ -158,7 +174,6 @@ class SetupInfo(object):
name = attr.ib(type=str, default=None)
base_dir = attr.ib(type=Path, default=None)
version = attr.ib(type=packaging.version.Version, default=None)
extras = attr.ib(type=list, default=attr.Factory(list))
requires = attr.ib(type=dict, default=attr.Factory(dict))
build_requires = attr.ib(type=list, default=attr.Factory(list))
build_backend = attr.ib(type=list, default=attr.Factory(list))
Expand Down Expand Up @@ -288,6 +303,15 @@ def get_egg_metadata(self):
self.requires.update(
{req.key: req for req in metadata.get("requires", {})}
)
if getattr(self.ireq, "extras", None):
for extra in self.ireq.extras:
self.requires.update(
{
req.key: req for req
in metadata.get("extras", {}).get(extra)
if req is not None
}
)

def run_pyproject(self):
if self.pyproject and self.pyproject.exists():
Expand Down

0 comments on commit dc89130

Please sign in to comment.