Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved module path discovery when source-roots are not specified #9910

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def discover_package_path(modulepath: str, source_roots: Sequence[str]) -> str:
if os.path.commonpath([source_root, dirname]) == source_root:
return source_root

# Logic if source_roots are not specified.
# This is inline with how python treats scripts and modules.
# See https://docs.python.org/3/library/sys_path_init.html
# If input is a script(ie file), the directory of the script is first in sys.path.
# Otherwise, the current directory is first in sys.path
if len(source_roots) == 0:
if os.path.isfile(modulepath):
return dirname
else:
return os.getcwd()

# TODO: Is this still needed?
# Fall back to legacy discovery by looking for __init__.py upwards as
# it's the only way given that source root was not found or was not provided
while True:
Expand Down
Loading