Skip to content

Commit 6bbc3df

Browse files
abatiloemmatyping
authored andcommitted
Have --package usage respect mypy_path (#6926)
Fixes #6595
1 parent 23dba19 commit 6bbc3df

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

mypy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def add_invertible_flag(flag: str,
755755
# Set target.
756756
if special_opts.modules + special_opts.packages:
757757
options.build_type = BuildType.MODULE
758-
search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path()), (), ())
758+
search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path() + options.mypy_path), (), ())
759759
targets = []
760760
# TODO: use the same cache that the BuildManager will
761761
cache = FindModuleCache(search_paths, fscache)

mypy/test/testpep561.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,40 @@ def test_typedpkg(self) -> None:
216216
venv_dir=venv_dir,
217217
)
218218

219+
def test_mypy_path_is_respected(self) -> None:
220+
packages = 'packages'
221+
pkg_name = 'a'
222+
with tempfile.TemporaryDirectory() as temp_dir:
223+
old_dir = os.getcwd()
224+
os.chdir(temp_dir)
225+
try:
226+
# Create the pkg for files to go into
227+
full_pkg_name = os.path.join(temp_dir, packages, pkg_name)
228+
os.makedirs(full_pkg_name)
229+
230+
# Create the empty __init__ file to declare a package
231+
pkg_init_name = os.path.join(temp_dir, packages, pkg_name, '__init__.py')
232+
open(pkg_init_name, 'w', encoding='utf8').close()
233+
234+
mypy_config_path = os.path.join(temp_dir, 'mypy.ini')
235+
with open(mypy_config_path, 'w') as mypy_file:
236+
mypy_file.write('[mypy]\n')
237+
mypy_file.write('mypy_path = ./{}\n'.format(packages))
238+
239+
with self.virtualenv() as venv:
240+
venv_dir, python_executable = venv
241+
242+
cmd_line_args = []
243+
if python_executable != sys.executable:
244+
cmd_line_args.append('--python-executable={}'.format(python_executable))
245+
cmd_line_args.extend(['--config-file', mypy_config_path,
246+
'--package', pkg_name])
247+
248+
out, err, returncode = mypy.api.run(cmd_line_args)
249+
assert returncode == 0
250+
finally:
251+
os.chdir(old_dir)
252+
219253
def test_stub_and_typed_pkg(self) -> None:
220254
self.simple_prog.create()
221255
with self.virtualenv() as venv:

0 commit comments

Comments
 (0)