Add support for env variable TACH_CACHE_DIR#775
Add support for env variable TACH_CACHE_DIR#775luukvhoudt wants to merge 1 commit intotach-org:mainfrom
TACH_CACHE_DIR#775Conversation
There was a problem hiding this comment.
thanks for the contribution
docs/usage/caching.md
Outdated
| ## Cache storage | ||
|
|
||
| The computation cache exists within the `.tach` directory in your project root. The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. | ||
| The computation cache exists within the directory defined by the `TACH_CACHE_DIR` environment variable (default is `.tach`). The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. |
There was a problem hiding this comment.
| The computation cache exists within the directory defined by the `TACH_CACHE_DIR` environment variable (default is `.tach`). The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. | |
| The computation cache exists within the directory defined by the `TACH_CACHE_DIR` environment variable (default is `.tach` in your project root). The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. |
python/tach/cache/setup.py
Outdated
| path_is_not_absolute_re = compile(r'^(?![a-zA-Z]:[\\/]|\\\\|/|~[/\\])') if os_name == 'nt' else compile(r'^[^/~]') | ||
| if match(path_is_not_absolute_re, env_value): |
There was a problem hiding this comment.
can we use is_absolute from pathlib.Path here
5e8b1fa to
f54a1ab
Compare
Fallback is `.tach` in the project root. If the value of `TACH_CACHE_DIR` is a relative path, then it is relative to the project root.
f54a1ab to
b0e4aab
Compare
| .join( | ||
| match env::var(ENV_KEY_CACHE_DIR) { | ||
| Ok(env_value) => env_value, | ||
| Err() => DEFAULT_CACHE_DIR, | ||
| } | ||
| ) |
There was a problem hiding this comment.
nit: you can use unwrap_or_else here
| .join( | |
| match env::var(ENV_KEY_CACHE_DIR) { | |
| Ok(env_value) => env_value, | |
| Err() => DEFAULT_CACHE_DIR, | |
| } | |
| ) | |
| .join( | |
| env::var(ENV_KEY_CACHE_DIR) | |
| .unwrap_or_else(|_| DEFAULT_CACHE_DIR), | |
| ) |
| ## Cache storage | ||
|
|
||
| The computation cache exists within the `.tach` directory in your project root. The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. | ||
| The computation cache exists within the directory defined by the `TACH_CACHE_DIR` environment variable (default is `.tach` in your project root). The directory is managed by Tach, and your cached results are stored on-disk on each machine where tasks are run. |
There was a problem hiding this comment.
thinking about this some more, would it be better to specify the cache dir in the config file and/or as a CLI argument? just wondering since i don't think tach has anything else configured via environment variables.
do you mind sharing a bit more info about your use case?
There was a problem hiding this comment.
Not sure if I can recall the exact use case because it has been a while since I've worked on the project that uses tach. I guess it had something to do that I wanted to do with docker.
There was a problem hiding this comment.
in that case i think i'll just leave this PR open for now and wait to see if anybody else has a use case for it
Fallback is
.tachin the project root. If the value ofTACH_CACHE_DIRis a relative path, then it is relative to the project root.