Repository navigation
Labels
kind/bugSomething isn't working as expectedSomething isn't working as expected
Description
- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption).
- OS version and name: Windows 10
- Poetry version: 1.0.5
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/mdgilene/0da1568f8ac90615e89cd1331115d80a
Issue
Setting the cache-dir location using either the environment variable POETRY_CACHE_DIR or with poetry config cache-dir /path/to/new/cache does not work. Poetry still uses the default location C:\Users\<user>\AppData\Local\pypoetry\Cache.
This will not work for me as there are size constraints on my user profile directory. Beacuse of this I need to relocate this directory to another drive.
I believe this to be cause by the fact that the environment/config settings are never read when determining the cache location.
poetry/utils/appdirs.py
def user_cache_dir(appname):
r"""
Return full path to the user-specific cache dir for this application.
"appname" is the name of application.
Typical user cache directories are:
macOS: ~/Library/Caches/<AppName>
Unix: ~/.cache/<AppName> (XDG default)
Windows: C:\Users\<username>\AppData\Local\<AppName>\Cache
On Windows the only suggestion in the MSDN docs is that local settings go
in the `CSIDL_LOCAL_APPDATA` directory. This is identical to the
non-roaming app data dir (the default returned by `user_data_dir`). Apps
typically put cache data somewhere *under* the given dir here. Some
examples:
...\Mozilla\Firefox\Profiles\<ProfileName>\Cache
...\Acme\SuperApp\Cache\1.0
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
"""
if WINDOWS:
# Get the base path
path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
# Add our app name and Cache directory to it
path = os.path.join(path, appname, "Cache")
elif sys.platform == "darwin":
# Get the base path
path = expanduser("~/Library/Caches")
# Add our app name to it
path = os.path.join(path, appname)
else:
# Get the base path
path = os.getenv("XDG_CACHE_HOME", expanduser("~/.cache"))
# Add our app name to it
path = os.path.join(path, appname)
return pathReacted by Colin Cyr, Akhilesh Raju, Adam Hodges, Bertrand Bonnefoy-Claudet, Dmitrii Zakharov, Ilya Baryshnikov, Danil Troshnev, James Duley, Daniel Mühlbachler-Pietrzykowski, Ángel Manuel Martín and 3 more
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't working as expectedSomething isn't working as expected
Activity
pwoolvett commentedon Aug 8, 2020
Far from ideal, but as a workaround you can temporarily set/replace
XDG_CACHE_HOME, eg:(tested on 1.0.9)
finswimmer commentedon Aug 12, 2020
Hello,
I tested it with the latest preview release without any problems. Is someone else able to reproduce the issue?
fin swimmer
inseopark commentedon Oct 16, 2020
I've found something strange behavior on this topic.
Using poetry version 1.1.2, on Windows, I wanted run some script runnning with System privileges, I want to set cache-dir set other than Windows system directory.
When testing with normal user account,
only artifacts directory goes into POETRY_CACHE_DIR, but cache\repositories\pypi generated in %LOCALAPPDATA%
mohan43u commentedon Jan 6, 2021
I can confirm this is still happening in Linux. Even after setting POETRY_CACHE_DIR, I see
~/.cache/pypoetry/cache/repositories/pypi/created with contents.Poetry Version: 1.1.4
TBBle commentedon Jan 12, 2021
Perhaps it makes more sense to just drop the "cache-dir" config option, rather than trying to plumb it through the other places that are directly using
locations.CACHE_DIRandlocations.REPOSITORY_CACHE_DIR?Honouring
XDG_CACHE_HOMEis probably sufficient on Posix platforms, and Windows and OS X have pretty clear cache locations as well.mdgilene commentedon Jan 12, 2021
I'm sorry but "just remove it" is not a valid solution. It is common practice among many development tools that utilize a local cache to allow the user to configure where this cache is stored.
My workplace uses network storage for users home directories so that settings can be used on multiple machines. This however means that we are VERY limited on how much can be stored on the user profile (<500Mb). I HAVE to move this cache to another location or I just simply cannot use the tool.
mohan43u commentedon Jan 12, 2021
changing XDG_CACHE_HOME (also XDG_CONFIG_HOME and XDG_DATA_HOME) breaks other apps when we run those apps under 'poetry shell'. Changing
XDG_*_HOMEvariables for other apps under 'poetry shell' is unnecessary and may lead to unwanted results.The change In my PR provides alternate to
XDG_*_HOMEvariables in poetry. So, when POETRY_HOME is available, poetry will use it instead ofXDG_*_HOMEvariables.TBBle commentedon Jan 12, 2021
I don't think
POETRY_HOMEis the right thing to leverage for this, because it's surprising that it would override theXDG_CACHE_HOMEdefault behaviour, and also I'd expect nothing to change inPOETRY_HOMEexcept when using the self-updater (and then only if Poetry was installed byget-poetry.py).Edit: I see that
POETRY_HOMEis only set by the user for certain uses of get-poetry.py, and the self-updater, but it's not actually ensured to be available at any other time as nothing else in the system uses it or is aware of it. So it definitely seems like the wrong thing to use for the cache directory.Anyway, fair 'nuff, if the cache-dir config is useful, then it should only take a few fixes to make it apply, by making sure that nothing directly accesses
location.CACHE_DIRorlocation.REPOSITORY_CACHE_DIR, and instead all such code usesconfig.get("cache-dir"), which correctly defaults tolocation.CACHE_DIR.It might also be good to fix the default for
virtualenvs.path, which is documented as{cache-dir}/virtualenvsbut{cache-dir}here actually means "The default cache-dir", not "the value of the cache-dir configuration", at least on inspection of the config-defaulting code. It's possible this is actually not a problem in practice, the curcumstance where I was changing thecache-dir, I am also usingvirtualenvs.in-projectsovirtualenvs.pathis ignored, so I didn't see any issues with the virtualenv directory.On the last comment, I'm not sure what
poetry shellhas to do with this. If I'm changingXDG_CACHE_HOME, of course I'm changing it for everything. That's the whole point. It doesn't break other apps, it causes them to cache in that directory instead. I wouldn't want this changing under something likepoetry shell, that'd be awful and surprising.My use-case is that I'm running
poetryinside a container, and the defaultXDG_CACHE_HOMEis not writeable (weird container setup, running as non-root but$HOMEis /) so redirecting$XDG_CACHE_HOMEis the correct solution.But in the general case, the cache-env setting should be either fixed or removed. I personally don't mind which, as I don't have a use-case where I need to move just the Poetry cache.
@mdgilene In your circumstance, you probably should be changing
$XDG_CACHE_HOMErather than Poetry'scache-dirsetting, otherwise you'll have to change each application's own cache setting one by one, and are stuck for apps that don't have that feature. Changing$XDG_CACHE_HOMEwill fix all (FreeDesktop-spec compliant) apps at once, which is what I would think you want for the general "cache needs to be redirected elsewhere" use-case.You probably do want to change the
virtualenv.pathsetting if you're putting the cache somewhere temporary; I'm not sure I agree with Poetry that the env is a "cache", but I can see the logic of it.mohan43u commentedon Jan 12, 2021
The PR doesn't modify
POETRY_HOMEdir, it creates hidden directories underPOETRY_HOMEand do the change under those hidden directories.This way, all I have to do in my bootstrap script is set
POETRY_HOMEto one location under the project's root directory, so that everything poetry creates (including get-poetry.py) contained within the project's root directory.the point is why someone has to change
XDG_CACHE_HOMEin the first place in order to make poetry store its cache and virtualenv dirs in a different place.Also, there is no way to make poetry store its config in a different place other than changing
XDG_CONFIG_HOME.In my openion,
XDG_*_HOMEdirs are fallback dirs when the user not explicitly specify where to store the files. But poetry is usingXDG_*_HOMEdirs assuming user is not going to care about providing the locations.TBBle commentedon Jan 12, 2021
Maybe this is a difference of opinion on
XDG_*_HOME, which to me are the way to tell all my apps if I want them putting data somewhere other than~/.cacheor~/.localetc. They're not fallbacks, but the first config target, since I rarely want to tell individual apps to put their caches somewhere different than other apps.Your use of
POETRY_HOMEmakes your PR make more sense, since I'd never thought of using it to put Poetry inside my project (that seems the opposite of the intention of get-poetry.py, which seems focussed on a single, isolated Poetry install). The use-case I had seem forPOETRY_HOMEwas for putting Poetry somewhere other than~/.poetry, e.g. somewhere system wide shared by multiple users, rather than for multi-installing it.But I think in the general case, mutating
POETRY_HOMEoutside the self-updater will hit issues for people wherePOETRY_HOMEis not writable, i.e. the container use-case I mentioned, where I was usingget-poetry.pyearlier, and would have usedPOETRY_HOMEto install it in/poetryas root, but then used it as a regular user."creates hidden directories under
POETRY_HOME" is mutating the contents ofPOETRY_HOME, and will fail ifPOETRY_HOMEis not writable by the user, and would be surprising if I delete and reinstall a get-poetry.py-installed Poetry and expect to not lose my caches. Which I would expect, because caches by default should live in ~/.cache per the FreeDesktop spec. UsingPOETRY_HOMEfirst, since it's not specifically a config for the Poetry cache, but also controls other behaviour, would be in violation of the FreeDesktop spec, and generally surprising to users.Anyway, that PR, and discussion about the use-cases of
POETRY_HOME, doesn't really affect this issue, which is that the existingcache-dirconfig option, which should override the common default of$XDG_CACHE_DIR/pypoetry, is not used consistently within Poetry, and that common default leaks through.Adding another conditional default doesn't fix this issue, it just adds another possible workaround.
parched commentedon Aug 5, 2021
Is there any workaround for this on windows? Perhaps some environment variable like
XDG_CACHE_DIRI can set?I'm running multiple instances of Poetry at one once and I'm getting a conflict in the cache directory.
So I want to use a different cache directory for each invocation. Although, this is probably a separate issue that needs to be addressed.
Add caching to poetry install process.
Initial poc (#2)
arielnmz commentedon Mar 2, 2022
Can confirm this happens in version 1.1.13 in a docker container:
Firing up the container with user 1000 and running
poetry lockfails with this error:It fails because ofc user 1000 does not have access to
/.cache, why is it trying to create a directory there?gshpychka commentedon May 11, 2022
@abn has this been acknowledged? Can we configure the repository cache?
mohan43u commentedon May 24, 2022
this issue should be fixed now. poetry will not create repositories directory (cache/repositories) outside of
cache-dirafter this commit #5672 , see #5301 for more details.abn commentedon May 24, 2022
Resovled by #5672.
adam-grant-hendry commentedon Jun 17, 2022
This is happening for me on
Windowswith version1.2.0b2. Any help would be greatly appreciated:When adding to my packages,
poetryupdates from a cache stored in%LOCALAPPDATA%:mohan43u commentedon Jun 17, 2022
check "Default Directories" section in this doc https://python-poetry.org/docs/master/configuration/ . It provides details about how you can override the default directories
adam-grant-hendry commentedon Jun 17, 2022
@mohan43u Thank you, but I think I have those set already?
The above printout of
config --listshowscache-dirset to the folder I want, andis set as a system environment variable. I even cleared my cache
and regardless
poetryupdates from 33 wheels stored in%LOCALAPPDATA%from the existing version to the same version.Using
-vvvoption when runningpoetry updatedoesn't give me any details for the 33 updates.NOTE: In the above, I've replaced my actual username with "
username". Poetry shows the right path to my%USERPROFILE%.adam-grant-hendry commentedon Jun 17, 2022
@mohan43u @abn After disabling the
experimental.new-installer, poetry began warning that the.dist-infofolders for these packages were invalid and should be removed. In each of these, thedirect_url.jsonfile points to a wheel in%LOCALAPPDATA%.For example,
numpywas one of these and thenumpy-1.22.4.dist-info/direct_url.jsonwas{"archive_info": {}, "url": "file:///C:/Users/username/AppData/Local/pypoetry/Cache/artifacts/7e/42/12/cd512fbb1274bf257081cb661ba45881d717adc618df1a73d3a5532da8/numpy-1.22.4-cp38-cp38-win_amd64.whl"}I believe if
poetryis resolving and/or working with thesejsonfiles that it is resolving them incorrectly and/or writing to them incorrectly. I'm not sure howpoetryuses them. It clearly reads them (otherwise it wouldn't give aninvalid distributionmessage).mohan43u commentedon Jun 18, 2022
@adam-grant-hendry You may need to set three environment variables to alter poetry's default directories instead of single
POETRY_CACHE_DIRadam-grant-hendry commentedon Jun 18, 2022
Oh interesting....
poetry configto set the values and have them stored in theconfig.tomlsuffice? Why do I also need to set environment variables?suvoooo commentedon Jul 20, 2023
Is this the right way to set cache and config dir when installing?
curl -sSL https://install.python-poetry.org | POETRY_HOME=/new/path/to/poetry POETRY_CONFIG_DIR=/new/path/to/poetry/.config POETRY_DATA_DIR=/new/path/to/poetry/ POETRY_CACHE_DIR=/new/path/to/poetry/.cache python3 -because the cache and config are still set to
~/.cache/pypoetryand~/.config/pypoetry. Where I'm doing it wrong?github-actions commentedon Feb 29, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.