From 9583f41816c1af2cb11fc4b6b8e5ed8e978f4375 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Sun, 7 Aug 2022 23:22:05 -0400 Subject: [PATCH] latest changes to requirementslib. Revert back to vistir for create_tracked_tempfile. --- pipenv/utils/dependencies.py | 5 +- .../requirementslib/models/requirements.py | 63 ++++++++----------- .../requirementslib/models/setup_info.py | 4 +- tests/unit/test_utils.py | 2 +- 4 files changed, 32 insertions(+), 42 deletions(-) diff --git a/pipenv/utils/dependencies.py b/pipenv/utils/dependencies.py index bf6ccb3cee..cf38da7089 100644 --- a/pipenv/utils/dependencies.py +++ b/pipenv/utils/dependencies.py @@ -1,6 +1,5 @@ import os from contextlib import contextmanager -from tempfile import NamedTemporaryFile from typing import Mapping, Sequence from pipenv.patched.pip._vendor.packaging.markers import Marker @@ -272,7 +271,9 @@ def convert_deps_to_pip( return dependencies # Write requirements.txt to tmp directory. - f = NamedTemporaryFile(suffix="-requirements.txt", delete=False) + from pipenv.vendor.vistir.path import create_tracked_tempfile + + f = create_tracked_tempfile(suffix="-requirements.txt", delete=False) f.write("\n".join(dependencies).encode("utf-8")) f.close() return f.name diff --git a/pipenv/vendor/requirementslib/models/requirements.py b/pipenv/vendor/requirementslib/models/requirements.py index f3fc34e450..386fed74f5 100644 --- a/pipenv/vendor/requirementslib/models/requirements.py +++ b/pipenv/vendor/requirementslib/models/requirements.py @@ -558,25 +558,26 @@ def parse_extras(self): :rtype: :class:`~Line` """ extras = None - line = "{0}".format(self.line) - if any([self.is_vcs, self.is_url, "@" in line]): - try: - if self.parsed_url.name: - self._name = self.parsed_url.name - if ( - self.parsed_url.host - and self.parsed_url.path - and self.parsed_url.scheme - ): - self.line = self.parsed_url.to_string( - escape_password=False, - direct=False, - strip_ssh=self.parsed_url.is_implicit_ssh, - ) - except ValueError: + if not self.line: + line = "{0}".format(self.line) + if any([self.is_vcs, self.is_url, "@" in line]): + try: + if self.parsed_url.name: + self._name = self.parsed_url.name + if ( + self.parsed_url.host + and self.parsed_url.path + and self.parsed_url.scheme + ): + self.line = self.parsed_url.to_string( + escape_password=False, + direct=False, + strip_ssh=self.parsed_url.is_implicit_ssh, + ) + except ValueError: + self.line, extras = _strip_extras(self.line) + else: self.line, extras = _strip_extras(self.line) - else: - self.line, extras = _strip_extras(self.line) extras_set = set() # type: Set[STRING_TYPE] if extras is not None: extras_set = set(parse_extras(extras)) @@ -587,7 +588,6 @@ def parse_extras(self): extras_set |= name_extras if extras_set is not None: self.extras = tuple(sorted(extras_set)) - return self def get_url(self): # type: () -> STRING_TYPE @@ -850,14 +850,12 @@ def vcsrepo(self): self._vcsrepo = self._get_vcsrepo() return self._vcsrepo - @property + @cached_property def parsed_url(self): # type: () -> URI - if self._parsed_url is None: - self._parsed_url = URI.parse(self.line) - return self._parsed_url + return URI.parse(self.line) - @property + @cached_property def is_direct_url(self): # type: () -> bool try: @@ -1177,7 +1175,6 @@ def parse_link(self): self._link = parsed_link else: self._link = link - return self def parse_markers(self): # type: () -> None @@ -2523,7 +2520,10 @@ def get_line_instance(self): else: line_parts.append(self.req.line_part) if not self.is_vcs and not self.vcs and self.extras_as_pip: - line_parts.append(self.extras_as_pip) + if self.is_file_or_url: + line_parts.append(f"#egg={self.extras_as_pip}") + else: + line_parts.append(self.extras_as_pip) if self._specifiers and not (self.is_file_or_url or self.is_vcs): line_parts.append(self._specifiers) if self.markers: @@ -2545,16 +2545,7 @@ def get_line_instance(self): @property def line_instance(self): # type: () -> Optional[Line] - if self._line_instance is None: - self.line_instance = self.get_line_instance() - return self._line_instance - - @line_instance.setter - def line_instance(self, line_instance): - # type: (Line) -> None - if self.req: - self.req._parsed_line = line_instance - self._line_instance = line_instance + return self.get_line_instance() @property def specifiers(self): diff --git a/pipenv/vendor/requirementslib/models/setup_info.py b/pipenv/vendor/requirementslib/models/setup_info.py index 5184c953d4..656bf9cdc2 100644 --- a/pipenv/vendor/requirementslib/models/setup_info.py +++ b/pipenv/vendor/requirementslib/models/setup_info.py @@ -1532,9 +1532,7 @@ def from_ireq(cls, ireq, subdir=None, finder=None, session=None): uri = uri.replace("file:/", "file:///") path = url_to_path(uri) kwargs = _prepare_wheel_building_kwargs(ireq) - is_artifact_or_vcs = getattr( - ireq.link, "is_vcs", getattr(ireq.link, "is_artifact", False) - ) + is_artifact_or_vcs = getattr(ireq.link, "is_vcs", False) is_vcs = True if vcs else is_artifact_or_vcs download_dir = None if not (ireq.editable and is_file and is_vcs): diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 3aa22dbbb7..94b6721ed4 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -60,7 +60,7 @@ "extras": ["voice"], } }, - "https://github.com/Rapptz/discord.py/archive/async.zip#egg=discord.py[voice]", + "https://github.com/Rapptz/discord.py/archive/async.zip#egg=[voice]", ), ( {