diff --git a/docs/source/command_line.rst b/docs/source/command_line.rst index c1fd4ad6446b..b8e4c7c187ba 100644 --- a/docs/source/command_line.rst +++ b/docs/source/command_line.rst @@ -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, diff --git a/docs/source/config_file.rst b/docs/source/config_file.rst index 4f2fddaeba8c..d5431b1476aa 100644 --- a/docs/source/config_file.rst +++ b/docs/source/config_file.rst @@ -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 ` for more details. + This setting will be overridden by the ``MYPY_NUM_WORKERS`` environment + variable. Advanced options diff --git a/mypy/main.py b/mypy/main.py index 040275984fb6..9227e24680ce 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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): @@ -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:"))