piptools.cache module#

exception piptools.cache.CorruptCacheError(path: str)#

Bases: PipToolsError

class piptools.cache.DependencyCache(cache_dir: str)#

Bases: object

Create new persistent dependency cache for the current Python version.

The cache file is written to the appropriate user cache dir for the current platform, i.e.

~/.cache/pip-tools/depcache-pyX.Y.json

Where py indicates the Python implementation. Where X.Y indicates the Python version.

_reverse_dependencies(cache_keys: Iterable[tuple[str, str]]) dict[str, set[str]]#

Return a lookup table of reverse dependencies for all the given cache keys.

Example input:

[(‘pep8’, ‘1.5.7’),

(‘flake8’, ‘2.4.0’), (‘mccabe’, ‘0.3’), (‘pyflakes’, ‘0.8.1’)]

Example output:

{‘pep8’: [‘flake8’],

‘flake8’: [], ‘mccabe’: [‘flake8’], ‘pyflakes’: [‘flake8’]}

as_cache_key(ireq: InstallRequirement) Tuple[str, str]#

Given a requirement, return its cache key.

This behavior is a little weird in order to allow backwards compatibility with cache files. For a requirement without extras, this will return, for example:

(“ipython”, “2.1.0”)

For a requirement with extras, the extras will be comma-separated and appended to the version, inside brackets, like so:

(“ipython”, “2.1.0[nbconvert,notebook]”)

property cache: Dict[str, Dict[str, List[str]]]#

The dictionary that is the actual in-memory cache. This property lazily loads the cache from disk.

clear() None#
reverse_dependencies(ireqs: Iterable[InstallRequirement]) dict[str, set[str]]#

Return a lookup table of reverse dependencies for all the given ireqs.

Since this is all static, it only works if the dependency cache contains the complete data, otherwise you end up with a partial view. This is typically no problem if you use this function after the entire dependency tree is resolved.

write_cache() None#

Write the cache to disk as JSON.

piptools.cache._implementation_name() str#

Get Python implementation and version.

Similar to PEP 425, however the minor version is separated from the major to differentiate “3.10” and “31.0”.

piptools.cache.read_cache_file(cache_file_path: str) Dict[str, Dict[str, List[str]]]#