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

Set local_cache_dir from environment variable? #352

Closed
indigoviolet opened this issue Jul 22, 2023 · 4 comments · Fixed by #361
Closed

Set local_cache_dir from environment variable? #352

indigoviolet opened this issue Jul 22, 2023 · 4 comments · Fixed by #361
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@indigoviolet
Copy link

If I want a persistent cache, I can set CLOUPATHLIB_FILE_CACHE_MODE. But I then have to pass a local_cache_dir in code - why not allow this to also be set from the environment?

@pjbull
Copy link
Member

pjbull commented Jul 22, 2023

Thanks @indigoviolet, good point. We should allow specifying a CLOUDPATHLIB_DEFAULT_CACHE_DIR.

We should check for this in in Client instantiation and use it if present. I think precedence should be:

  • local_cache_dir if passed
  • fallback to CLOUDPATHLIB_DEFAULT_CACHE_DIR if available
  • fallback to TemporaryDirectory like we do now

Would be happy to accept a PR if you're so inclined. PR should include tests and docs.

@pjbull pjbull added enhancement New feature or request good first issue Good for newcomers labels Jul 22, 2023
@indigoviolet
Copy link
Author

Thanks @pjbull, I will try to do that.

Another point I noticed was that there isn't a clean way to set up persistence/local_cache_dir while being agnostic to the type of path via AnyPath -> CloudPath. Do you have a suggestion for how to do that?

@pjbull
Copy link
Member

pjbull commented Jul 27, 2023

Another point I noticed was that there isn't a clean way to set up persistence/local_cache_dir while being agnostic to the type of path via AnyPath -> CloudPath. Do you have a suggestion for how to do that?

Yep, that should be doable with set_as_default_client.

For example:

from cloudpathlib import AnyPath, S3Client

s3 = S3Client(local_cache_dir="./data")
s3.set_as_default_client()

cp = AnyPath("s3://test-bucket/file.txt")
cp.client._local_cache_dir
#> PosixPath('data')

Docs here:
https://cloudpathlib.drivendata.org/v0.15/api-reference/client/#cloudpathlib.client.Client.set_as_default_client

@pjbull
Copy link
Member

pjbull commented Oct 10, 2023

This has beed added and shipped @indigoviolet. Try install 0.16.0 with pip if you want to experiment with it and confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants