From 4716b6458a0663f7fd0337c2c431d152c77935ea Mon Sep 17 00:00:00 2001 From: amir Date: Tue, 23 Aug 2022 13:21:50 +0200 Subject: [PATCH] Fix nondeterminism with environment markers #5239 --- news/5239.bugfix.rst | 1 + pipenv/utils/resolver.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 news/5239.bugfix.rst diff --git a/news/5239.bugfix.rst b/news/5239.bugfix.rst new file mode 100644 index 0000000000..e1a4072254 --- /dev/null +++ b/news/5239.bugfix.rst @@ -0,0 +1 @@ +Fix nondeterminism with environment markers #5239 diff --git a/pipenv/utils/resolver.py b/pipenv/utils/resolver.py index 258e18929b..5896a63af2 100644 --- a/pipenv/utils/resolver.py +++ b/pipenv/utils/resolver.py @@ -5,7 +5,7 @@ import sys import warnings from functools import lru_cache -from typing import Dict, List, Optional, Set, Tuple, Union +from typing import Dict, List, Optional, Tuple, Union from pipenv import environments from pipenv.exceptions import RequirementError, ResolutionFailure @@ -189,12 +189,12 @@ def get_metadata( pre: bool = False, clear: bool = False, ) -> Tuple[ - Set[str], + Dict[str, str], Dict[str, Dict[str, Union[str, bool, List[str]]]], Dict[str, str], Dict[str, str], ]: - constraints: Set[str] = set() + constraints: Dict[str, str] = {} skipped: Dict[str, Dict[str, Union[str, bool, List[str]]]] = {} if index_lookup is None: index_lookup = {} @@ -247,7 +247,7 @@ def get_metadata( constraint_update, lockfile_update = self.get_deps_from_req( req, resolver=transient_resolver, resolve_vcs=project.s.PIPENV_RESOLVE_VCS ) - constraints |= constraint_update + constraints.update(constraint_update) skipped.update(lockfile_update) return constraints, skipped, index_lookup, markers_lookup @@ -309,7 +309,7 @@ def get_deps_from_req( req: Requirement, resolver: Optional["Resolver"] = None, resolve_vcs: bool = True, - ) -> Tuple[Set[str], Dict[str, Dict[str, Union[str, bool, List[str]]]]]: + ) -> Tuple[Dict[str, str], Dict[str, Dict[str, Union[str, bool, List[str]]]]]: from pipenv.vendor.requirementslib.models.requirements import Requirement from pipenv.vendor.requirementslib.models.utils import ( _requirement_to_str_lowercase_name, @@ -317,7 +317,7 @@ def get_deps_from_req( from pipenv.vendor.requirementslib.utils import is_installable_dir # TODO: this is way too complex, refactor this - constraints: Set[str] = set() + constraints: Dict[str, str] = {} locked_deps: Dict[str, Dict[str, Union[str, bool, List[str]]]] = {} editable_packages = self.project.get_editable_packages(dev=self.dev) if (req.is_file_or_url or req.is_vcs) and not req.is_wheel: @@ -365,12 +365,12 @@ def get_deps_from_req( new_req, resolver ) locked_deps.update(new_lock) - constraints |= new_constraints + constraints.update(new_constraints) # if there is no marker or there is a valid marker, add the constraint line elif r and (not r.marker or (r.marker and r.marker.evaluate())): if r.name not in editable_packages: line = _requirement_to_str_lowercase_name(r) - constraints.add(line) + constraints[line] = None # ensure the top level entry remains as provided # note that we shouldn't pin versions for editable vcs deps if not req.is_vcs: @@ -418,7 +418,7 @@ def get_deps_from_req( err=True, ) return constraints, locked_deps - constraints.add(req.constraint_line) + constraints[req.constraint_line] = None return constraints, locked_deps return constraints, locked_deps