Skip to content

Commit e0cb9ec

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 bf82b76 commit e0cb9ec

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
@@ -1577,6 +1577,13 @@ def mypy_options(stubgen_options: Options) -> MypyOptions:
15771577
options.python_version = stubgen_options.pyversion
15781578
options.show_traceback = True
15791579
options.transform_source = remove_misplaced_type_comments
1580+
1581+
# Override cache_dir if provided in the environment
1582+
environ_cache_dir = os.getenv("MYPY_CACHE_DIR", "")
1583+
if environ_cache_dir.strip():
1584+
options.cache_dir = environ_cache_dir
1585+
options.cache_dir = os.path.expanduser(options.cache_dir)
1586+
15801587
return options
15811588

15821589

@@ -1737,6 +1744,9 @@ def generate_stubs(options: Options) -> None:
17371744
manual changes. This directory is assumed to exist.
17381745
"""
17391746

1747+
FOOTER: Final = """Environment variables:
1748+
Define MYPY_CACHE_DIR to override configuration cache_dir path."""
1749+
17401750

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

0 commit comments

Comments
 (0)