-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 as file watcher in container with PyCharm truncates file #8552
Comments
I thought that maybe this was an issue with the cache, but I tried setting |
I've tried playing around with different things when this happens to understand what's going on and the oddest thing I've noticed is that undoing the format and then editing the file usually doesn't change anything about the result. Here's an example: This was the function at the end of a file I just edited:
And it was truncated to this:
As mentioned, I undid the change from the format applied on save and then copied a second copy of the function just below it and saved again and it truncated to the same spot. I then did that 2 more times, so there were 4 copies of the function and it did the same thing. I added newlines above the function and after doing that a few times, it returned a result without the truncation and a warning about the multiple definitions of the function. So it appears that the issue is happening on the reading of the file (or else the warning about the multiple definitions would have happened) and it appears that it's using the old length of the file when reading the data and that's what is causing the truncation |
@daveisfera -- Any idea if this is still an issue? |
Yes, it is unfortunately still an issue. I'm guessing it's something to do with the way that PyCharm handles files and edits that isn't playing nice with how |
Sounds mysterious. Does this only happen in a container or also when running it locally? Is my understanding correct that you created a pycharm watcher to run the script or is there another watch task? |
Only when I run it in a container so I've switched to running And yes, it's a PyCharm watcher that's running the script, and I set it up the same way that I used to run |
That's very strange. Could you try adding a random 10ms timeout before calling ruff to emulate Python's startup time 🤣 Have you tried https://plugins.jetbrains.com/plugin/20574-ruff ? |
Do you run into the same issue when using ruff as an external tool? https://docs.astral.sh/ruff/editors/setup/#via-external-tool |
I prefer to run it in a container, because then the version being run is controlled by the code itself and changes automatically roll out to all developers and CI as the commit with the change is merged From my testing so far, putting |
I've setup a file watcher that run
ruff --fix
andruff format
in a docker image. I've run just one of those commands to isolate the issue and have seen it happen when justruff --fix
orruff format
is running so it's happening with either command run separatelyHere's an example of the error output and when I look at the file, several characters from the last few lines have been removed (i.e. the file was truncated):
Here's the scripts that I use as the watcher (which I have setup in the same manner that
black
recommends):On a related note, I know there's a PyCharm plugin but I like running it in a container, because then CI and every developer machine is automagically kept in sync
Here's my
ruff.toml
The text was updated successfully, but these errors were encountered: