-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Running pylint twice on the same file while changing the file in between runs doesn't work #5888
Comments
I did a little digging and this is because of the following lines: Because we re-use the constant That said, I'm not sure if this is something we should change there, as the caching of |
We're using pylint inside pyodide, so in a WebAssembly environment. It was hard to get it to work because of some dependencies but we managed and got it to work using lint.Run. The user enters code in the browser, we save it to a file called test.py and run pylint on it. For now we have to keep creating test1.py, test2.py etc for each submission which is a terrible solution of course. Any other way we've tried to use pylint programmatically has resulted in issues because it tries to create subprocesses, calls sys.exit or outputs to stdout which is hard to access. I'll be honest I don't fully understand pylint's source code but maybe it would be possible to add an optional parameter to disable caching or something? |
That might be something we could explore, although I'm hesitant to change how the caching in I have no experience with WebAssembly, but I guess you're unable to run |
We're running the javascript code that calls pylint using pyodide.runPython. Unfortunately when you start pyodide it has to load and install all necessary packages before running the code. This would take far too long so unfortunately we cannot restart the process. Maybe it would be possible to add a function to clear the cache? Or maybe that's already possible in which case I'm not quite sure of how you would go about doing that. |
You could try and see if adding: import astroid
from astroid.manager import AstroidManager
astroid.MANAGER = AstroidManager() between the two
|
Hm, I'm going to think about this some more. Perhaps others have better ideas.. |
This seems to work: from pylint import lint
lint.pylinter.MANAGER.astroid_cache = {} |
That does indeed solve the issue, thank you so much for your help. Maybe it's still worth putting in the docs in the FAQ or something? Regardless, thanks for the help. |
Related to pylint-dev/astroid#1242 |
BTW, this is probably the better call: from pylint.lint import pylinter
pylinter.MANAGER.clear_cache() |
Question
So in our code we wanted to run pylint programmatically on the same file "test.py" multiple times while changing the content of the file in between runs. We figured a new reporter and new Run object each call should be enough but it just keeps outputting the same report from the content of the file on the first run.
Below is some code we wrote to test the issue further, using two different kinds of reporters that use 2 different kinds of output streams just to be absolutely 100% sure there is no way the first reporter is being used in the second call.
The file test.py in our tests contained simply
and we just changed a to b in between the Run calls (so when the test program is waiting for input).
You can see the output in the screenshot attachment, the issue is only the report for the original content of test.py is being given twice even though we changed & saved test.py in between calls. Our workaround fix for now is to just keep creating new test1.py, test2.py, etc but that is obviously not a good solution.
Documentation for future user
Either in the "Running pylint section" or FAQ probably.
Additional context
No response
The text was updated successfully, but these errors were encountered: