Skip to content

Commit 289f643

Browse files
committed
Allow user to specify custom typeshed directory
1 parent 4c11bb3 commit 289f643

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

mypy/build.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,20 @@ def build(sources: List[BuildSource],
125125
directories; if omitted, use '.' as the data directory
126126
"""
127127

128-
data_dir = default_data_dir(bin_dir)
128+
custom_typeshed_name = None
129+
if options.custom_typeshed_dir:
130+
custom_data_dir, custom_typeshed_name = os.path.split(
131+
options.custom_typeshed_dir.rstrip(os.sep))
132+
data_dir = custom_data_dir
133+
else:
134+
data_dir = default_data_dir(bin_dir)
129135

130136
find_module_clear_caches()
131137

132138
# Determine the default module search path.
133-
lib_path = default_lib_path(data_dir, options.python_version)
139+
lib_path = default_lib_path(data_dir,
140+
options.python_version,
141+
custom_typeshed_name=custom_typeshed_name)
134142

135143
if options.use_builtins_fixtures:
136144
# Use stub builtins (to speed up test cases and to make them easier to
@@ -244,10 +252,13 @@ def mypy_path() -> List[str]:
244252
return path_env.split(os.pathsep)
245253

246254

247-
def default_lib_path(data_dir: str, pyversion: Tuple[int, int]) -> List[str]:
255+
def default_lib_path(data_dir: str,
256+
pyversion: Tuple[int, int],
257+
custom_typeshed_name: str = None) -> List[str]:
248258
"""Return default standard library search paths."""
249259
# IDEA: Make this more portable.
250260
path = [] # type: List[str]
261+
typeshed_name = custom_typeshed_name or 'typeshed'
251262

252263
auto = os.path.join(data_dir, 'stubs-auto')
253264
if os.path.isdir(auto):
@@ -261,7 +272,7 @@ def default_lib_path(data_dir: str, pyversion: Tuple[int, int]) -> List[str]:
261272
# (Note that 3.1 and 3.0 aren't really supported, but we don't care.)
262273
for v in versions + [str(pyversion[0]), '2and3']:
263274
for lib_type in ['stdlib', 'third_party']:
264-
stubdir = os.path.join(data_dir, 'typeshed', lib_type, v)
275+
stubdir = os.path.join(data_dir, typeshed_name, lib_type, v)
265276
if os.path.isdir(stubdir):
266277
path.append(stubdir)
267278

mypy/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def parse_version(v: str) -> Tuple[int, int]:
180180
help="dump type inference stats")
181181
parser.add_argument('--custom-typing', metavar='MODULE', dest='custom_typing_module',
182182
help="use a custom typing module")
183+
parser.add_argument('--custom-typeshed-dir', metavar='DIR',
184+
help="use the custom typeshed in DIR")
183185

184186
report_group = parser.add_argument_group(
185187
title='report generation',

mypy/options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def __init__(self) -> None:
1616
# -- build options --
1717
self.build_type = BuildType.STANDARD
1818
self.python_version = defaults.PYTHON3_VERSION
19-
self.custom_typing_module = None # type: str
19+
self.custom_typing_module = None # type: Optional[str]
20+
self.custom_typeshed_dir = None # type: Optional[str]
2021
self.report_dirs = {} # type: Dict[str, str]
2122
self.silent_imports = False
2223
self.almost_silent = False

0 commit comments

Comments
 (0)