Cross-platform command to return pip's cache directory
See original GitHub issueWhat’s the problem this feature will solve?
From the command-line, I’d like a cross-platform method to get pip’s cache directory, which by default is different per OS.
There’s currently no supported way to do this.
Describe the solution you’d like
PR https://github.com/pypa/pip/pull/6391 is adding pip cache info
to returns the wheels directory, plus some extra info:
$ pip cache info
Cache info:
Location: /Users/hugo/Library/Caches/pip/wheels
Packages: 471
So something like pip cache dir
could be a simplified version of that:
$ pip cache dir
/Users/hugo/Library/Caches/pip
This would be useful for caching with GitHub Actions CI. Right now, the config needs repeating three times, once per OS, which is rather cumbersome (https://github.com/actions/cache/pull/86):
- name: Ubuntu cache
uses: actions/cache@v1
if: startsWith(matrix.os, 'ubuntu')
with:
path: ~/.cache/pip
key:
${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
}}
restore-keys: |
${{ matrix.os }}-${{ matrix.python-version }}-
- name: macOS cache
uses: actions/cache@v1
if: startsWith(matrix.os, 'macOS')
with:
path: ~/Library/Caches/pip
key:
${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
}}
restore-keys: |
${{ matrix.os }}-${{ matrix.python-version }}-
- name: Windows cache
uses: actions/cache@v1
if: startsWith(matrix.os, 'windows')
with:
path: ~\AppData\Local\pip\Cache
key:
${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
}}
restore-keys: |
${{ matrix.os }}-${{ matrix.python-version }}-
Other people also want a cross-platform method:
Alternative Solutions
- The wrong way: use pip’s internal API
Use pip’s private, internal API, which has changed in the past and may change in the future:
$ python -c "from pip._internal.locations import USER_CACHE_DIR; print(USER_CACHE_DIR)"
/Users/hugo/Library/Caches/pip
- Another way: change pip’s cache dir
Provide --cache-dir
or set the PIP_CACHE_DIR
environment variable to whatever path you like and cache that. Or use --user
to install into the user directory, and cache from there.
However, ideally I’d like not to change pip’s behaviour in any way.
We also test on other CIs, and locally, and I’d like pip to use its defaults as much as possible across the board, and have fewer differences across envs.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (9 by maintainers)
Top GitHub Comments
Thanks for the comments! I agree.
To start things off, I’ve created PR https://github.com/pypa/pip/pull/8095 for
pip cache dir
. It’s simpler to implement, and is easier to use for my actual use case: checking the cache dir on a CI.I agree, I’d like to see #6391 land first and don’t wish to delay it.
Just one thing to consider: perhaps rename “Location:” to “Wheels:” in #6391 to avoid doing it later here. But again, bikeshedding/naming also takes time so we can do it here to avoid delaying #6391 😃
And I’ve created https://github.com/pypa/pip/issues/7372 for https://github.com/pypa/pip/pull/6391#issuecomment-554368620.