Skip to content

Commit

Permalink
Have --package usage respect mypy_path (python#6926)
Browse files Browse the repository at this point in the history
  • Loading branch information
abatilo authored and emmatyping committed Jun 20, 2019
1 parent 23dba19 commit 6bbc3df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6bbc3df

Please sign in to comment.