def create( cls, project_name, # type: str target_python=None, # type: Optional[TargetPython] prefer_binary=False, # type: bool allow_all_prereleases=False, # type: bool specifier=None, # type: Optional[specifiers.BaseSpecifier] hashes=None, # type: Optional[Hashes] ): # type: (...) -> CandidateEvaluator """Create a CandidateEvaluator object. :param target_python: The target Python interpreter to use when checking compatibility. If None (the default), a TargetPython object will be constructed from the running Python. :param specifier: An optional object implementing `filter` (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable versions. :param hashes: An optional collection of allowed hashes. """ if target_python is None: target_python = TargetPython() if specifier is None: specifier = specifiers.SpecifierSet() supported_tags = target_python.get_tags() return cls( project_name=project_name, supported_tags=supported_tags, specifier=specifier, prefer_binary=prefer_binary, allow_all_prereleases=allow_all_prereleases, hashes=hashes, )
def test_get_tags__uses_cached_value(self): """ Test that get_tags() uses the cached value. """ target_python = TargetPython(py_version_info=None) target_python._valid_tags = ['tag-1', 'tag-2'] actual = target_python.get_tags() assert actual == ['tag-1', 'tag-2']
def test_get_tags__uses_cached_value(self) -> None: """ Test that get_tags() uses the cached value. """ target_python = TargetPython(py_version_info=None) target_python._valid_tags = [ Tag("py2", "none", "any"), Tag("py3", "none", "any"), ] actual = target_python.get_tags() assert actual == [Tag("py2", "none", "any"), Tag("py3", "none", "any")]
def test_get_tags(self, mock_get_supported, py_version_info): mock_get_supported.return_value = ['tag-1', 'tag-2'] target_python = TargetPython(py_version_info=py_version_info) actual = target_python.get_tags() assert actual == ['tag-1', 'tag-2'] actual = mock_get_supported.call_args[1]['version_info'] assert actual == py_version_info # Check that the value was cached. assert target_python._valid_tags == ['tag-1', 'tag-2']
def test_get_tags( self, mock_get_supported: mock.Mock, py_version_info: Optional[Tuple[int, ...]], expected_version: Optional[str], ) -> None: mock_get_supported.return_value = ["tag-1", "tag-2"] target_python = TargetPython(py_version_info=py_version_info) actual = target_python.get_tags() assert actual == ["tag-1", "tag-2"] actual = mock_get_supported.call_args[1]["version"] assert actual == expected_version # Check that the value was cached. assert target_python._valid_tags == ["tag-1", "tag-2"]
def create( cls, search_scope, # type: SearchScope selection_prefs, # type: SelectionPreferences trusted_hosts=None, # type: Optional[List[str]] session=None, # type: Optional[PipSession] target_python=None, # type: Optional[TargetPython] ): # type: (...) -> PackageFinder """Create a PackageFinder. :param selection_prefs: The candidate selection preferences, as a SelectionPreferences object. :param trusted_hosts: Domains not to emit warnings for when not using HTTPS. :param session: The Session to use to make requests. :param target_python: The target Python interpreter to use when checking compatibility. If None (the default), a TargetPython object will be constructed from the running Python. """ if session is None: raise TypeError( "PackageFinder.create() missing 1 required keyword argument: " "'session'") if target_python is None: target_python = TargetPython() supported_tags = target_python.get_tags() candidate_evaluator = CandidateEvaluator( supported_tags=supported_tags, prefer_binary=selection_prefs.prefer_binary, allow_all_prereleases=selection_prefs.allow_all_prereleases, ) return cls( candidate_evaluator=candidate_evaluator, search_scope=search_scope, session=session, target_python=target_python, allow_yanked=selection_prefs.allow_yanked, format_control=selection_prefs.format_control, trusted_hosts=trusted_hosts, ignore_requires_python=selection_prefs.ignore_requires_python, )
def __init__( self, supported_tags=None, # type: Optional[List[Pep425Tag]] prefer_binary=False, # type: bool allow_all_prereleases=False, # type: bool ): # type: (...) -> None """ :param supported_tags: The PEP 425 tags supported by the target Python in order of preference (most preferred first). If None, then the list will be generated from the running Python. :param allow_all_prereleases: Whether to allow all pre-releases. """ if supported_tags is None: target_python = TargetPython() supported_tags = target_python.get_tags() self._prefer_binary = prefer_binary self._supported_tags = supported_tags self.allow_all_prereleases = allow_all_prereleases