Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def create_source_list(
finder = SourceFinder(fscache, options)

sources = []
empty_dirs = []
for path in paths:
path = os.path.normpath(path)
if path.endswith(PY_EXTENSIONS):
Expand All @@ -47,11 +48,14 @@ def create_source_list(
elif fscache.isdir(path):
sub_sources = finder.find_sources_in_dir(path)
if not sub_sources and not allow_empty_dir:
raise InvalidSourceList(f"There are no .py[i] files in directory '{path}'")
empty_dirs.append(path)
sources.extend(sub_sources)
else:
mod = os.path.basename(path) if options.scripts_are_modules else None
sources.append(BuildSource(path, mod, None))
if not sources and empty_dirs:
empty_dirs_str = ", ".join(map(repr, empty_dirs))
raise InvalidSourceList(f"There are no .py[i] files in directories: {empty_dirs_str}")
return sources


Expand Down
10 changes: 10 additions & 0 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ def test_find_sources_in_dir_namespace_multi_dir(self) -> None:
finder = SourceFinder(FakeFSCache({"/a/pkg/a.py", "/b/pkg/b.py"}), options)
assert find_sources_in_dir(finder, "/") == [("pkg.a", "/a"), ("pkg.b", "/b")]

def test_find_sources_with_empty_directory(self) -> None:
options = Options()
fscache = FakeFSCache({"/empty/README", "/other'empty/README", "/src/a.py"})

assert find_sources(["/empty", "/src"], options, fscache) == [("a", "/src")]
with pytest.raises(InvalidSourceList, match="directories") as exc_info:
find_sources(["/empty", "/other'empty"], options, fscache)
assert repr(os.path.abspath("/empty")) in str(exc_info.value)
assert repr(os.path.abspath("/other'empty")) in str(exc_info.value)

def test_find_sources_exclude(self) -> None:
options = Options()
options.namespace_packages = True
Expand Down
Loading