Skip to content

Cache directory may be set via environment (#7016) #7443

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

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ beyond what incremental mode can offer, try running mypy in
change this folder. This flag can also be useful for controlling
cache use when using :ref:`remote caching <remote-cache>`.

This setting will override the ``MYPY_CACHE_DIR`` environment
variable if it is set.

Mypy will also always write to the cache even when incremental
mode is disabled so it can "warm up" the cache. To disable
writing to the cache, use ``--cache-dir=/dev/null`` (UNIX)
Expand Down
2 changes: 2 additions & 0 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ section of the command line docs.
``cache_dir`` (string, default ``.mypy_cache``)
Specifies the location where mypy stores incremental cache info.
User home directory and environment variables will be expanded.
This setting will be overridden by the ``MYPY_CACHE_DIR`` environment
variable.

Note that the cache is only read when incremental mode is enabled
but is always written to, unless the value is set to ``/dev/nul``
Expand Down
8 changes: 7 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def infer_python_executable(options: Options,
""" # type: Final

FOOTER = """Environment variables:
Define MYPYPATH for additional module search path entries.""" # type: Final
Define MYPYPATH for additional module search path entries.
Define MYPY_CACHE_DIR to override configuration cache_dir path.""" # type: Final


def process_options(args: List[str],
Expand Down Expand Up @@ -704,6 +705,11 @@ def add_invertible_flag(flag: str,
for dest, value in strict_flag_assignments:
setattr(options, dest, value)

# Override cache_dir if provided in the environment
environ_cache_dir = os.getenv('MYPY_CACHE_DIR', '')
if environ_cache_dir.strip():
options.cache_dir = environ_cache_dir

# Parse command line for real, using a split namespace.
special_opts = argparse.Namespace()
parser.parse_args(args, SplitNamespace(options, special_opts, 'special-opts:'))
Expand Down