Skip to content

Feature request: Cache directory environment variable #7016

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

Closed
hetmankp opened this issue Jun 18, 2019 · 6 comments · Fixed by #7443
Closed

Feature request: Cache directory environment variable #7016

hetmankp opened this issue Jun 18, 2019 · 6 comments · Fixed by #7443

Comments

@hetmankp
Copy link
Contributor

The cache directory can currently be customised using the --cache-dir argument. It would be convenient to also be able to do this using an environment variable akin to the MYPYPATH variable.

For very large projects that are not pure Python and contain multiple Python packages within the source tree, both the search path and cache directory often need to be customised for the entire project. Being able to do this via the environment is very convenient. Additionally, environment variables can often provide more flexible options when dealing with wrapper tools.

I would be happy to provide the implementation if this feature is considered reasonable.

@ilevkivskyi
Copy link
Member

I think it may be a reasonable thing to add, please go ahead with a PR.

@hetmankp
Copy link
Contributor Author

hetmankp commented Aug 13, 2019

I'm happy to provide an implementation however the one thing that is still not obvious to me is whether the environment should take precedence over the config file or the other way around.

Making the environment variable take precedence would give any wrapper scripts ultimate control, however it seems like in some circumstances this could lead to unexpected results as a localised config file option may be unexpectedly overridden by a more global environment setting.

I think I would err on the side of removing potentially confusing situations at the cost of perhaps reducing the power of this feature and make the config file take precedence over the environment variable.

Any thoughts?

@ilevkivskyi
Copy link
Member

I would try to match behaviour here with the one of MYPYPATH vs mypy_path as much as possible.

@hetmankp
Copy link
Contributor Author

That would have been ideal but for MYPYPATH and mypy_path both are merged. In the case of cache_dir this is not possible as there is only a single path that can apply (rather than a set of paths) so either it or the environment variable would have to take precedence.

@ilevkivskyi
Copy link
Member

That would have been ideal but for MYPYPATH and mypy_path both are merged. In the case of cache_dir this is not possible as there is only a single path that can apply

Well, but when you merge something, one part goes first, and another goes last, why can't we have the same "order" here?

@hetmankp
Copy link
Contributor Author

Sure I can do that. It's just that that order makes the environment variable take precedence. I mean it should be fine as long as it's clear that the environment variable should not be used as a default fallback and I can clarify that in the documentation.

hetmankp added a commit to hetmankp/mypy that referenced this issue Sep 2, 2019
This adds an environment variable MYPY_CACHE_DIR which can set the
current cache directory. This variable will override the cache_dir
setting in the configuration but can be overridden via the command line.
Fixes python#7016.
ilevkivskyi pushed a commit that referenced this issue Sep 2, 2019
This adds an environment variable MYPY_CACHE_DIR which can set the
current cache directory. This variable will override the cache_dir
setting in the configuration but can be overridden via the command line.
Fixes #7016.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants