Skip to content

Commit 11de599

Browse files
committed
Make stubgen respect MYPY_CACHE_DIR
This is required when using stubgen in a parallel build system, such as GNU make.
1 parent 0061d6e commit 11de599

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mypy/stubgen.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,13 @@ def mypy_options(stubgen_options: Options) -> MypyOptions:
15881588
options.python_version = stubgen_options.pyversion
15891589
options.show_traceback = True
15901590
options.transform_source = remove_misplaced_type_comments
1591+
1592+
# Override cache_dir if provided in the environment
1593+
environ_cache_dir = os.getenv("MYPY_CACHE_DIR", "")
1594+
if environ_cache_dir.strip():
1595+
options.cache_dir = environ_cache_dir
1596+
options.cache_dir = os.path.expanduser(options.cache_dir)
1597+
15911598
return options
15921599

15931600

@@ -1751,6 +1758,9 @@ def generate_stubs(options: Options) -> None:
17511758
manual changes. This directory is assumed to exist.
17521759
"""
17531760

1761+
FOOTER: Final = """Environment variables:
1762+
Define MYPY_CACHE_DIR to override configuration cache_dir path."""
1763+
17541764

17551765
def parse_options(args: list[str]) -> Options:
17561766
parser = argparse.ArgumentParser(prog="stubgen", usage=HEADER, description=DESCRIPTION)

0 commit comments

Comments
 (0)