def get_default_pyproject_backend(): # type: () -> STRING_TYPE st_version = get_setuptools_version() if st_version is not None: parsed_st_version = parse_version(st_version) if parsed_st_version >= parse_version("40.8.0"): return "setuptools.build_meta:__legacy__" return "setuptools.build_meta"
def parse_python_version(version_str): # type: (str) -> Dict[str, Union[str, int, Version]] from pipenv.vendor.packaging.version import parse as parse_version is_debug = False if version_str.endswith("-debug"): is_debug = True version_str, _, _ = version_str.rpartition("-") match = version_re.match(version_str) if not match: raise InvalidPythonVersion("%s is not a python version" % version_str) version_dict = match.groupdict() # type: Dict[str, str] major = int(version_dict.get("major", 0)) if version_dict.get("major") else None minor = int(version_dict.get("minor", 0)) if version_dict.get("minor") else None patch = int(version_dict.get("patch", 0)) if version_dict.get("patch") else None is_postrelease = True if version_dict.get("post") else False is_prerelease = True if version_dict.get("prerel") else False is_devrelease = True if version_dict.get("dev") else False if patch: patch = int(patch) version = None # type: Optional[Union[Version, LegacyVersion]] try: version = parse_version(version_str) except TypeError: version = None if isinstance(version, LegacyVersion) or version is None: v_dict = version_dict.copy() pre = "" if v_dict.get("prerel") and v_dict.get("prerelversion"): pre = v_dict.pop("prerel") pre = "{0}{1}".format(pre, v_dict.pop("prerelversion")) v_dict["pre"] = pre keys = ["major", "minor", "patch", "pre", "postdev", "post", "dev"] values = [v_dict.get(val) for val in keys] version_str = ".".join([str(v) for v in values if v]) version = parse_version(version_str) return { "major": major, "minor": minor, "patch": patch, "is_postrelease": is_postrelease, "is_prerelease": is_prerelease, "is_devrelease": is_devrelease, "is_debug": is_debug, "version": version, }
def clean_requires_python(candidates): """Get a cleaned list of all the candidates with valid specifiers in the `requires_python` attributes.""" all_candidates = [] sys_version = ".".join(map(str, sys.version_info[:3])) from pipenv.vendor.packaging.version import parse as parse_version py_version = parse_version( os.environ.get("PIP_PYTHON_VERSION", sys_version)) for c in candidates: requires_python = _get_requires_python(c) if requires_python: # Old specifications had people setting this to single digits # which is effectively the same as '>=digit,<digit+1' if requires_python.isdigit(): requires_python = ">={0},<{1}".format(requires_python, int(requires_python) + 1) try: specifierset = SpecifierSet(requires_python) except InvalidSpecifier: continue else: if not specifierset.contains(py_version): continue all_candidates.append(c) return all_candidates
def get_packages_licenses(packages, licenses_db): """Get the licenses for the specified packages based on their version. :param packages: packages list :param licenses_db: the licenses db in the raw form. :return: list of objects with the packages and their respectives licenses. """ packages_licenses_db = licenses_db.get('packages', {}) filtered_packages_licenses = [] for pkg in packages: # Ignore recursive files not resolved if isinstance(pkg, RequirementFile): continue # normalize the package name pkg_name = pkg.key.replace("_", "-").lower() # packages may have different licenses depending their version. pkg_licenses = packages_licenses_db.get(pkg_name, []) version_requested = parse_version(pkg.version) license_id = None license_name = None for pkg_version in pkg_licenses: license_start_version = parse_version(pkg_version['start_version']) # Stops and return the previous stored license when a new # license starts on a version above the requested one. if version_requested >= license_start_version: license_id = pkg_version['license_id'] else: # We found the license for the version requested break if license_id: license_name = get_license_name_by_id(license_id, licenses_db) if not license_id or not license_name: license_name = "N/A" filtered_packages_licenses.append({ "package": pkg_name, "version": pkg.version, "license": license_name }) return filtered_packages_licenses
def clean_requires_python(candidates): """Get a cleaned list of all the candidates with valid specifiers in the `requires_python` attributes.""" all_candidates = [] py_version = parse_version(os.environ.get('PIP_PYTHON_VERSION', '.'.join(map(str, sys.version_info[:3])))) for c in candidates: if getattr(c, "requires_python", None): # Old specifications had people setting this to single digits # which is effectively the same as '>=digit,<digit+1' if len(c.requires_python) == 1 and c.requires_python in ("2", "3"): c.requires_python = '>={0},<{1!s}'.format(c.requires_python, int(c.requires_python) + 1) try: specifierset = SpecifierSet(c.requires_python) except InvalidSpecifier: continue else: if not specifierset.contains(py_version): continue all_candidates.append(c) return all_candidates
def parse_version(cls, version): return parse_version(version)