def get_versions(self): versions = defaultdict() bin_ = sysconfig._INSTALL_SCHEMES[ sysconfig._get_default_scheme()]["scripts"] for p in self.root.glob("versions/*"): if p.parent.name == "envs" or p.name == "envs": continue bin_dir = Path(bin_.format(base=p.as_posix())) version_path = None if bin_dir.exists(): version_path = PathEntry.create( path=bin_dir.absolute().as_posix(), only_python=False, name=p.name, is_root=True, ) version = None try: version = PythonVersion.parse(p.name) except ValueError: entry = next(iter(version_path.find_all_python_versions()), None) if not entry: if self.ignore_unsupported: continue raise else: version = entry.py_version.as_dict() except Exception: if not self.ignore_unsupported: raise logger.warning("Unsupported Python version %r, ignoring...", p.name, exc_info=True) continue if not version: continue version_tuple = ( version.get("major"), version.get("minor"), version.get("patch"), version.get("is_prerelease"), version.get("is_devrelease"), version.get("is_debug"), ) self.roots[p] = version_path versions[version_tuple] = version_path self.paths.append(version_path) return versions
def get_versions(self): from .path import PathEntry versions = defaultdict() bin_ = "{base}/bin" for p in self.get_version_order(): bin_dir = Path(bin_.format(base=p.as_posix())) version_path = None if bin_dir.exists(): version_path = PathEntry.create( path=bin_dir.absolute().as_posix(), only_python=False, name=p.name, is_root=True, ) version = None try: version = PythonVersion.parse(p.name) except (ValueError, InvalidPythonVersion): entry = next(iter(version_path.find_all_python_versions()), None) if not entry: if self.ignore_unsupported: continue raise else: version = entry.py_version.as_dict() except Exception: if not self.ignore_unsupported: raise logger.warning("Unsupported Python version %r, ignoring...", p.name, exc_info=True) continue if not version: continue version_tuple = ( version.get("major"), version.get("minor"), version.get("patch"), version.get("is_prerelease"), version.get("is_devrelease"), version.get("is_debug"), ) self.roots[p] = version_path versions[version_tuple] = version_path self.paths.append(version_path) return versions
def ensure_path(path): """Given a path (either a string or a Path object), expand variables and return a Path object. :param path: A string or a :class:`~pathlib.Path` object. :type path: str or :class:`~pathlib.Path` :return: A fully expanded Path object. :rtype: :class:`~pathlib.Path` """ if isinstance(path, Path): path = path.as_posix() path = Path(os.path.expandvars(path)) try: path = path.resolve() except OSError: path = path.absolute() return path
def is_installable_file(path): """Determine if a path can potentially be installed""" from packaging import specifiers if hasattr(path, "keys") and any( key for key in path.keys() if key in ["file", "path"]): path = urlparse(path["file"]).path if "file" in path else path["path"] if not isinstance(path, six.string_types) or path == "*": return False # If the string starts with a valid specifier operator, test if it is a valid # specifier set before making a path object (to avoid breaking windows) if any(path.startswith(spec) for spec in "!=<>~"): try: specifiers.SpecifierSet(path) # If this is not a valid specifier, just move on and try it as a path except specifiers.InvalidSpecifier: pass else: return False parsed = urlparse(path) if parsed.scheme == "file": path = parsed.path if not os.path.exists(os.path.abspath(path)): return False lookup_path = Path(path) absolute_path = "{0}".format(lookup_path.absolute()) if lookup_path.is_dir() and is_installable_dir(absolute_path): return True elif lookup_path.is_file() and pip_shims.shims.is_archive_file( absolute_path): return True return False
from hypothesis import given, settings, strategies as st from vistir.compat import Path from requirementslib.exceptions import RequirementError from requirementslib.models.requirements import Line, Requirement from requirementslib.models.setup_info import SetupInfo from .strategies import random_marker_strings, repository_line, requirements UNIT_TEST_DIR = os.path.dirname(os.path.abspath(__file__)) TEST_DIR = os.path.dirname(UNIT_TEST_DIR) ARTIFACTS_DIR = os.path.join(TEST_DIR, "artifacts") TEST_WHEEL = os.path.join(ARTIFACTS_DIR, "six", "six-1.11.0-py2.py3-none-any.whl") TEST_WHEEL_PATH = Path(TEST_WHEEL) TEST_WHEEL_URI = TEST_WHEEL_PATH.absolute().as_uri() TEST_PROJECT_RELATIVE_DIR = "tests/artifacts/six/six-1.11.0-py2.py3-none-any.whl" # Pipfile format <-> requirements.txt format. DEP_PIP_PAIRS = [ ({ "requests": "*" }, "requests"), ({ "requests": { "extras": ["socks"], "version": "*" } }, "requests[socks]"), ({ "django": ">1.10"