Alter fallback when source-root
based package path discovery when a source root containing the module directory is not found
#9955
Labels
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 besrc
when callingpylint
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 thetest
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 aSequence[str]
instead ofstr
. Forsrc
layout, there would only be onesource-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)
After the change, pylint command would be:
Note that this would be a general solution for a project with or without implicit namespace packages.
Additional context
No response
The text was updated successfully, but these errors were encountered: