microsoft / vscode-pylint

Linting support for python using the pylint library.
https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
MIT License
70 stars 34 forks source link

Cannot use rcfile above the workspace root #473

Closed dalemyers closed 9 months ago

dalemyers commented 9 months ago

I have a repo with several "projects" in it. They share a common pylint rc file, but are in individual folders other than that. I want to be able to set the command line flag as follows: --rcfile=${workspaceFolder}/../.pylintrc but this does not seem to be supported.

If I run the generated command (the one shown in the output pane), it works as expected. It just doesn't work within VS Code.

I'm running the latest version of VS Code and of the extension.

karthiknadig commented 9 months ago

Can you share the full logs from Output > Pylint? Also absolute paths to the folder you opened in VS Code and absolute path to .pylintrc.

dalemyers commented 9 months ago

Sure:

2023-12-13 11:29:08.681 [info] [Trace - 11:29:08 AM] Sending notification 'textDocument/didSave'.
2023-12-13 11:29:08.683 [info] [Trace - 11:29:08 AM] Received notification 'window/logMessage'.
2023-12-13 11:29:08.683 [info] {BaseRepoPath}/iOS/build_scripts/../../.venv/bin/pylint --reports=n --output-format=json --rcfile={BaseRepoPath}/iOS/build_scripts/../../.pylintrc --extension-pkg-allow-list=mypy --init-hook import sys; sys.path.insert(0, '{BaseRepoPath}/iOS/build_scripts') --clear-cache-post-run=y --from-stdin {BaseRepoPath}/iOS/build_scripts/run_xcwarn.py
2023-12-13 11:29:08.683 [info] {BaseRepoPath}/.venv/bin/python -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin {BaseRepoPath}/iOS/build_scripts/run_xcwarn.py
2023-12-13 11:29:08.683 [info] [Trace - 11:29:08 AM] Received notification 'window/logMessage'.
2023-12-13 11:29:08.683 [info] CWD Server: {BaseRepoPath}/iOS/build_scripts
2023-12-13 11:29:08.683 [info] CWD Linter: {BaseRepoPath}/iOS/build_scripts
2023-12-13 11:29:09.557 [info] file://{BaseRepoPath}/iOS/build_scripts/run_xcwarn.py :
[
    [snipped]
]

2023-12-13 11:29:10.202 [info] [Trace - 11:29:10 AM] Received notification 'textDocument/publishDiagnostics'.

I've replaced the actual root path of my repo with {BaseRepoPath}. The folder I opened was {BaseRepoPath}/iOS/build_scripts. The absolute path of .pylintrc is {BaseRepoPath}/.pylintrc

To be clear, {BaseRepoPath} is not some kind of variable. I've just used it as a placeholder in this issue.

karthiknadig commented 9 months ago

The substitution that we have done seems accurate. I still don't understand what you mean by it does not work with .rcfile. For clarification, this is the exact equivalent of what the extension does.

> cat {BaseRepoPath}/iOS/build_scripts/run_xcwarn.py | {BaseRepoPath}/iOS/build_scripts/../../.venv/bin/pylint --reports=n --output-format=json --rcfile={BaseRepoPath}/iOS/build_scripts/../../.pylintrc --extension-pkg-allow-list=mypy --init-hook import sys; sys.path.insert(0, '{BaseRepoPath}/iOS/build_scripts') --clear-cache-post-run=y --from-stdin {BaseRepoPath}/iOS/build_scripts/run_xcwarn.py

I need lot more detail to reproduce the issue. From what I can tell extension is correctly setting the rcfile path. What I don't understand is how the initial part of the logs look like where we pass the settings info to the server.

From what I suspect the configuration for this project is weird. It seems like you have set the pylint.path somewhere. I will need to see the initial part of the logs where the server starts up and settings are passed to it. Both workspace and global settings are needed. And, if you have any *.code-workspace please share that as well.

dalemyers commented 9 months ago

Ah, so I found the issue. I had "python.pythonPath": "/usr/local/bin/python3", still in my user settings. It seems all other tools were picking up my virtual environment, but the pylint extension wasn't. If I remove that, it works as expected.

I'm not sure if that is still a bug or not though?

karthiknadig commented 9 months ago

pylint extension doesn't automatically select any python. It asks python extension for a python executable. That setting can interfere with python extensions ability to auto-select.