pip_shims.shims

Main module with magic self-replacement mechanisms to handle import speedups.

class pip_shims.shims.SessionCommandMixin[source]

Bases: pip._internal.cli.command_context.CommandContextMixIn

A class mixin for command classes needing _build_session().

get_default_session(options)[source]

Get a default-managed session.

class pip_shims.shims.Command(name='Default pip command.', summary='PipCommand', isolated='Default pip command.')[source]

Bases: pip._internal.cli.base_command.Command, pip._internal.cli.req_command.SessionCommandMixin

get_default_session(options)

Get a default-managed session.

handle_pip_version_check(options)[source]

This is a no-op so that commands by default do not do the pip version check.

ignore_require_venv = False
main(args)[source]
parse_args(args)[source]
run(options, args)[source]
usage = None
class pip_shims.shims.ConfigOptionParser(*args, **kwargs)[source]

Bases: pip._internal.cli.parser.CustomOptionParser

Custom option parser which updates its defaults by checking the configuration files and environmental variables

check_default(option, key, val)[source]
error(msg : string)[source]

Print a usage message incorporating ‘msg’ to stderr and exit. If you override this in a subclass, it should not return – it should either exit or raise an exception.

get_default_values()[source]

Overriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.

exception pip_shims.shims.DistributionNotFound[source]

Bases: pip._internal.exceptions.InstallationError

Raised when a distribution cannot be found to satisfy a requirement

class pip_shims.shims.FormatControl(no_binary=None, only_binary=None)[source]

Bases: object

Helper for managing formats from which a package can be installed.

disallow_binaries()[source]
get_allowed_formats(canonical_name)[source]
static handle_mutual_excludes(value, target, other)[source]
class pip_shims.shims.FrozenRequirement(name, req, editable, comments=())[source]

Bases: object

classmethod from_dist(dist)[source]
pip_shims.shims.get_installed_distributions(local_only=True, skip={'argparse', 'python', 'wsgiref'}, include_editables=True, editables_only=False, user_only=False, paths=None)[source]

Return a list of installed Distribution objects.

If local_only is True (default), only return installations local to the current virtualenv, if in a virtualenv.

skip argument is an iterable of lower-case project names to ignore; defaults to stdlib_pkgs

If include_editables is False, don’t report editables.

If editables_only is True , only report editables.

If user_only is True , only report installations in the user site directory.

If paths is set, only report the distributions present at the specified list of locations.

pip_shims.shims.get_supported(version=None, platform=None, impl=None, abi=None)[source]

Return a list of supported tags for each version specified in versions.

Parameters:
  • version – a string version, of the form “33” or “32”, or None. The version will be assumed to support our ABI.
  • platform – specify the exact platform you want valid tags for, or None. If None, use the local system platform.
  • impl – specify the exact implementation you want valid tags for, or None. If None, use the local interpreter impl.
  • abi – specify the exact abi you want valid tags for, or None. If None, use the local interpreter abi.
exception pip_shims.shims.InstallationError[source]

Bases: pip._internal.exceptions.PipError

General exception during installation

exception pip_shims.shims.UninstallationError[source]

Bases: pip._internal.exceptions.PipError

General exception during uninstallation

exception pip_shims.shims.RequirementsFileParseError[source]

Bases: pip._internal.exceptions.InstallationError

Raised when a general error occurs parsing a requirements file line.

exception pip_shims.shims.BestVersionAlreadyInstalled[source]

Bases: pip._internal.exceptions.PipError

Raised when the most up-to-date version of a package is already installed.

exception pip_shims.shims.BadCommand[source]

Bases: pip._internal.exceptions.PipError

Raised when virtualenv or a command is not found

exception pip_shims.shims.CommandError[source]

Bases: pip._internal.exceptions.PipError

Raised when there is an error in command-line arguments

exception pip_shims.shims.PreviousBuildDirError[source]

Bases: pip._internal.exceptions.PipError

Raised when there’s a previous conflicting build directory

pip_shims.shims.install_req_from_editable(editable_req, comes_from=None, use_pep517=None, isolated=False, options=None, wheel_cache=None, constraint=False)[source]
pip_shims.shims.install_req_from_line(name, comes_from=None, use_pep517=None, isolated=False, options=None, wheel_cache=None, constraint=False, line_source=None)[source]

Creates an InstallRequirement from a name, which might be a requirement, directory containing ‘setup.py’, filename, or URL.

Parameters:line_source – An optional string describing where the line is from, for logging purposes in case of an error.
pip_shims.shims.install_req_from_req_string(req_string, comes_from=None, isolated=False, wheel_cache=None, use_pep517=None)[source]
class pip_shims.shims.InstallRequirement(req, comes_from, source_dir=None, editable=False, link=None, markers=None, use_pep517=None, isolated=False, options=None, wheel_cache=None, constraint=False, extras=())[source]

Bases: pip._internal.req.req_install.InstallRequirement

Represents something that may be installed later on, may have information about where to fetch the relevant requirement and also contains logic for installing the said requirement.

archive(build_dir)[source]

Saves archive to provided build_dir.

Used for saving downloaded VCS requirements as part of pip download.

assert_source_matches_version()[source]
build_location(build_dir)
check_if_exists(use_user_site)[source]

Find an installed distribution that satisfies or conflicts with this requirement, and set self.satisfied_by or self.should_reinstall appropriately.

ensure_build_location(build_dir)[source]
ensure_has_source_dir(parent_dir)[source]

Ensure that a source_dir is set.

This will create a temporary build dir if the name of the requirement isn’t known yet.

Parameters:parent_dir – The ideal pip parent_dir for the source_dir. Generally src_dir for editables and build_dir for sdists.
Returns:self.source_dir
format_debug()[source]

An un-tested helper for getting state, for debugging.

from_editable = <pip_shims.utils.BaseMethod object>
from_line = <pip_shims.utils.BaseMethod object>
from_path()[source]

Format a nice indicator to show where this “comes from”

get_dist()[source]
has_hash_options

Return whether any known-good hashes are specified as options.

These activate –require-hashes mode; hashes specified as part of a URL do not.

hashes(trust_internet=True)[source]

Return a hash-comparer that considers my option- and URL-based hashes to be known-good.

Hashes in URLs–ones embedded in the requirements file, not ones downloaded from an index server–are almost peers with ones from flags. They satisfy –require-hashes (whether it was implicitly or explicitly activated) but do not activate it. md5 and sha224 are not allowed in flags, which should nudge people toward good algos. We always OR all hashes together, even ones from URLs.

Parameters:trust_internet – Whether to trust URL-based (#md5=…) hashes downloaded from the internet, as by populate_link()
install(install_options, global_options=None, root=None, home=None, prefix=None, warn_script_location=True, use_user_site=False, pycompile=True)[source]
installed_version
is_pinned

Return whether I am pinned to an exact version.

For example, some-package==1.2 is pinned; some-package>1.2 is not.

is_wheel
load_pyproject_toml()[source]

Load the pyproject.toml file.

After calling this routine, all of the attributes related to PEP 517 processing for this requirement have been set. In particular, the use_pep517 attribute can be used to determine whether we should follow the PEP 517 or legacy (setup.py) code path.

match_markers(extras_requested=None)[source]
metadata
name

Ensure that if a link can be found for this, that it is found.

Note that self.link may still be None - if Upgrade is False and the requirement is already installed.

If require_hashes is True, don’t use the wheel cache, because cached wheels, always built locally, have different hashes than the files downloaded from the index server and thus throw false hash mismatches. Furthermore, cached wheels at present have undeterministic contents due to file modification times.

prepare_metadata()[source]

Ensure that project metadata is available.

Under PEP 517, call the backend hook to prepare the metadata. Under legacy processing, call setup.py egg-info.

pyproject_toml_path
remove_temporary_source()[source]

Remove the source files from this requirement, if they are marked for deletion

setup_py_path
specifier
uninstall(auto_confirm=False, verbose=False)[source]

Uninstall the distribution currently satisfying this requirement.

Prompts before removing or modifying files unless auto_confirm is True.

Refuses to delete or modify files outside of sys.prefix - thus uninstallation within a virtual environment can only modify that virtual environment, even if the virtualenv is linked to global site-packages.

unpacked_source_directory
update_editable(obtain=True)[source]
warn_on_mismatching_name()[source]
pip_shims.shims.is_archive_file(name)[source]

Return True if name is a considered as an archive file.

pip_shims.shims.is_file_url(link)
class pip_shims.shims.Downloader(session, progress_bar)[source]

Bases: object

pip_shims.shims.unpack_url(link, location, downloader, download_dir=None, hashes=None)[source]

Unpack link into location, downloading if required.

Parameters:hashes – A Hashes object, one of whose embedded hashes must match, or HashMismatch will be raised. If the Hashes is empty, no matches are required, and unhashable types of requirements (like VCS ones, which would ordinarily raise HashUnsupported) are allowed.
pip_shims.shims.shim_unpack(*, unpack_fn=<pip_shims.models.ShimmedPathCollection object>, download_dir, ireq=None, link=None, location=None, hashes=None, progress_bar='off', only_download=None, downloader_provider=<pip_shims.models.ShimmedPathCollection object>, session=None)

Accepts all parameters that have been valid to pass to pip._internal.download.unpack_url() and selects or drops parameters as needed before invoking the provided callable.

Parameters:
  • unpack_fn (Callable) – A callable or shim referring to the pip implementation
  • download_dir (str) – The directory to download the file to
:param Optional[InstallRequirement] ireq:
an Install Requirement instance, defaults to None
:param Optional[Link] link: A Link instance,
defaults to None.
Parameters:
  • location (Optional[str]) – A location or source directory if the target is a VCS url, defaults to None.
  • hashes (Optional[Any]) – A Hashes instance, defaults to None
  • progress_bar (str) – Indicates progress par usage during download, defatuls to off.
  • only_download (Optional[bool]) – Whether to skip install, defaults to None.
  • downloader_provider (Optional[ShimmedPathCollection]) – A downloader class to instantiate, if applicable.
  • session (Optional[Session]) – A PipSession instance, defaults to None.
Returns:

The result of unpacking the url.

Return type:

None

pip_shims.shims.is_installable_dir(path)[source]

Is path is a directory containing setup.py or pyproject.toml?

Bases: pip._internal.models.link.Link

Represents a parsed link from a Package Index’s simple URL

egg_fragment
ext
file_path
filename
has_hash
hash
hash_name
is_artifact
is_existing_dir()[source]
is_file
is_hash_allowed(hashes)[source]

Return True if the link has a hash and it is allowed.

is_vcs
is_wheel
is_yanked
netloc

This can contain auth information.

path
scheme
show_url
splitext()[source]
subdirectory_fragment
url
url_without_fragment
pip_shims.shims.make_abstract_dist(install_req)

Returns a Distribution for the given InstallRequirement

pip_shims.shims.make_distribution_for_install_requirement(install_req)[source]

Returns a Distribution for the given InstallRequirement

pip_shims.shims.make_option_group(group, parser)[source]

Return an OptionGroup object group – assumed to be dict with ‘name’ and ‘options’ keys parser – an optparse Parser

class pip_shims.shims.PackageFinder(link_collector, target_python, allow_yanked, format_control=None, candidate_prefs=None, ignore_requires_python=None)[source]

Bases: object

This finds packages.

This is meant to match easy_install’s technique for looking for packages, by reading pages and looking for appropriate links.

allow_all_prereleases
classmethod create(link_collector, selection_prefs, target_python=None)[source]

Create a PackageFinder.

Parameters:
  • selection_prefs – The candidate selection preferences, as a SelectionPreferences object.
  • target_python – The target Python interpreter to use when checking compatibility. If None (the default), a TargetPython object will be constructed from the running Python.

Convert links that are candidates to InstallationCandidate objects.

find_all_candidates(project_name)[source]

Find all available InstallationCandidate for project_name

This checks index_urls and find_links. All versions found are returned as an InstallationCandidate list.

See LinkEvaluator.evaluate_link() for details on which files are accepted.

find_best_candidate(project_name, specifier=None, hashes=None)[source]

Find matches for the given project and specifier.

Parameters:specifier – An optional object implementing filter (e.g. packaging.specifiers.SpecifierSet) to filter applicable versions.
Returns:A BestCandidateResult instance.
find_requirement(req, upgrade)[source]

Try to find a Link matching req

Expects req, an InstallRequirement and upgrade, a boolean Returns a Link if found, Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise

get_install_candidate(link_evaluator, link)[source]

If the link is a candidate for install, convert it to an InstallationCandidate and return it. Otherwise, return None.

index_urls
make_candidate_evaluator(project_name, specifier=None, hashes=None)[source]

Create a CandidateEvaluator object to use.

process_project_url(project_url, link_evaluator)[source]
search_scope
set_allow_all_prereleases()[source]
trusted_hosts
class pip_shims.shims.CandidateEvaluator(project_name, supported_tags, specifier, prefer_binary=False, allow_all_prereleases=False, hashes=None)[source]

Bases: object

Responsible for filtering and sorting candidates for installation based on what tags are valid.

compute_best_candidate(candidates)[source]

Compute and return a BestCandidateResult instance.

classmethod create(project_name, target_python=None, prefer_binary=False, allow_all_prereleases=False, specifier=None, hashes=None)[source]

Create a CandidateEvaluator object.

Parameters:
  • target_python – The target Python interpreter to use when checking compatibility. If None (the default), a TargetPython object will be constructed from the running Python.
  • specifier – An optional object implementing filter (e.g. packaging.specifiers.SpecifierSet) to filter applicable versions.
  • hashes – An optional collection of allowed hashes.
get_applicable_candidates(candidates)[source]

Return the applicable candidates from a list of candidates.

sort_best_candidate(candidates)[source]

Return the best candidate per the instance’s sort order, or None if no candidate is acceptable.

class pip_shims.shims.CandidatePreferences(prefer_binary=False, allow_all_prereleases=False)[source]

Bases: object

Encapsulates some of the preferences for filtering and sorting InstallationCandidate objects.

class pip_shims.shims.LinkCollector(session, search_scope)[source]

Bases: object

Responsible for collecting Link objects from all configured locations, making network requests as needed.

The class’s main method is its collect_links() method.

Find all available links for the given project name.

Returns:All the Link objects (unfiltered), as a CollectedLinks object.
fetch_page(location)[source]

Fetch an HTML page containing package links.

class pip_shims.shims.LinkEvaluator(project_name, canonical_name, formats, target_python, allow_yanked, ignore_requires_python=None)[source]

Bases: object

Responsible for evaluating links for a particular project.

Determine whether a link is a candidate for installation.

Returns:A tuple (is_candidate, result), where result is (1) a version string if is_candidate is True, and (2) if is_candidate is False, an optional string to log the reason the link fails to qualify.
class pip_shims.shims.TargetPython(platform=None, py_version_info=None, abi=None, implementation=None)[source]

Bases: object

Encapsulates the properties of a Python interpreter one is targeting for a package install, download, etc.

format_given()[source]

Format the given, non-None attributes for display.

get_tags()[source]

Return the supported PEP 425 tags to check wheel candidates against.

The tags are returned in order of preference (most preferred first).

class pip_shims.shims.SearchScope(find_links, index_urls)[source]

Bases: object

Encapsulates the locations that pip is configured to search.

classmethod create(find_links, index_urls)[source]

Create a SearchScope object after normalizing the find_links.

get_formatted_locations()[source]
get_index_urls_locations(project_name)[source]

Returns the locations found via self.index_urls

Checks the url_name on the main (first in the list) index and use this url_name to produce all locations

class pip_shims.shims.SelectionPreferences(allow_yanked, allow_all_prereleases=False, format_control=None, prefer_binary=False, ignore_requires_python=None)[source]

Bases: object

Encapsulates the candidate selection preferences for downloading and installing files.

pip_shims.shims.parse_requirements(filename, session, finder=None, comes_from=None, options=None, constraint=False, wheel_cache=None, use_pep517=None)[source]

Parse a requirements file and yield InstallRequirement instances.

Parameters:
  • filename – Path or url of requirements file.
  • session – PipSession instance.
  • finder – Instance of pip.index.PackageFinder.
  • comes_from – Origin description of requirements.
  • options – cli options.
  • constraint – If true, parsing a constraint file rather than requirements file.
  • wheel_cache – Instance of pip.wheel.WheelCache
  • use_pep517 – Value of the –use-pep517 option.
pip_shims.shims.path_to_url(path)[source]

Convert a path to a file: URL. The path will be made absolute and have quoted path parts.

exception pip_shims.shims.PipError[source]

Bases: Exception

Base pip exception

class pip_shims.shims.RequirementPreparer(build_dir, download_dir, src_dir, wheel_download_dir, build_isolation, req_tracker, downloader, finder, require_hashes, use_user_site)[source]

Bases: object

Prepares a Requirement

prepare_editable_requirement(req)[source]

Prepare an editable requirement

prepare_installed_requirement(req, skip_reason)[source]

Prepare an already-installed requirement

prepare_linked_requirement(req)[source]

Prepare a requirement that would be obtained from req.link

class pip_shims.shims.RequirementSet(check_supported_wheels=True)[source]

Bases: object

add_named_requirement(install_req)[source]
add_requirement(install_req, parent_req_name=None, extras_requested=None)[source]

Add install_req as a requirement to install.

Parameters:
  • parent_req_name – The name of the requirement that needed this added. The name is used because when multiple unnamed requirements resolve to the same name, we could otherwise end up with dependency links that point outside the Requirements set. parent_req must already be added. Note that None implies that this is a user supplied requirement, vs an inferred one.
  • extras_requested – an iterable of extras used to evaluate the environment markers.
Returns:

Additional requirements to scan. That is either [] if the requirement is not applicable, or [install_req] if the requirement is applicable and has just been added.

add_unnamed_requirement(install_req)[source]
cleanup_files()[source]

Clean up files, remove builds.

get_requirement(name)[source]
has_requirement(name)[source]
class pip_shims.shims.RequirementTracker(root)[source]

Bases: object

add(req)[source]

Add an InstallRequirement to build tracking.

cleanup()[source]
remove(req)[source]

Remove an InstallRequirement from build tracking.

track(req)[source]
class pip_shims.shims.TempDirectory(path=None, delete=None, kind='temp', globally_managed=False)[source]

Bases: object

Helper class that owns and cleans up a temporary directory.

This class can be used as a context manager or as an OO representation of a temporary directory.

Attributes:
path
Location to the created temporary directory
delete
Whether the directory should be deleted when exiting (when used as a contextmanager)
Methods:
cleanup()
Deletes the temporary directory

When used as a context manager, if the delete attribute is True, on exiting the context the temporary directory is deleted.

cleanup()[source]

Remove the temporary directory created and reset state

path
pip_shims.shims.global_tempdir_manager()[source]
pip_shims.shims.get_requirement_tracker()[source]
class pip_shims.shims.Resolver(preparer, finder, make_install_req, use_user_site, ignore_dependencies, ignore_installed, ignore_requires_python, force_reinstall, upgrade_strategy, py_version_info=None)[source]

Bases: object

Resolves which packages need to be installed/uninstalled to perform the requested operation without breaking the requirements of any package.

get_installation_order(req_set)[source]

Create the installation order.

The installation order is topological - requirements are installed before the requiring thing. We break cycles at an arbitrary point, and make no other guarantees.

resolve(requirement_set)[source]

Resolve what operations need to be done

As a side-effect of this method, the packages (and their dependencies) are downloaded, unpacked and prepared for installation. This preparation is done by pip.operations.prepare.

Once PyPI has static dependency metadata available, it would be possible to move the preparation to become a step separated from dependency resolution.

class pip_shims.shims.SafeFileCache(directory)[source]

Bases: pip._vendor.cachecontrol.cache.BaseCache

A file based cache which is safe to use even when the target directory may not be accessible or writable.

delete(key)[source]
get(key)[source]
set(key, value)[source]
class pip_shims.shims.UninstallPathSet(dist)[source]

Bases: object

A set of file paths to be removed in the uninstallation of a requirement.

add(path)[source]
add_pth(pth_file, entry)[source]
commit()[source]

Remove temporary save dir: rollback will no longer be possible.

classmethod from_dist(dist)[source]
remove(auto_confirm=False, verbose=False)[source]

Remove paths in self.paths with confirmation (unless auto_confirm is True).

rollback()[source]

Rollback the changes previously made by remove().

pip_shims.shims.url_to_path(url)[source]

Convert a file: URL to a path.

class pip_shims.shims.VcsSupport[source]

Bases: object

all_schemes
backends
dirnames
get_backend(name)[source]

Return a VersionControl object or None.

get_backend_for_dir(location)[source]

Return a VersionControl object if a repository of that type is found at the given directory.

get_backend_for_scheme(scheme)[source]

Return a VersionControl object or None.

register(cls)[source]
schemes = ['ssh', 'git', 'hg', 'bzr', 'sftp', 'svn']
unregister(name)[source]
class pip_shims.shims.Wheel(filename)[source]

Bases: object

get_formatted_file_tags()[source]

Return the wheel’s tags as a sorted list of strings.

support_index_min(tags)[source]

Return the lowest index that one of the wheel’s file_tag combinations achieves in the given list of supported tags.

For example, if there are 8 supported tags and one of the file tags is first in the list, then return 0.

Parameters:tags – the PEP 425 tags to check the wheel against, in order with most preferred first.
Raises:ValueError – If none of the wheel’s file tags match one of the supported tags.
supported(tags)[source]

Return whether the wheel is compatible with one of the given tags.

Parameters:tags – the PEP 425 tags to check the wheel against.
wheel_file_re = re.compile('^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))\n ((-(?P<build>\\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)\n \\.whl|\\.dist-info)$', re.VERBOSE)
class pip_shims.shims.WheelCache(cache_dir, format_control)[source]

Bases: pip._internal.cache.Cache

Wraps EphemWheelCache and SimpleWheelCache into a single Cache

This Cache allows for gracefully degradation, using the ephem wheel cache when a certain link is not found in the simple wheel cache first.

cleanup()[source]
get(link, package_name, supported_tags)[source]

Returns a link to a cached item if it exists, otherwise returns the passed link.

Return a directory to store cached items in for link.

pip_shims.shims.build(requirements, wheel_cache, build_options, global_options)[source]

Build wheels.

Returns:The list of InstallRequirement that succeeded to build and the list of InstallRequirement that failed to build.
pip_shims.shims.build_one(req, output_dir, build_options, global_options)

Build one wheel.

Returns:The filename of the built wheel, or None if the build failed.
pip_shims.shims.build_one_inside_env(req, output_dir, build_options, global_options)
class pip_shims.shims.AbstractDistribution(req)[source]

Bases: object

A base class for handling installable artifacts.

The requirements for anything installable are as follows:

  • we must be able to determine the requirement name (or we can’t correctly handle the non-upgrade case).
  • for packages with setup requirements, we must also be able to determine their requirements without installing additional packages (for the same reason as run-time dependencies)
  • we must be able to create a Distribution object exposing the above metadata.
get_pkg_resources_distribution()[source]
prepare_distribution_metadata(finder, build_isolation)[source]
class pip_shims.shims.InstalledDistribution(req)[source]

Bases: pip._internal.distributions.base.AbstractDistribution

Represents an installed package.

This does not need any preparation as the required information has already been computed.

get_pkg_resources_distribution()[source]
prepare_distribution_metadata(finder, build_isolation)[source]
class pip_shims.shims.SourceDistribution(req)[source]

Bases: pip._internal.distributions.base.AbstractDistribution

Represents a source distribution.

The preparation step for these needs metadata for the packages to be generated, either using PEP 517 or using the legacy setup.py egg_info.

get_pkg_resources_distribution()[source]
prepare_distribution_metadata(finder, build_isolation)[source]
class pip_shims.shims.WheelDistribution(req)[source]

Bases: pip._internal.distributions.base.AbstractDistribution

Represents a wheel distribution.

This does not need any preparation as wheels can be directly unpacked.

get_pkg_resources_distribution()[source]

Loads the metadata from the wheel file into memory and returns a Distribution that uses it, not relying on the wheel file or requirement.

prepare_distribution_metadata(finder, build_isolation)[source]
pip_shims.shims.get_package_finder(install_cmd=None, options=None, session=None, platform=None, python_versions=None, abi=None, implementation=None, target_python=None, ignore_requires_python=None, *, target_python_builder=<class 'pip._internal.models.target_python.TargetPython'>, install_cmd_provider=<pip_shims.models.ShimmedPathCollection object>)

Shim for compatibility to generate package finders.

Build and return a PackageFinder instance using the InstallCommand helper method to construct the finder, shimmed with backports as needed for compatibility.

Parameters:
  • install_cmd_provider (ShimmedPathCollection) – A shim for providing new install command instances.
  • install_cmd – A InstallCommand instance which is used to generate the finder.
  • options (optparse.Values) – An optional optparse.Values instance generated by calling install_cmd.parser.parse_args() typically.
  • session – An optional session instance, can be created by the install_cmd.
  • platform (Optional[str]) – An optional platform string, e.g. linux_x86_64
  • ..]] python_versions (Optional[Tuple[str,) – A tuple of 2-digit strings representing python versions, e.g. (“27”, “35”, “36”, “37”…)
  • abi (Optional[str]) – The target abi to support, e.g. “cp38”
  • implementation (Optional[str]) – An optional implementation string for limiting searches to a specific implementation, e.g. “cp” or “py”
  • target_python – A TargetPython instance (will be translated to alternate arguments if necessary on incompatible pip versions).
  • ignore_requires_python (Optional[bool]) – Whether to ignore requires_python on resulting candidates, only valid after pip version 19.3.1
  • target_python_builder – A ‘TargetPython’ builder (e.g. the class itself, uninstantiated)
Returns:

A pip._internal.index.package_finder.PackageFinder instance

Return type:

pip._internal.index.package_finder.PackageFinder

Example:
>>> from pip_shims.shims import InstallCommand, get_package_finder
>>> install_cmd = InstallCommand()
>>> finder = get_package_finder(
...     install_cmd, python_versions=("27", "35", "36", "37", "38"), implementation="
cp"
... )
>>> candidates = finder.find_all_candidates("requests")
>>> requests_222 = next(iter(c for c in candidates if c.version.public == "2.22.0"))
>>> requests_222
<InstallationCandidate('requests', <Version('2.22.0')>, <Link https://files.pythonhos
ted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/r
equests-2.22.0-py2.py3-none-any.whl#sha256=9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9
a590f48c010551dc6c4b31 (from https://pypi.org/simple/requests/) (requires-python:>=2.
7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*)>)>
pip_shims.shims.make_preparer(*, preparer_fn=<pip_shims.models.ShimmedPathCollection object>, req_tracker_fn=<pip_shims.models.ShimmedPathCollection object>, build_dir=None, src_dir=None, download_dir=None, wheel_download_dir=None, progress_bar='off', build_isolation=False, session=None, finder=None, options=None, require_hashes=None, use_user_site=None, req_tracker=None, install_cmd_provider=<pip_shims.models.ShimmedPathCollection object>, downloader_provider=<pip_shims.models.ShimmedPathCollection object>, install_cmd=None, finder_provider=<pip_shims.models.ShimmedPathCollection object>)

Creates a requirement preparer for preparing pip requirements.

Provides a compatibilty shim that accepts all previously valid arguments and discards any that are no longer used.

Raises:
  • TypeError – No requirement tracker provided and one cannot be generated
  • TypeError – No valid sessions provided and one cannot be generated
  • TypeError – No valid finders provided and one cannot be generated
Parameters:
  • preparer_fn (TShimmedFunc) – Callable or shim for generating preparers.
  • req_tracker_fn (Optional[TShimmedFunc]) – Callable or shim for generating requirement trackers, defualts to None
  • build_dir (Optional[str]) – Directory for building packages and wheels, defaults to None
  • src_dir (Optional[str]) – Directory to find or extract source files, defaults to None
  • download_dir (Optional[str]) – Target directory to download files, defaults to None
  • wheel_download_dir (Optional[str]) – Target directoryto download wheels, defaults to None
  • progress_bar (str) – Whether to display a progress bar, defaults to off
  • build_isolation (bool) – Whether to build requirements in isolation, defaults to False
  • session (Optional[TSession]) – Existing session to use for getting requirements, defaults to None
  • finder (Optional[TFinder]) – The package finder to use during resolution, defaults to None
  • options (Optional[Values]) – Pip options to use if needed, defaults to None
  • require_hashes (Optional[bool]) – Whether to require hashes for preparation
  • use_user_site (Optional[bool]) – Whether to use the user site directory for preparing requirements
  • TShimmedFunc]] req_tracker (Optional[Union[TReqTracker,) – The requirement tracker to use for building packages, defaults to None
  • downloader_provider (Optional[TShimmedFunc]) – A downloader provider
  • install_cmd (Optional[TCommandInstance]) – The install command used to create the finder, session, and options if needed, defaults to None
  • finder_provider (Optional[TShimmedFunc]) – A package finder provider
Yield:

A new requirement preparer instance

Return type:

ContextManager[RequirementPreparer]

Example:
>>> from pip_shims.shims import (
...     InstallCommand, get_package_finder, make_preparer, get_requirement_tracker
... )
>>> install_cmd = InstallCommand()
>>> pip_options, _ = install_cmd.parser.parse_args([])
>>> session = install_cmd._build_session(pip_options)
>>> finder = get_package_finder(
...     install_cmd, session=session, options=pip_options
... )
>>> with make_preparer(
...     options=pip_options, finder=finder, session=session, install_cmd=ic
... ) as preparer:
...     print(preparer)
<pip._internal.operations.prepare.RequirementPreparer object at 0x7f8a2734be80>
pip_shims.shims.get_resolver(*, resolver_fn=<pip_shims.models.ShimmedPathCollection object>, install_req_provider=<pip_shims.models.ShimmedPathCollection object>, format_control_provider=<pip_shims.models.ShimmedPathCollection object>, wheel_cache_provider=<pip_shims.models.ShimmedPathCollection object>, finder=None, upgrade_strategy='to-satisfy-only', force_reinstall=None, ignore_dependencies=None, ignore_requires_python=None, ignore_installed=True, use_user_site=False, isolated=None, wheel_cache=None, preparer=None, session=None, options=None, make_install_req=None, install_cmd_provider=<pip_shims.models.ShimmedPathCollection object>, install_cmd=None)

A resolver creation compatibility shim for generating a resolver.

Consumes any argument that was previously used to instantiate a resolver, discards anything that is no longer valid.

Note

This is only valid for pip >= 10.0.0

Raises:
  • ValueError – A session is required but not provided and one cannot be created
  • ValueError – A finder is required but not provided and one cannot be created
  • ValueError – An install requirement provider is required and has not been provided
Parameters:
  • resolver_fn (TShimmedFunc) – The resolver function used to create new resolver instances.
  • install_req_provider (TShimmedFunc) – The provider function to use to generate install requirements if needed.
  • format_control_provider (TShimmedFunc) – The provider function to use to generate a format_control instance if needed.
  • wheel_cache_provider (TShimmedFunc) – The provider function to use to generate a wheel cache if needed.
  • finder (Optional[TFinder]) – The package finder to use during resolution, defaults to None.
  • upgrade_strategy (str) – Upgrade strategy to use, defaults to only-if-needed.
  • force_reinstall (Optional[bool]) – Whether to simulate or assume package reinstallation during resolution, defaults to None
  • ignore_dependencies (Optional[bool]) – Whether to ignore package dependencies, defaults to None
  • ignore_requires_python (Optional[bool]) – Whether to ignore indicated required_python versions on packages, defaults to None
  • ignore_installed (bool) – Whether to ignore installed packages during resolution, defaults to True
  • use_user_site (bool) – Whether to use the user site location during resolution, defaults to False
  • isolated (Optional[bool]) – Whether to isolate the resolution process, defaults to None
  • wheel_cache (Optional[TWheelCache]) – The wheel cache to use, defaults to None
  • preparer (Optional[TPreparer]) – The requirement preparer to use, defaults to None
  • session (Optional[TSession]) – Existing session to use for getting requirements, defaults to None
  • options (Optional[Values]) – Pip options to use if needed, defaults to None
  • make_install_req (Optional[functools.partial]) – The partial function to pass in to the resolver for actually generating install requirements, if necessary
  • install_cmd (Optional[TCommandInstance]) – The install command used to create the finder, session, and options if needed, defaults to None.
Returns:

A new resolver instance.

Return type:

Resolver

Example:
>>> import os
>>> from tempdir import TemporaryDirectory
>>> from pip_shims.shims import (
...     InstallCommand, get_package_finder, make_preparer, get_requirement_tracker,
...     get_resolver, InstallRequirement, RequirementSet
... )
>>> install_cmd = InstallCommand()
>>> pip_options, _ = install_cmd.parser.parse_args([])
>>> session = install_cmd._build_session(pip_options)
>>> finder = get_package_finder(
...     install_cmd, session=session, options=pip_options
... )
>>> wheel_cache = WheelCache(USER_CACHE_DIR, FormatControl(None, None))
>>> with TemporaryDirectory() as temp_base:
...     reqset = RequirementSet()
...     ireq = InstallRequirement.from_line("requests")
...     ireq.is_direct = True
...     build_dir = os.path.join(temp_base, "build")
...     src_dir = os.path.join(temp_base, "src")
...     ireq.build_location(build_dir)
...     with make_preparer(
...         options=pip_options, finder=finder, session=session,
...         build_dir=build_dir, install_cmd=install_cmd,
...     ) as preparer:
...         resolver = get_resolver(
...             finder=finder, ignore_dependencies=False, ignore_requires_python=True,
...             preparer=preparer, session=session, options=pip_options,
...             install_cmd=install_cmd, wheel_cache=wheel_cache,
...         )
...         resolver.require_hashes = False
...         reqset.add_requirement(ireq)
...         results = resolver.resolve(reqset)
...         #reqset.cleanup_files()
...         for result_req in reqset.requirements:
...             print(result_req)
requests
chardet
certifi
urllib3
idna
pip_shims.shims.get_requirement_set(install_command=None, *, req_set_provider=<pip_shims.models.ShimmedPathCollection object>, build_dir=None, src_dir=None, download_dir=None, wheel_download_dir=None, session=None, wheel_cache=None, upgrade=False, upgrade_strategy=None, ignore_installed=False, ignore_dependencies=False, force_reinstall=False, use_user_site=False, isolated=False, ignore_requires_python=False, require_hashes=None, cache_dir=None, options=None, install_cmd_provider=<pip_shims.models.ShimmedPathCollection object>)

Creates a requirement set from the supplied parameters.

Not all parameters are passed through for all pip versions, but any invalid parameters will be ignored if they are not needed to generate a requirement set on the current pip version.

Parameters:install_command – A InstallCommand instance which is used to generate the finder.
:param ShimmedPathCollection req_set_provider: A provider
to build requirement set instances.
Parameters:
  • build_dir (str) – The directory to build requirements in. Removed in pip 10, defeaults to None
  • source_dir (str) – The directory to use for source requirements. Removed in pip 10, defaults to None
  • download_dir (str) – The directory to download requirement artifacts to. Removed in pip 10, defaults to None
  • wheel_download_dir (str) – The directory to download wheels to. Removed in pip 10, defaults ot None
:param Session session: The pip session to use. Removed in pip 10,
defaults to None
Parameters:
  • wheel_cache (WheelCache) – The pip WheelCache instance to use for caching wheels. Removed in pip 10, defaults to None
  • upgrade (bool) – Whether to try to upgrade existing requirements. Removed in pip 10, defaults to False.
  • upgrade_strategy (str) – The upgrade strategy to use, e.g. “only-if-needed”. Removed in pip 10, defaults to None.
  • ignore_installed (bool) – Whether to ignore installed packages when resolving. Removed in pip 10, defaults to False.
  • ignore_dependencies (bool) – Whether to ignore dependencies of requirements when resolving. Removed in pip 10, defaults to False.
  • force_reinstall (bool) – Whether to force reinstall of packages when resolving. Removed in pip 10, defaults to False.
  • use_user_site (bool) – Whether to use user site packages when resolving. Removed in pip 10, defaults to False.
  • isolated (bool) – Whether to resolve in isolation. Removed in pip 10, defaults to False.
  • ignore_requires_python (bool) – Removed in pip 10, defaults to False.
  • require_hashes (bool) – Whether to require hashes when resolving. Defaults to False.
  • options (Values) – An Values instance from an install cmd
  • install_cmd_provider (ShimmedPathCollection) – A shim for providing new install command instances.
Returns:

A new requirement set instance

Return type:

RequirementSet

pip_shims.shims.resolve(ireq, *, reqset_provider=<pip_shims.models.ShimmedPathCollection object>, req_tracker_provider=<pip_shims.models.ShimmedPathCollection object>, install_cmd_provider=<pip_shims.models.ShimmedPathCollection object>, install_command=None, finder_provider=<pip_shims.models.ShimmedPathCollection object>, resolver_provider=<pip_shims.models.ShimmedPathCollection object>, wheel_cache_provider=<pip_shims.models.ShimmedPathCollection object>, format_control_provider=<pip_shims.models.ShimmedPathCollection object>, make_preparer_provider=<pip_shims.models.ShimmedPathCollection object>, tempdir_manager_provider=<pip_shims.models.ShimmedPathCollection object>, options=None, session=None, resolver=None, finder=None, upgrade_strategy='to-satisfy-only', force_reinstall=None, ignore_dependencies=None, ignore_requires_python=None, ignore_installed=True, use_user_site=False, isolated=None, build_dir=None, source_dir=None, download_dir=None, cache_dir=None, wheel_download_dir=None, wheel_cache=None, require_hashes=None, check_supported_wheels=True)

Resolves the provided InstallRequirement, returning a dictionary.

Maps a dictionary of names to corresponding InstallRequirement values.

:param InstallRequirement ireq: An
InstallRequirement to initiate the resolution process
:param ShimmedPathCollection reqset_provider: A provider
to build requirement set instances.
:param ShimmedPathCollection req_tracker_provider: A
provider to build requirement tracker instances
Parameters:
  • install_cmd_provider (ShimmedPathCollection) – A shim for providing new install command instances.
  • install_command (Optional[TCommandInstance]) – The install command used to create the finder, session, and options if needed, defaults to None.
:param ShimmedPathCollection finder_provider: A provider
to package finder instances.
:param ShimmedPathCollection resolver_provider: A provider
to build resolver instances
Parameters:
  • wheel_cache_provider (TShimmedFunc) – The provider function to use to generate a wheel cache if needed.
  • format_control_provider (TShimmedFunc) – The provider function to use to generate a format_control instance if needed.
  • make_preparer_provider (TShimmedFunc) – Callable or shim for generating preparers.
  • tempdir_manager_provider (Optional[TShimmedFunc]) – Shim for generating tempdir manager for pip temporary directories
  • options (Optional[Values]) – Pip options to use if needed, defaults to None
  • session (Optional[TSession]) – Existing session to use for getting requirements, defaults to None
:param Resolver resolver: A pre-existing
resolver instance to use for resolution
Parameters:
  • finder (Optional[TFinder]) – The package finder to use during resolution, defaults to None.
  • upgrade_strategy (str) – Upgrade strategy to use, defaults to only-if-needed.
  • force_reinstall (Optional[bool]) – Whether to simulate or assume package reinstallation during resolution, defaults to None
  • ignore_dependencies (Optional[bool]) – Whether to ignore package dependencies, defaults to None
  • ignore_requires_python (Optional[bool]) – Whether to ignore indicated required_python versions on packages, defaults to None
  • ignore_installed (bool) – Whether to ignore installed packages during resolution, defaults to True
  • use_user_site (bool) – Whether to use the user site location during resolution, defaults to False
  • isolated (Optional[bool]) – Whether to isolate the resolution process, defaults to None
  • build_dir (Optional[str]) – Directory for building packages and wheels, defaults to None
  • source_dir (str) – The directory to use for source requirements. Removed in pip 10, defaults to None
  • download_dir (Optional[str]) – Target directory to download files, defaults to None
  • cache_dir (str) – The cache directory to use for caching artifacts during resolution
  • wheel_download_dir (Optional[str]) – Target directoryto download wheels, defaults to None
  • wheel_cache (Optional[TWheelCache]) – The wheel cache to use, defaults to None
  • require_hashes (bool) – Whether to require hashes when resolving. Defaults to False.
  • check_supported_wheels (bool) – Whether to check support of wheels before including them in resolution.
Returns:

A dictionary mapping requirements to corresponding :class:`~pip._internal.req.req_install.InstallRequirement`s

Return type:

InstallRequirement

Example:
>>> from pip_shims.shims import resolve, InstallRequirement
>>> ireq = InstallRequirement.from_line("requests>=2.20")
>>> results = resolve(ireq)
>>> for k, v in results.items():
...    print("{0}: {1!r}".format(k, v))
requests: <InstallRequirement object: requests>=2.20 from https://files.pythonhosted.
org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/reque
sts-2.22.0-py2.py3-none-any.whl#sha256=9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590
f48c010551dc6c4b31 editable=False>
idna: <InstallRequirement object: idna<2.9,>=2.5 from https://files.pythonhosted.org/
packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-
py2.py3-none-any.whl#sha256=ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432
f7e4a3c (from requests>=2.20) editable=False>
urllib3: <InstallRequirement object: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 from htt
ps://files.pythonhosted.org/packages/b4/40/a9837291310ee1ccc242ceb6ebfd9eb21539649f19
3a7c8c86ba15b98539/urllib3-1.25.7-py2.py3-none-any.whl#sha256=a8a318824cc77d1fd4b2bec
2ded92646630d7fe8619497b142c84a9e6f5a7293 (from requests>=2.20) editable=False>
chardet: <InstallRequirement object: chardet<3.1.0,>=3.0.2 from https://files.pythonh
osted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8
/chardet-3.0.4-py2.py3-none-any.whl#sha256=fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed
4531e3e15460124c106691 (from requests>=2.20) editable=False>
certifi: <InstallRequirement object: certifi>=2017.4.17 from https://files.pythonhost
ed.org/packages/18/b0/8146a4f8dd402f60744fa380bc73ca47303cccf8b9190fd16a827281eac2/ce
rtifi-2019.9.11-py2.py3-none-any.whl#sha256=fd7c7c74727ddcf00e9acd26bba8da604ffec95bf
1c2144e67aff7a8b50e6cef (from requests>=2.20) editable=False>
pip_shims.shims.build_wheel(req=None, reqset=None, output_dir=None, preparer=None, wheel_cache=None, build_options=None, global_options=None, check_binary_allowed=None, no_clean=False, session=None, finder=None, install_command=None, req_tracker=None, build_dir=None, src_dir=None, download_dir=None, wheel_download_dir=None, cache_dir=None, use_user_site=False, use_pep517=None, *, format_control_provider=<pip_shims.models.ShimmedPathCollection object>, wheel_cache_provider=<pip_shims.models.ShimmedPathCollection object>, preparer_provider=<pip_shims.models.ShimmedPathCollection object>, wheel_builder_provider=<pip_shims.models.ShimmedPathCollection object>, build_one_provider=<pip_shims.models.ShimmedPathCollection object>, build_one_inside_env_provider=<pip_shims.models.ShimmedPathCollection object>, build_many_provider=<pip_shims.models.ShimmedPathCollection object>, install_command_provider=<pip_shims.models.ShimmedPathCollection object>, finder_provider=None)

Build a wheel or a set of wheels

Raises:

TypeError – Raised when no requirements are provided

Parameters:
  • req (Optional[TInstallRequirement]) – An InstallRequirement to build
  • reqset (Optional[TReqSet]) – A RequirementSet instance (pip<10) or an iterable of InstallRequirement instances (pip>=10) to build
  • output_dir (Optional[str]) – Target output directory, only useful when building one wheel using pip>=20.0
  • preparer (Optional[TPreparer]) – A preparer instance, defaults to None
  • wheel_cache (Optional[TWheelCache]) – A wheel cache instance, defaults to None
  • build_options (Optional[List[str]]) – A list of build options to pass in
  • global_options (Optional[List[str]]) – A list of global options to pass in
  • bool]] check_binary_allowed (Optional[Callable[TInstallRequirement,) – A callable to check whether we are allowed to build and cache wheels for an ireq
  • no_clean (bool) – Whether to avoid cleaning up wheels
  • session (Optional[TSession]) – A PipSession instance to pass to create a finder if necessary
  • finder (Optional[TFinder]) – A PackageFinder instance to use for generating a WheelBuilder instance on pip<20
  • install_command (Optional[TCommandInstance]) – The install command used to create the finder, session, and options if needed, defaults to None.
  • req_tracker (Optional[TReqTracker]) – An optional requirement tracker instance, if one already exists
  • build_dir (Optional[str]) – Passthrough parameter for building preparer
  • src_dir (Optional[str]) – Passthrough parameter for building preparer
  • download_dir (Optional[str]) – Passthrough parameter for building preparer
  • wheel_download_dir (Optional[str]) – Passthrough parameter for building preparer
  • cache_dir (Optional[str]) – Passthrough cache directory for wheel cache options
  • use_user_site (bool) – Whether to use the user site directory when preparing install requirements on pip<20
  • use_pep517 (Optional[bool]) – When set to True or False, prefers building with or without pep517 as specified, otherwise uses requirement preference. Only works for single requirements.
  • format_control_provider (Optional[TShimmedFunc]) – A provider for the FormatControl class
  • wheel_cache_provider (Optional[TShimmedFunc]) – A provider for the WheelCache class
  • preparer_provider (Optional[TShimmedFunc]) – A provider for the RequirementPreparer class
  • wheel_builder_provider (Optional[TShimmedFunc]) – A provider for the WheelBuilder class, if it exists
  • build_one_provider (Optional[TShimmedFunc]) – A provider for the _build_one function, if it exists
  • build_one_inside_env_provider (Optional[TShimmedFunc]) – A provider for the _build_one_inside_env function, if it exists
  • build_many_provider (Optional[TShimmedFunc]) – A provider for the build function, if it exists
  • install_command_provider (Optional[TShimmedFunc]) – A shim for providing new install command instances
  • finder_provider (TShimmedFunc) – A provider to package finder instances
Returns:

A tuple of successful and failed install requirements or else a path to a wheel

Return type:

Optional[Union[str, Tuple[List[TInstallRequirement], List[TInstallRequirement]]]]