diff --git a/pipenv/utils.py b/pipenv/utils.py index 1c026e3ad8..9d02f92be7 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -1072,38 +1072,6 @@ def handle_remove_readonly(func, path, exc): raise -def split_argument(req, short=None, long_=None, num=-1): - """Split an argument from a string (finds None if not present). - - Uses -short , --long , and --long=arg as permutations. - - returns string, index - """ - index_entries = [] - import re - - if long_: - index_entries.append("--{0}".format(long_)) - if short: - index_entries.append("-{0}".format(short)) - match_string = "|".join(index_entries) - matches = re.findall("(?<=\s)({0})([\s=])(\S+)".format(match_string), req) - remove_strings = [] - match_values = [] - for match in matches: - match_values.append(match[-1]) - remove_strings.append("".join(match)) - for string_to_remove in remove_strings: - req = req.replace(" {0}".format(string_to_remove), "") - if not match_values: - return req, None - if num == 1: - return req, match_values[0] - if num == -1: - return req, match_values - return req, match_values[:num] - - @contextmanager def atomic_open_for_write(target, binary=False, newline=None, encoding=None): """Atomically open `target` for writing. @@ -1187,10 +1155,7 @@ def get_vcs_deps( packages = getattr(project, section) except AttributeError: return [], [] - if not os.environ.get("PIP_SRC") and not project.virtualenv_location: - _src_dir = TemporaryDirectory(prefix="pipenv-", suffix="-src") - src_dir = Path(_src_dir.name) - else: + if os.environ.get("PIP_SRC"): src_dir = Path( os.environ.get("PIP_SRC", os.path.join(project.virtualenv_location, "src")) ) @@ -1199,8 +1164,8 @@ def get_vcs_deps( requirement = Requirement.from_pipfile(pkg_name, pkg_pipfile) name = requirement.normalized_name if requirement.is_vcs: - requirement.req.lock_vcs_ref() lockfile[name] = requirement.pipfile_entry[1] + lockfile[name]['ref'] = requirement.req.repo.get_commit_hash() reqs.append(requirement) return reqs, lockfile @@ -1219,17 +1184,26 @@ def translate_markers(pipfile_entry): if not isinstance(pipfile_entry, Mapping): raise TypeError("Entry is not a pipfile formatted mapping.") from notpip._vendor.distlib.markers import DEFAULT_CONTEXT as marker_context + from .vendor.packaging.markers import Marker + from .vendor.vistir.misc import dedup allowed_marker_keys = ["markers"] + [k for k in marker_context.keys()] provided_keys = list(pipfile_entry.keys()) if hasattr(pipfile_entry, "keys") else [] - pipfile_marker = next((k for k in provided_keys if k in allowed_marker_keys), None) + pipfile_markers = [k for k in provided_keys if k in allowed_marker_keys] new_pipfile = dict(pipfile_entry).copy() - if pipfile_marker: - entry = "{0}".format(pipfile_entry[pipfile_marker]) - if pipfile_marker != "markers": - entry = "{0} {1}".format(pipfile_marker, entry) - new_pipfile.pop(pipfile_marker) - new_pipfile["markers"] = entry + marker_set = set() + if "markers" in new_pipfile: + marker_set.add(str(Marker(new_pipfile.get("markers")))) + for m in pipfile_markers: + entry = "{0}".format(pipfile_entry[m]) + if m != "markers": + marker_set.add(str(Marker("{0}'{1}'".format(m, entry)))) + new_pipfile.pop(m) + marker_set.add(str(entry)) + if marker_set: + new_pipfile["markers"] = str(Marker(" or ".join(["{0}".format(s) + if " and " in s else s + for s in sorted(dedup(marker_set))]))) return new_pipfile diff --git a/pipenv/vendor/requirementslib/models/vcs.py b/pipenv/vendor/requirementslib/models/vcs.py index 79b9d610eb..3bfb05d5fd 100644 --- a/pipenv/vendor/requirementslib/models/vcs.py +++ b/pipenv/vendor/requirementslib/models/vcs.py @@ -1,6 +1,7 @@ # -*- coding=utf-8 -*- import attr -from pip_shims import VcsSupport +from pip_shims import VcsSupport, parse_version, pip_version +import vistir import os @@ -24,10 +25,11 @@ def get_repo_instance(self): def obtain(self): if not os.path.exists(self.checkout_directory): - self.repo_instance.unpack(self.checkout_directory) + self.repo_instance.obtain(self.checkout_directory) if self.ref: - self.update(self.ref) - self.commit_sha = self.get_commit_hash(self.ref) + with vistir.contextmanagers.cd(self.checkout_directory): + self.update(self.ref) + self.commit_sha = self.get_commit_hash() else: if not self.commit_sha: self.commit_sha = self.get_commit_hash() @@ -37,11 +39,18 @@ def checkout_ref(self, ref): if not self.repo_instance.is_commit_id_equal( self.checkout_directory, self.get_commit_hash(ref) ) and not self.repo_instance.is_commit_id_equal(self.checkout_directory, ref): - self.repo_instance.switch(self.checkout_directory, self.url, target_rev) + self.repo_instance.update(self.checkout_directory, self.url, target_rev) + self.commit_hash = self.get_commit_hash() def update(self, ref): target_rev = self.repo_instance.make_rev_options(ref) - self.repo_instance.update(self.checkout_directory, target_rev) + if parse_version(pip_version) > parse_version("18.0"): + self.repo_instance.update(self.checkout_directory, self.url, target_rev) + else: + self.repo_instance.update(self.checkout_directory, target_rev) + self.commit_hash = self.get_commit_hash() def get_commit_hash(self, ref=None): + if ref: + return self.repo_instance.get_revision(self.checkout_directory) return self.repo_instance.get_revision(self.checkout_directory) diff --git a/setup.cfg b/setup.cfg index f0cb3bf581..78140fa0c0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,6 +26,6 @@ lines_between_types=1 multi_line_output=5 not_skip=__init__.py known_first_party = - passa + pipenv tests ignore_trailing_comma=true