def test_info_verbose(pex, pex_tools_env): # type: (str, Dict[str, str]) -> None output = subprocess.check_output(args=[pex, "repository", "info", "-v"], env=pex_tools_env) infos = {} for line in output.decode("utf-8").splitlines(): info = json.loads(line) distribution = DistributionHelper.distribution_from_path(info["location"]) assert isinstance(distribution, Distribution) project_name = info["project_name"] assert distribution.project_name == project_name assert distribution.version == info["version"] infos[project_name] = info assert {"certifi", "chardet", "idna", "requests", "urllib3"} == set(infos.keys()) requests_info = infos["requests"] assert "2.25.1" == requests_info["version"] assert SpecifierSet("!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7") == SpecifierSet( requests_info["requires_python"] ) assert { Requirement.parse(req) for req in ( 'PySocks!=1.5.7,>=1.5.6; extra == "socks"', "certifi>=2017.4.17", "chardet<5,>=3.0.2", 'cryptography>=1.3.4; extra == "security"', "idna<3,>=2.5", 'pyOpenSSL>=0.14; extra == "security"', "urllib3<1.27,>=1.21.1", 'win-inet-pton; (sys_platform == "win32" and python_version == "2.7") and extra == "socks"', ) } == {Requirement.parse(req) for req in requests_info["requires_dists"]}
def test_requires_python( pip_tgz_sdist, # type: str pip_wheel, # type: str pip_distribution, # type: Distribution ): # type: (...) -> None expected_requires_python = SpecifierSet(">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*") assert expected_requires_python == requires_python(pip_tgz_sdist) assert expected_requires_python == requires_python(pip_wheel) assert expected_requires_python == requires_python(pip_distribution)
def parse_requirement_from_project_name_and_specifier( project_name, # type: str extras=None, # type: Optional[Iterable[str]] specifier=None, # type: Optional[SpecifierSet] marker=None, # type: Optional[Marker] ): # type: (...) -> Requirement requirement_string = "{project_name}{extras}{specifier}".format( project_name=project_name, extras="[{extras}]".format(extras=", ".join(extras)) if extras else "", specifier=specifier or SpecifierSet(), ) if marker: requirement_string += ";" + str(marker) return Requirement.parse(requirement_string)
def requires_python(dist): # type: (DistributionLike) -> Optional[SpecifierSet] """Examines dist for `Python-Requires` metadata and returns version constraints if any. See: https://www.python.org/dev/peps/pep-0345/#requires-python :param dist: A distribution to check for `Python-Requires` metadata. :return: The required python version specifiers. """ pkg_info = _parse_pkg_info(dist) if pkg_info is None: return None python_requirement = pkg_info.get("Requires-Python", None) if python_requirement is None: return None return SpecifierSet(python_requirement)
def requires_python(dist): # type: (Distribution) -> Optional[SpecifierSet] """Examines dist for `Python-Requires` metadata and returns version constraints if any. See: https://www.python.org/dev/peps/pep-0345/#requires-python :param dist: A distribution to check for `Python-Requires` metadata. :return: The required python version specifiers. """ if not dist.has_metadata(DistInfoDistribution.PKG_INFO): return None metadata = dist.get_metadata(DistInfoDistribution.PKG_INFO) pkg_info = email.parser.Parser().parsestr(metadata) python_requirement = pkg_info.get("Requires-Python") if not python_requirement: return None return SpecifierSet(python_requirement)
def requires_python(dist): """Examines dist for `Python-Requires` metadata and returns version constraints if any. See: https://www.python.org/dev/peps/pep-0345/#requires-python :param dist: A distribution to check for `Python-Requires` metadata. :type dist: :class:`pkg_resources.Distribution` :return: The required python version specifiers. :rtype: :class:`packaging.specifiers.SpecifierSet` or None """ if not dist.has_metadata(DistInfoDistribution.PKG_INFO): return None metadata = dist.get_metadata(DistInfoDistribution.PKG_INFO) pkg_info = email.parser.Parser().parsestr(metadata) python_requirement = pkg_info.get('Requires-Python') if not python_requirement: return None return SpecifierSet(python_requirement)
def _version_as_specifier(version): # type: (str) -> SpecifierSet try: return SpecifierSet("=={}".format(Version(version))) except InvalidVersion: return SpecifierSet("==={}".format(version))
def test_requires_python(): # type: () -> None with resolved_distribution("pex==2.1.21") as dist: assert SpecifierSet( ">=2.7,<=3.9,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" ) == requires_python(dist)