def finalize(): os.environ['PIP_SRC'] = fs_str(old_src_dir)
from pip_shims.shims import ( Command, InstallationCandidate, InstallRequirement, PackageFinder, ) TRequirement = TypeVar("TRequirement") RequirementType = TypeVar("RequirementType", covariant=True, bound=PackagingRequirement) MarkerType = TypeVar("MarkerType", covariant=True, bound=Marker) STRING_TYPE = Union[str, bytes, Text] S = TypeVar("S", bytes, str, Text) PKGS_DOWNLOAD_DIR = fs_str(os.path.join(CACHE_DIR, "pkgs")) WHEEL_DOWNLOAD_DIR = fs_str(os.path.join(CACHE_DIR, "wheels")) DEPENDENCY_CACHE = DependencyCache() @contextlib.contextmanager def _get_wheel_cache(): with pip_shims.shims.global_tempdir_manager(): yield pip_shims.shims.WheelCache( CACHE_DIR, pip_shims.shims.FormatControl(set(), set())) def _get_filtered_versions(ireq, versions, prereleases): return set(ireq.specifier.filter(versions, prereleases=prereleases))
def __init__(self, pypi=None, pipfile=True, chdir=False, path=None, home_dir=None, venv_root=None, ignore_virtualenvs=True, venv_in_project=True, name=None): self.pypi = pypi os.environ["PYTHONWARNINGS"] = "ignore:DEPRECATION" if ignore_virtualenvs: os.environ["PIPENV_IGNORE_VIRTUALENVS"] = fs_str("1") if venv_root: os.environ["VIRTUAL_ENV"] = venv_root if venv_in_project: os.environ["PIPENV_VENV_IN_PROJECT"] = fs_str("1") else: os.environ.pop("PIPENV_VENV_IN_PROJECT", None) self.original_dir = os.path.abspath(os.curdir) path = path if path else os.environ.get("PIPENV_PROJECT_DIR", None) if name is not None: path = Path(os.environ["HOME"]) / "projects" / name path.mkdir(exist_ok=True) if not path: path = TemporaryDirectory(suffix='-project', prefix='pipenv-') if isinstance(path, TemporaryDirectory): self._path = path path = Path(self._path.name) try: self.path = str(path.resolve()) except OSError: self.path = str(path.absolute()) elif isinstance(path, Path): self._path = path try: self.path = str(path.resolve()) except OSError: self.path = str(path.absolute()) else: self._path = path self.path = path # set file creation perms self.pipfile_path = None self.chdir = chdir if self.pypi: os.environ['PIPENV_PYPI_URL'] = fs_str('{0}'.format(self.pypi.url)) os.environ['PIPENV_TEST_INDEX'] = fs_str('{0}/simple'.format( self.pypi.url)) if pipfile: p_path = os.sep.join([self.path, 'Pipfile']) with open(p_path, 'a'): os.utime(p_path, None) self.chdir = False or chdir self.pipfile_path = p_path self._pipfile = _Pipfile(Path(p_path))
def start_resolver(finder=None, session=None, wheel_cache=None): """Context manager to produce a resolver. :param finder: A package finder to use for searching the index :type finder: :class:`~pip._internal.index.PackageFinder` :param :class:`~requests.Session` session: A session instance :param :class:`~pip._internal.cache.WheelCache` wheel_cache: A pip WheelCache instance :return: A 3-tuple of finder, preparer, resolver :rtype: (:class:`~pip._internal.operations.prepare.RequirementPreparer`, :class:`~pip._internal.resolve.Resolver`) """ pip_command = get_pip_command() pip_options = get_pip_options(pip_command=pip_command) session = None if not finder: session, finder = get_finder(pip_command=pip_command, pip_options=pip_options) if not session: session = pip_command._build_session(pip_options) download_dir = PKGS_DOWNLOAD_DIR _ensure_dir(download_dir) _build_dir = create_tracked_tempdir(fs_str("build")) _source_dir = create_tracked_tempdir(fs_str("source")) try: with ExitStack() as ctx: ctx.enter_context(pip_shims.shims.global_tempdir_manager()) if not wheel_cache: wheel_cache = ctx.enter_context(_get_wheel_cache()) _ensure_dir(fs_str(os.path.join(wheel_cache.cache_dir, "wheels"))) preparer = ctx.enter_context( pip_shims.shims.make_preparer( options=pip_options, finder=finder, session=session, build_dir=_build_dir, src_dir=_source_dir, download_dir=download_dir, wheel_download_dir=WHEEL_DOWNLOAD_DIR, progress_bar="off", build_isolation=False, install_cmd=pip_command, )) resolver = pip_shims.shims.get_resolver( finder=finder, ignore_dependencies=False, ignore_requires_python=True, preparer=preparer, session=session, options=pip_options, install_cmd=pip_command, wheel_cache=wheel_cache, force_reinstall=True, ignore_installed=True, upgrade_strategy="to-satisfy-only", isolated=False, use_user_site=False, ) yield resolver finally: session.close()
def __str__(self): return fs_str("{0}".format(self.path.as_posix()))
def __str__(self): # type: () -> str return fs_str("{0}".format(self.path.as_posix()))
def create( cls, path=None, # type: str system=False, # type: bool only_python=False, # type: bool global_search=True, # type: bool ignore_unsupported=True, # type: bool ): # type: (...) -> SystemPath """Create a new :class:`pythonfinder.models.SystemPath` instance. :param path: Search path to prepend when searching, defaults to None :param path: str, optional :param bool system: Whether to use the running python by default instead of searching, defaults to False :param bool only_python: Whether to search only for python executables, defaults to False :param bool ignore_unsupported: Whether to ignore unsupported python versions, if False, an error is raised, defaults to True :return: A new :class:`pythonfinder.models.SystemPath` instance. :rtype: :class:`pythonfinder.models.SystemPath` """ path_entries = defaultdict( PathEntry ) # type: DefaultDict[str, Union[PythonFinder, PathEntry]] paths = [] # type: List[str] if ignore_unsupported: os.environ["PYTHONFINDER_IGNORE_UNSUPPORTED"] = fs_str("1") if global_search: if "PATH" in os.environ: paths = os.environ["PATH"].split(os.pathsep) path_order = [] if path: path_order = [path] path_instance = ensure_path(path) path_entries.update( { path_instance.as_posix(): PathEntry.create( path=path_instance.absolute(), is_root=True, only_python=only_python, ) } ) paths = [path] + paths paths = [p for p in paths if not any(is_in_path(p, shim) for shim in SHIM_PATHS)] _path_objects = [ensure_path(p.strip('"')) for p in paths] paths = [p.as_posix() for p in _path_objects] path_entries.update( { p.as_posix(): PathEntry.create( path=p.absolute(), is_root=True, only_python=only_python ) for p in _path_objects } ) instance = cls( paths=path_entries, path_order=path_order, only_python=only_python, system=system, global_search=global_search, ignore_unsupported=ignore_unsupported, ) instance = instance._run_setup() return instance