From 6bbc3df97213d7b777f3bd236cf7c5825e20b270 Mon Sep 17 00:00:00 2001 From: Aaron Batilo Date: Thu, 20 Jun 2019 12:18:57 -0600 Subject: [PATCH] Have --package usage respect mypy_path (#6926) Fixes #6595 --- mypy/main.py | 2 +- mypy/test/testpep561.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mypy/main.py b/mypy/main.py index a0b210f86feb..14fbee845516 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -755,7 +755,7 @@ def add_invertible_flag(flag: str, # Set target. if special_opts.modules + special_opts.packages: options.build_type = BuildType.MODULE - search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path()), (), ()) + search_paths = SearchPaths((os.getcwd(),), tuple(mypy_path() + options.mypy_path), (), ()) targets = [] # TODO: use the same cache that the BuildManager will cache = FindModuleCache(search_paths, fscache) diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index b88fc6d88634..77d38db00f1b 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -216,6 +216,40 @@ def test_typedpkg(self) -> None: venv_dir=venv_dir, ) + def test_mypy_path_is_respected(self) -> None: + packages = 'packages' + pkg_name = 'a' + with tempfile.TemporaryDirectory() as temp_dir: + old_dir = os.getcwd() + os.chdir(temp_dir) + try: + # Create the pkg for files to go into + full_pkg_name = os.path.join(temp_dir, packages, pkg_name) + os.makedirs(full_pkg_name) + + # Create the empty __init__ file to declare a package + pkg_init_name = os.path.join(temp_dir, packages, pkg_name, '__init__.py') + open(pkg_init_name, 'w', encoding='utf8').close() + + mypy_config_path = os.path.join(temp_dir, 'mypy.ini') + with open(mypy_config_path, 'w') as mypy_file: + mypy_file.write('[mypy]\n') + mypy_file.write('mypy_path = ./{}\n'.format(packages)) + + with self.virtualenv() as venv: + venv_dir, python_executable = venv + + cmd_line_args = [] + if python_executable != sys.executable: + cmd_line_args.append('--python-executable={}'.format(python_executable)) + cmd_line_args.extend(['--config-file', mypy_config_path, + '--package', pkg_name]) + + out, err, returncode = mypy.api.run(cmd_line_args) + assert returncode == 0 + finally: + os.chdir(old_dir) + def test_stub_and_typed_pkg(self) -> None: self.simple_prog.create() with self.virtualenv() as venv: