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

How does pylint decide where it should put stat files? #6394

Closed
karthiknadig opened this issue Apr 19, 2022 · 6 comments · Fixed by #6526
Closed

How does pylint decide where it should put stat files? #6394

karthiknadig opened this issue Apr 19, 2022 · 6 comments · Fixed by #6526
Assignees
Labels
Bug 🪲 Windows 🪟 Bug affecting only Windows users
Milestone

Comments

@karthiknadig
Copy link
Contributor

karthiknadig commented Apr 19, 2022

Question

I am from the VS Code python extension team, working on building an extension for VS Code using pylint. We have pre-release version out. An issue was reported on the extension that it creates pylint stat files in the project directory. We are not specifically passing anything to change the stat file location (see issue here microsoft/vscode-pylint#30).

Generally, the stat files go into pre-set directory like %USERPROFILE%/AppData/Local/pylint on windows. What can cause these to be written to the current working directory.

We use pass the source code into pylint via stdin, and the only two arguments we use are --reports=n, --output-format=json. Any clue to debug this would be helpful.

Documentation for future user

I could not find fall back location for the stat files and when would the fallback location be used.

Additional context

We use runpy.run_module to run pylint, and we send source to pylint via stdin.
Relevant code here: https://github.com/microsoft/vscode-pylint/blob/725fc7ae415a9638e2a44e922cf5133efde62811/bundled/linter/utils.py#L146-L168

@karthiknadig karthiknadig added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 19, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Question and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 19, 2022
@Pierre-Sassoulas
Copy link
Member

One thing that could prevent using the XDG_HOME is if an env var for PYLINTHOME exists.

Relevant code:
https://github.com/PyCQA/pylint/blob/main/pylint/constants.py#L54
https://github.com/PyCQA/pylint/blob/main/pylint/config/__init__.py#L39

@DanielNoord
Copy link
Collaborator

Another issue might be that by using stdin the FileItem used by our main PyLinter class has a non-sensical file name.
That file name is used by the following function to determine a part of the file to be saved to:
https://github.com/PyCQA/pylint/blob/ae5ed5c57a8f9a60a37bd010be052b08aa864de7/pylint/lint/pylinter.py#L1038

I followed the mentioned topic somewhat but haven't fully kept up. Is there an easily reproducible example? I'd be happy to try and investigate what is happening inside save_results.

diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py
index b8fb0a0b..87b9ef24 100644
--- a/pylint/config/__init__.py
+++ b/pylint/config/__init__.py
@@ -95,12 +95,15 @@ def load_results(base):
 
 
 def save_results(results, base):
+    print(base)
+    print(PYLINT_HOME)
     if not os.path.exists(PYLINT_HOME):
         try:
             os.makedirs(PYLINT_HOME)
         except OSError:
             print(f"Unable to create directory {PYLINT_HOME}", file=sys.stderr)
     data_file = _get_pdata_path(base, 1)
+    print(data_file)
     try:
         with open(data_file, "wb") as stream:
             pickle.dump(results, stream)

Could also help investigate some of the variables within that function.

@karthiknadig
Copy link
Contributor Author

karthiknadig commented Apr 19, 2022

@DanielNoord @Pierre-Sassoulas Thanks for the input, I will try and look into it.

for the minimal repro, unfortunately we have not been able to narrow down the parameters that cause. It seems to be specific to the permissions and how the server hosting pylint itself is launched. The information above might help narrow this down.

@DanielNoord
Copy link
Collaborator

@karthiknadig Feel free to ping me in the other issue if needed! I'd be glad to provide any other diffs or fix-branches that might solve the issue. From what I gathered from the discussion until now it is still not clear whether the issue is with the user, the extension or pylint's internals. Happy to help narrow that down!

@alkatar21
Copy link

I have opened the issue for the extension. I think I found the reason (microsoft/vscode-pylint#30 (comment)) and there is now a reproducible example (microsoft/vscode-pylint#30 (comment)).

@DanielNoord DanielNoord added Bug 🪲 Windows 🪟 Bug affecting only Windows users and removed Question labels May 5, 2022
@DanielNoord DanielNoord self-assigned this May 5, 2022
@DanielNoord
Copy link
Collaborator

Just to update: I have been working on a fix in DanielNoord#135. I just need to test with the original reporter once more if this does indeed work and then I'll submit the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Windows 🪟 Bug affecting only Windows users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants