Skip to content

Commit 385ce42

Browse files
committed
Allow package files to be properly discovered with multiple jobs
Close #3524
1 parent 1664303 commit 385ce42

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Release date: TBA
2626

2727
Close #3563
2828

29+
* Allow package files to be properly discovered with multiple jobs
30+
31+
Close #3524
32+
2933
What's New in Pylint 2.5.0?
3034
===========================
3135

pylint/utils/utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ def _basename_in_blacklist_re(base_name, black_list_re):
104104
return False
105105

106106

107-
def _modpath_from_file(filename, is_namespace):
107+
def _modpath_from_file(filename, is_namespace, path=None):
108108
def _is_package_cb(path, parts):
109109
return modutils.check_modpath_has_init(path, parts) or is_namespace
110110

111111
return modutils.modpath_from_file_with_callback(
112-
filename, is_package_cb=_is_package_cb
112+
filename, path=path, is_package_cb=_is_package_cb
113113
)
114114

115115

@@ -200,7 +200,6 @@ def expand_modules(files_or_modules, black_list, black_list_re):
200200
not (modname.endswith(".__init__") or modname == "__init__")
201201
and os.path.basename(filepath) == "__init__.py"
202202
)
203-
204203
if has_init or is_namespace or is_directory:
205204
for subfilepath in modutils.get_module_files(
206205
os.path.dirname(filepath), black_list, list_all=is_namespace
@@ -212,7 +211,9 @@ def expand_modules(files_or_modules, black_list, black_list_re):
212211
):
213212
continue
214213

215-
modpath = _modpath_from_file(subfilepath, is_namespace)
214+
modpath = _modpath_from_file(
215+
subfilepath, is_namespace, path=additional_search_path
216+
)
216217
submodname = ".".join(modpath)
217218
result.append(
218219
{

tests/test_self.py

+31
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,34 @@ def test_do_not_import_files_from_local_directory(tmpdir):
732732
],
733733
cwd=str(tmpdir),
734734
)
735+
736+
def test_allow_import_of_files_found_in_modules_during_parallel_check(self, tmpdir):
737+
test_directory = tmpdir / "test_directory"
738+
test_directory.mkdir()
739+
spam_module = test_directory / "spam.py"
740+
spam_module.write("'Empty'")
741+
742+
init_module = test_directory / "__init__.py"
743+
init_module.write("'Empty'")
744+
745+
# For multiple jobs we could not find the `spam.py` file.
746+
with tmpdir.as_cwd():
747+
self._runtest(
748+
[
749+
"-j2",
750+
"--disable=missing-docstring, missing-final-newline",
751+
"test_directory",
752+
],
753+
code=0,
754+
)
755+
756+
# A single job should be fine as well
757+
with tmpdir.as_cwd():
758+
self._runtest(
759+
[
760+
"-j1",
761+
"--disable=missing-docstring, missing-final-newline",
762+
"test_directory",
763+
],
764+
code=0,
765+
)

0 commit comments

Comments
 (0)