Skip to content

Commit

Permalink
Fix nondeterminism with environment markers #5239 (#5286)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakhtiary authored Aug 25, 2022
1 parent 897caca commit 4b9fc02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions news/5239.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix nondeterminism with environment markers #5239
25 changes: 14 additions & 11 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +86,6 @@ def get_package_finder(


class HashCacheMixin:

"""Caches hashes of PyPI artifacts so we do not need to re-download them.
Hashes are only cached when the URL appears to contain a hash in it and the
Expand Down Expand Up @@ -189,12 +188,14 @@ def get_metadata(
pre: bool = False,
clear: bool = False,
) -> Tuple[
Set[str],
List[str],
Dict[str, Dict[str, Union[str, bool, List[str]]]],
Dict[str, str],
Dict[str, str],
]:
constraints: Set[str] = set()
constraints: Dict[
str, None
] = {} # Used Dict instead of Set because Dict is ordered and is hence stable
skipped: Dict[str, Dict[str, Union[str, bool, List[str]]]] = {}
if index_lookup is None:
index_lookup = {}
Expand Down Expand Up @@ -247,9 +248,9 @@ 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
return list(constraints.keys()), skipped, index_lookup, markers_lookup

def parse_line(
self,
Expand Down Expand Up @@ -309,15 +310,17 @@ 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, None], 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,
)
from pipenv.vendor.requirementslib.utils import is_installable_dir

# TODO: this is way too complex, refactor this
constraints: Set[str] = set()
constraints: Dict[
str, None
] = {} # Used Dict instead of Set because Dict is ordered and is hence stable
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:
Expand Down Expand Up @@ -365,12 +368,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:
Expand Down Expand Up @@ -418,7 +421,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

Expand Down

0 comments on commit 4b9fc02

Please sign in to comment.