Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure cache directory with an environment variable #435

Closed
pawamoy opened this issue May 3, 2021 · 5 comments
Closed

Configure cache directory with an environment variable #435

pawamoy opened this issue May 3, 2021 · 5 comments
Labels
⭐ enhancement Improvements for existing features

Comments

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented May 3, 2021

Is your feature request related to a problem? Please describe.

In CI, my scripts run without a proper user set (no HOME), so the cache directory end up being /.cache, which triggers PermissionDenied errors. Looking at this table (which is absolutely fantastic to have, thanks), it seems that the cache directory, contrary to other settings, cannot be configured using an environment variable. Is there a reason for this? Maybe the docs simply don't state it while it exists?

Currently the only option is to run pdm config cache_dir /my/cache/directory in each CI job.

Describe the solution you'd like

Instead of having to run the pdm config command, I'd prefer configuring this with an environment variable, once and for all jobs.

@pawamoy pawamoy added the ⭐ enhancement Improvements for existing features label May 3, 2021
@pawamoy
Copy link
Sponsor Contributor Author

pawamoy commented May 3, 2021

I need this even more now, because it turns out I can't even run pdm config cache_dir /my/cache/directory since PDM then tries to write the config in /.pdm, for which I also get a PermissionDenied error 😕 (not your fault of course)
I guess this /.pdm paths is obtained because it's the OS config path? Would it help if I set HOME or XDG_CONFIG_PATH to another directory?

@pawamoy
Copy link
Sponsor Contributor Author

pawamoy commented May 4, 2021

I was able to work around this:

export HOME=/tmp/home
mkdir -p $HOME
pdm config cache_dir /tmp/.pdm_cache

It would definitely be easier to be able to do PDM_CACHE_DIR=/tmp/.pdm_cache instead 😄
I guess more users could face the same issue in CI.

By the way, you should probably try to respect the XDG config instead of using Path.home() / ".pdm" for PDM config directory, but that's another issue.

@frostming
Copy link
Collaborator

frostming commented May 6, 2021

I guess this single line would do the trick:

export HOME=/tmp/home

The config system is designed in a way that allows 3 levels of modification:

  • Per machine (global config)
  • Per project (local config)
  • Per run (env var)

This is why only part of the config variables are available in the project or allow being overridden by env vars(refer to the table). And caches belong to the first category. Although users can persist the env vars across multiple runs, it is not recommended to do so. IMHO CI systems or workflows should be responsible for setting up the environment correctly to run scripts. Many tools have prerequisites, and the prerequisites of PDM is that it requires HOME to exist and it doesn't sound irreasonable.

@pawamoy
Copy link
Sponsor Contributor Author

pawamoy commented May 6, 2021

Oh, I see. Setting the HOME variable will actually allow PDM to create the $HOME/.pdm and $HOME/.cache/pdm directories without a permission error. I'll try that, thank you @frostming 🙂

@frostming
Copy link
Collaborator

Close this since a workaround is provided. PDM_CACHE_DIR=xxx pdm install looks not so good to me. It breaks the centralized cache assumption and pdm cache commands can't manage them correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

No branches or pull requests

2 participants