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

Alter fallback when source-root based package path discovery when a source root containing the module directory is not found #9955

Open
akamat10 opened this issue Sep 24, 2024 · 1 comment · May be fixed by #9967
Labels
Import system Needs decision 🔒 Needs a decision before implemention or rejection

Comments

@akamat10
Copy link
Contributor

akamat10 commented Sep 24, 2024

Current problem

A common setup for repos is to use the src layout discussed here. Currently, for src layouts, we could set --source-roots to be src when calling pylint with the source. This avoids the legacy issue of import discovery if there are namespace packages. One issue with the solution is that, if the user wants to also lint say the test directory in the repo, this solution does not work. That is because currently if a source root doesn't contain the module or directory passed to pylint for linting, it will fallback to legacy behavior of walking the directory. This will lead to import errors when linting the test files.

Desired solution

Alter the fallback logic when source-root containing module directory is not found here to return a list of source-roots. This requires changing the function return type to be a Sequence[str] instead of str. For src layout, there would only be one source-root. This would neatly work for the above case. Let me know your thoughts.

Sample project layout (borrowed from https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html)

pyproject.toml
src/
    mypkg/
        __init__.py
        app.py
        view.py
tests/
    test_app.py
    test_view.py
    ...

After the change, pylint command would be:

pylint --source-roots=src .

Note that this would be a general solution for a project with or without implicit namespace packages.

Additional context

No response

@akamat10 akamat10 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 24, 2024
@akamat10 akamat10 changed the title Alter fallback when source-root based package path discovery when a source root containing the module directory is not found Alter fallback when source-root based package path discovery when a source root containing the module directory is not found Sep 24, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Needs decision 🔒 Needs a decision before implemention or rejection and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 24, 2024
@akamat10 akamat10 linked a pull request Sep 25, 2024 that will close this issue
2 tasks
@akamat10
Copy link
Contributor Author

Implementation provided in #9967. Doesn't seem to break any regressions tests or files other than having to make changes since return type changes from str to Sequence[str]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Import system Needs decision 🔒 Needs a decision before implemention or rejection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants