@@ -34,6 +34,14 @@ def parse_version(v: str) -> Tuple[int, int]:
34
34
return major , minor
35
35
36
36
37
+ def expand_path (path : str ) -> str :
38
+ """Expand the user home directory and any environment variables contained within
39
+ the provided path.
40
+ """
41
+
42
+ return os .path .expandvars (os .path .expanduser (path ))
43
+
44
+
37
45
def split_and_match_files (paths : str ) -> List [str ]:
38
46
"""Take a string representing a list of files/directories (with support for globbing
39
47
through the glob library).
@@ -45,7 +53,7 @@ def split_and_match_files(paths: str) -> List[str]:
45
53
expanded_paths = []
46
54
47
55
for path in paths .split (',' ):
48
- path = path .strip ()
56
+ path = expand_path ( path .strip () )
49
57
globbed_files = fileglob .glob (path , recursive = True )
50
58
if globbed_files :
51
59
expanded_paths .extend (globbed_files )
@@ -63,8 +71,8 @@ def split_and_match_files(paths: str) -> List[str]:
63
71
'python_version' : parse_version ,
64
72
'strict_optional_whitelist' : lambda s : s .split (),
65
73
'custom_typing_module' : str ,
66
- 'custom_typeshed_dir' : str ,
67
- 'mypy_path' : lambda s : [p .strip () for p in re .split ('[,:]' , s )],
74
+ 'custom_typeshed_dir' : expand_path ,
75
+ 'mypy_path' : lambda s : [expand_path ( p .strip () ) for p in re .split ('[,:]' , s )],
68
76
'files' : split_and_match_files ,
69
77
'quickstart_file' : str ,
70
78
'junit_xml' : str ,
@@ -75,6 +83,8 @@ def split_and_match_files(paths: str) -> List[str]:
75
83
'always_true' : lambda s : [p .strip () for p in s .split (',' )],
76
84
'always_false' : lambda s : [p .strip () for p in s .split (',' )],
77
85
'package_root' : lambda s : [p .strip () for p in s .split (',' )],
86
+ 'cache_dir' : expand_path ,
87
+ 'python_executable' : expand_path ,
78
88
} # type: Final
79
89
80
90
@@ -223,8 +233,6 @@ def parse_section(prefix: str, template: Options,
223
233
except ValueError as err :
224
234
print ("%s%s: %s" % (prefix , key , err ), file = stderr )
225
235
continue
226
- if key == 'cache_dir' :
227
- v = os .path .expandvars (os .path .expanduser (v ))
228
236
if key == 'silent_imports' :
229
237
print ("%ssilent_imports has been replaced by "
230
238
"ignore_missing_imports=True; follow_imports=skip" % prefix , file = stderr )
0 commit comments