From dc8913065fe4e167457434f71b74f393348b9327 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 19 Nov 2018 17:58:44 -0500 Subject: [PATCH 1/2] Fix parsing of named `setup.py` extras - Fixes #3230 Signed-off-by: Dan Ryan --- news/3230.bugfix.rst | 1 + .../requirementslib/models/setup_info.py | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 news/3230.bugfix.rst diff --git a/news/3230.bugfix.rst b/news/3230.bugfix.rst new file mode 100644 index 0000000000..f8295b55c8 --- /dev/null +++ b/news/3230.bugfix.rst @@ -0,0 +1 @@ +Fixed an issue which prevented the parsing of named extras sections from certain ``setup.py`` files. diff --git a/pipenv/vendor/requirementslib/models/setup_info.py b/pipenv/vendor/requirementslib/models/setup_info.py index cd3c347770..d86ddfb7bf 100644 --- a/pipenv/vendor/requirementslib/models/setup_info.py +++ b/pipenv/vendor/requirementslib/models/setup_info.py @@ -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 } @@ -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)) @@ -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(): From 9b8b07b562ff380ef998581a5ad411425efdd5c5 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 19 Nov 2018 18:16:00 -0500 Subject: [PATCH 2/2] Fix setup info Signed-off-by: Dan Ryan --- pipenv/vendor/requirementslib/models/setup_info.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pipenv/vendor/requirementslib/models/setup_info.py b/pipenv/vendor/requirementslib/models/setup_info.py index d86ddfb7bf..c32c279086 100644 --- a/pipenv/vendor/requirementslib/models/setup_info.py +++ b/pipenv/vendor/requirementslib/models/setup_info.py @@ -262,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