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

treefmt treats relative paths as relative to the tree root, rather than the current working directory #443

Closed
jfly opened this issue Oct 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jfly
Copy link
Collaborator

jfly commented Oct 12, 2024

treefmt refuses to format files relative to $PWD when I'm in a subdirectory of my project.

This works:

./ $ treefmt subdir/tracked.py
traversed 1 files
emitted 1 files for processing
formatted 1 files (0 changed) in 143ms

But if I'm in subdir/:

subdir/ $ treefmt ./tracked.py
Error: path ./tracked.py not found within the tree root /tmp/tmp.NFu4zPpIQ9

But this does work if I use the same relative path from before:

subdir/ $ treefmt subdir/tracked.py
traversed 1 files
emitted 0 files for processing
formatted 0 files (0 changed) in 17ms

To Reproduce

Here's the setup for the above commands:

$ cd "$(mktemp -d)"
$ git init
$ mkdir subdir
$ touch subdir/tracked.py
$ git add --intent-to-add subdir/tracked.py

$ nix shell github:numtide/treefmt nixpkgs#black
$ treefmt --version
treefmt v659aa0f
$ cat treefmt.toml   # create this file
[formatter.python]
command = "black"
includes = ["*.py"]

Expected behavior

I expect treefmt to interpret relative paths relative to the current working directory, not the tree root.

System information

See above. I'm using 659aa0f.

@jfly jfly added the bug Something isn't working label Oct 12, 2024
@jfly jfly changed the title treefmt mis-handles relative paths when you're in a subdir of the project treefmt treets relative paths as relative to the tree root, rather than the current working directory Oct 12, 2024
@jfly jfly changed the title treefmt treets relative paths as relative to the tree root, rather than the current working directory treefmt treats relative paths as relative to the tree root, rather than the current working directory Oct 12, 2024
jfly added a commit to jfly/treefmt that referenced this issue Oct 12, 2024
This fixes a few issues with both relative and absolute paths:

- Previously, treefmt refused to format any files passed as absolute
  paths, regardless of if they were in tree or not: numtide#442
- Previously, treefmt would treat relative paths as relative to the
  project root, which is not ideal if you're in a subdirectory and you
  just want to format the file you're right next to: numtide#443
  - There was even a test asserting this behavior. I changed it to
    reflect the updated behavior.
- treefmt's handling of paths outside of the project root was a bit
  inconsistent: numtide#444
@jfly
Copy link
Collaborator Author

jfly commented Oct 12, 2024

Fix out for review here: #445

jfly added a commit to jfly/treefmt that referenced this issue Oct 12, 2024
This fixes a few issues with both relative and absolute paths:

- Previously, treefmt refused to format any files passed as absolute
  paths, regardless of if they were in tree or not: numtide#442
- Previously, treefmt would treat relative paths as relative to the
  project root, which is not ideal if you're in a subdirectory and you
  just want to format the file you're right next to: numtide#443
  - There was even a test asserting this behavior. I changed it to
    reflect the updated behavior.
- treefmt's handling of paths outside of the project root was a bit
  inconsistent: numtide#444
@brianmcgee
Copy link
Member

Fixed with #445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants