Open tan-wei-xin-alez opened 1 year ago
Workaround used in my case was cwd
parameter since pylint
was being called via subprocess
module e.g.
pylint_output = subprocess.check_output(
cwd=<working_directory_path>,
args=["pylint", <args>],
stderr=subprocess.STDOUT
).decode("utf-8")
Hi, thanks for the report.
pylint depends on isort's determination of what's first-party and third-party. I set up your minimal example (which is excellent!), replaced pylint
with another package (because I have my editable install of pylint on my path), and I ran isort path/to/package
from repo_dir
and from root_dir
and observed the same difference.
For that reason, I don't think there is a functional issue here. This does come up with some frequency (see #4437), so I think we should update the docs to indicate that if you want to lint a package, you should probably cd
to that package.
pylint output should be the same regardless of where it was run from so long as settings are the same
In other words, I don't think that's part of pylint's contract, since sys.path
depends on the working directory.
@jacobtylerwalls would it not be possible to introduce something like a cwd
parameter to pylint
? Would make it more explicit for users who are forced to run pylint
from other directories
Possibly, but if the only reason for it is to give information to isort
, I'm wondering if it's better to just configure isort
. Does adding module1 and module2 as known first-party imports help?
@jacobtylerwalls oh didn't see that option, only saw known-third-party
imports in the rcfile I was using, that makes a lot more sense, should have searched that up more thoroughly σ(^_^;)
Bug description
The working directory from where
pylint
binary was run influences whether it outputs thewrong-import-order
coding convention error or notConfiguration
Given the following directory structure
with the following file contents
[project] name = "pylint-wrong-import-order-bug-minimal-example" version = "0.0.1" requires-python = ">=3.11" dependencies = [ "pylint" ]
'''Module 1 '''
import module2
import pylint
def function1(): '''Function 1 ''' module2.function2() print(f"{pylint.version}")
if name == "main": function1()
'''Init for module1 '''
'''Module 2 '''
def function2(): '''Function 2 '''
'''Init for module2 '''
from .function2 import function2
***** Module module1.function1 src/module1/function1.py:6:0: C0411: third party import "import pylint" should be placed before "import module2" (wrong-import-order)
Pylint output
Expected behavior
pylint
output should be the same regardless of where it was run from so long as settings are the samePylint version
OS / Environment
Additional dependencies
Compiled with
pdm update --project root_dir/repo_dir