def test_dict_metadata_works(): name = "simple" version = "0.1.0" require_a = "a==1.0" require_b = "b==1.1; extra == 'also_b'" requires = [require_a, require_b, "c==1.2; extra == 'also_c'"] extras = ["also_b", "also_c"] requires_python = ">=3" metadata = Message() metadata["Name"] = name metadata["Version"] = version for require in requires: metadata["Requires-Dist"] = require for extra in extras: metadata["Provides-Extra"] = extra metadata["Requires-Python"] = requires_python inner_metadata = DictMetadata({ "METADATA": ensure_binary(metadata.as_string()) }) dist = DistInfoDistribution( location="<in-memory>", metadata=inner_metadata, project_name=name ) assert name == dist.project_name assert version == dist.version assert set(extras) == set(dist.extras) assert [Requirement.parse(require_a)] == dist.requires([]) assert [ Requirement.parse(require_a), Requirement.parse(require_b) ] == dist.requires(["also_b"]) assert metadata.as_string() == get_metadata(dist).as_string() assert requires_python == get_requires_python(dist)
def _get_requires_python_dependency(self) -> Optional[Requirement]: requires_python = get_requires_python(self.dist) if requires_python is None: return None try: spec = SpecifierSet(requires_python) except InvalidSpecifier as e: message = "Package %r has an invalid Requires-Python: %s" logger.warning(message, self.name, e) return None return self._factory.make_requires_python_requirement(spec)
def _check_dist_requires_python( dist, # type: pkg_resources.Distribution version_info, # type: Tuple[int, ...] ignore_requires_python=False, # type: bool ): # type: (...) -> None """ Check whether the given Python version is compatible with a distribution's "Requires-Python" value. :param version_info: The Python version to use to check, as a 3-tuple of ints (major-minor-micro). :param ignore_requires_python: Whether to ignore the "Requires-Python" value if the given Python version isn't compatible. :raises UnsupportedPythonVersion: When the given Python version isn't compatible. """ requires_python = get_requires_python(dist) try: is_compatible = check_requires_python( requires_python, version_info=version_info, ) except specifiers.InvalidSpecifier as exc: logger.warning( "Package %r has an invalid Requires-Python: %s", dist.project_name, exc, ) return if is_compatible: return version = '.'.join(map(str, version_info)) if ignore_requires_python: logger.debug( 'Ignoring failed Requires-Python check for package %r: ' '%s not in %r', dist.project_name, version, requires_python, ) return raise UnsupportedPythonVersion( 'Package {!r} requires a different Python: {} not in {!r}'.format( dist.project_name, version, requires_python, ))
def _get_requires_python_specifier(self): # type: () -> Optional[SpecifierSet] requires_python = get_requires_python(self.dist) if requires_python is None: return None try: spec = SpecifierSet(requires_python) except InvalidSpecifier as e: logger.warning( "Package %r has an invalid Requires-Python: %s", self.name, e, ) return None return spec
def _check_dist_requires_python( dist: Distribution, version_info: Tuple[int, int, int], ignore_requires_python: bool = False, ) -> None: """ Check whether the given Python version is compatible with a distribution's "Requires-Python" value. :param version_info: A 3-tuple of ints representing the Python major-minor-micro version to check. :param ignore_requires_python: Whether to ignore the "Requires-Python" value if the given Python version isn't compatible. :raises UnsupportedPythonVersion: When the given Python version isn't compatible. """ requires_python = get_requires_python(dist) try: is_compatible = check_requires_python( requires_python, version_info=version_info ) except specifiers.InvalidSpecifier as exc: logger.warning( "Package %r has an invalid Requires-Python: %s", dist.project_name, exc ) return if is_compatible: return version = ".".join(map(str, version_info)) if ignore_requires_python: logger.debug( "Ignoring failed Requires-Python check for package %r: %s not in %r", dist.project_name, version, requires_python, ) return raise UnsupportedPythonVersion( "Package {!r} requires a different Python: {} not in {!r}".format( dist.project_name, version, requires_python ) )
def test_none_requires_python(self, caplog): """ Test a dist with Requires-Python None. """ caplog.set_level(logging.DEBUG) dist = make_fake_dist() # Make sure our test setup is correct. assert get_requires_python(dist) is None assert len(caplog.records) == 0 # Then there is no exception and no log message. _check_dist_requires_python( dist, version_info=(3, 6, 5), ignore_requires_python=False, ) assert len(caplog.records) == 0
# type: () -> Distribution if self._dist is None: <<<<<<< HEAD self._prepare() return self._dist def _get_requires_python_dependency(self): # type: () -> Optional[Requirement] ======= self._fetch_metadata() return self._dist def _get_requires_python_specifier(self): # type: () -> Optional[SpecifierSet] >>>>>>> 74c061954d5e927be4caafbd793e96a50563c265 requires_python = get_requires_python(self.dist) if requires_python is None: return None try: spec = SpecifierSet(requires_python) except InvalidSpecifier as e: <<<<<<< HEAD message = "Package %r has an invalid Requires-Python: %s" logger.warning(message, self.name, e) return None return self._factory.make_requires_python_requirement(spec) def iter_dependencies(self, with_requires): # type: (bool) -> Iterable[Optional[Requirement]] requires = self.dist.requires() if with_requires else () for r in requires:
ignore_requires_python=False, # type: bool ): # type: (...) -> None """ Check whether the given Python version is compatible with a distribution's "Requires-Python" value. :param version_info: A 3-tuple of ints representing the Python major-minor-micro version to check. :param ignore_requires_python: Whether to ignore the "Requires-Python" value if the given Python version isn't compatible. :raises UnsupportedPythonVersion: When the given Python version isn't compatible. """ requires_python = get_requires_python(dist) try: is_compatible = check_requires_python( requires_python, version_info=version_info, ) except specifiers.InvalidSpecifier as exc: logger.warning( "Package %r has an invalid Requires-Python: %s", dist.project_name, exc, ) return if is_compatible: return version = '.'.join(map(str, version_info))