Skip to content
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 @@ -1052,6 +1052,9 @@ enabled by default starting from mypy 2.0.
disables parallel checking. Automatic detection of the optimal number
of workers is not supported yet.

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

Notes:

* An import cycle is always processed as a whole by a worker process. Thus,
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 @@ -1018,6 +1018,8 @@ These options may only be set in the global section (``[mypy]``).

Use specific number of parallel worker processes for type-checking, see
:ref:`parallel type-checking <parallel>` for more details.
This setting will be overridden by the ``MYPY_NUM_WORKERS`` environment
variable.


Advanced options
Expand Down
11 changes: 10 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def infer_python_executable(options: Options, special_opts: argparse.Namespace)

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


class CapturableArgumentParser(argparse.ArgumentParser):
Expand Down Expand Up @@ -1465,6 +1466,14 @@ def set_strict_flags() -> None:
options.cache_dir = environ_cache_dir
options.cache_dir = os.path.expanduser(options.cache_dir)

# Override num_workers if provided in the environment
environ_num_workers = os.getenv("MYPY_NUM_WORKERS", "")
if environ_num_workers.strip():
try:
options.num_workers = int(environ_num_workers)
except ValueError:
parser.error(f"MYPY_NUM_WORKERS must be an integer, got {environ_num_workers!r}")

# 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
Loading