Skip to content

Running as file watcher in container with PyCharm truncates file #8552

Open
@daveisfera

Description

I've setup a file watcher that run ruff --fix and ruff format in a docker image. I've run just one of those commands to isolate the issue and have seen it happen when just ruff --fix or ruff format is running so it's happening with either command run separately

Here'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):

/Users/dlj/projects/myproject/local/format_file.sh myfile.py
error: Failed to parse myfile.py:117:5: Unexpected token 'exc'
Found 1 error (1 fixed, 0 remaining).
error: Failed to format myfile.py: source contains syntax errors: ParseError { error: UnrecognizedToken(Name { name: "exc" }, None), offset: 3254, source_path: "<filename>" }

Process finished with exit code 2

Here's the scripts that I use as the watcher (which I have setup in the same manner that black recommends):

#!/usr/bin/env sh

cd "$(dirname "$0")/.." || exit

if ! local/_run_ruff.sh --fix "$@"; then
  exit 1
fi
local/_run_ruff.sh format "$@"
exit $?
#!/usr/bin/env sh

cd "$(dirname "$0")/.." || exit

docker run --rm \
  -v "${PWD}":/usr/src/app:z,cached \
  -w /usr/src/app \
  ruff:0.1.4 \
  /usr/local/bin/ruff "$@"
exit $?

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

line-length = 120

select = ["C", "I", "U", "W"]
ignore = ["E", "F", "C901", "W191"]

target-version = "py39"

[isort]
combine-as-imports = true

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions