Skip to content

Commit

Permalink
Merge pull request #3256 from pypa/bugfix/3230
Browse files Browse the repository at this point in the history
Fix parsing of named `setup.py` extras
  • Loading branch information
techalchemy authored Nov 20, 2018
2 parents fb3bcf3 + 9b8b07b commit 06abcd0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 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.
39 changes: 31 additions & 8 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 @@ -247,8 +262,7 @@ def run_setup(self):
except NameError:
python = os.environ.get('PIP_PYTHON_PATH', sys.executable)
out, _ = run([python, "setup.py"] + args, cwd=target_cwd, block=True,
combine_stderr=False, return_object=False, nospin=True,
write_to_stdout=False)
combine_stderr=False, return_object=False, nospin=True)
finally:
_setup_stop_after = None
sys.argv = save_argv
Expand Down Expand Up @@ -288,6 +302,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 06abcd0

Please sign in to comment.