Skip to content

Respect --project in uv format#15438

Merged
zanieb merged 3 commits intoastral-sh:mainfrom
jorgehermo9:feature/uv-format-project-dir
Aug 22, 2025
Merged

Respect --project in uv format#15438
zanieb merged 3 commits intoastral-sh:mainfrom
jorgehermo9:feature/uv-format-project-dir

Conversation

@jorgehermo9
Copy link
Contributor

@jorgehermo9 jorgehermo9 commented Aug 21, 2025

Closes #15431

This is my first contribution, so I'm sorry if I miss something! Didn't update any documentation nor added tests. Tell me if this is needed for this feature 😄

I will try to address #15430 in another PR

@zanieb
Copy link
Member

zanieb commented Aug 21, 2025

Nice! The best way to test this is probably to copy the existing format_project and place the project in a subdirectory instead then add an unformatted file to the working directory and assert that it doesn't change but the one in the subdirectory does when you use --project.

@zanieb zanieb added the preview Experimental behavior label Aug 21, 2025
@zanieb
Copy link
Member

zanieb commented Aug 21, 2025

(I haven't written the uv format documentation yet, so don't worry about that part)

}

#[test]
fn format_relative_project() -> Result<()> {
Copy link
Contributor Author

@jorgehermo9 jorgehermo9 Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inspired in https://github.com/astral-sh/uv/blob/35a8dd514ef22d4c71cab430c74af2c1b95fbfe3/crates/uv/tests/it/lock.rs#L25729

I'm not sure if the relative_project nomenclature applies here.

Also, there are a lot of duplicated code among these tests (mainly, the same pyproject.toml, and the formatted/unformatted code snippets). I preferred to maintain the previous style and copypaste the mock data. I'm not sure what approach do you usually follow here (to extract into constants/fixtures vs always copypaste)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably move them into a reusable snippet here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgehermo9
Copy link
Contributor Author

jorgehermo9 commented Aug 21, 2025

Everything addressed @zanieb! Thank you very much for your review 😃

@zanieb zanieb merged commit a2d97ae into astral-sh:main Aug 22, 2025
96 checks passed
@zanieb zanieb changed the title feat: uv format should read project dir Respect --project in uv format Aug 22, 2025
zanieb added a commit that referenced this pull request Aug 22, 2025
#15440)

Closes #15430

This PR is a branch from #15438,
opening it as a draft until that is merged to main and I'll merge main
with this branch to have a cleaner diff

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 2, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.8.13` -> `0.8.14` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.8.14`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0814)

[Compare Source](astral-sh/uv@0.8.13...0.8.14)

##### Python

- Add managed CPython distributions for aarch64 musl

##### Enhancements

- Add `--python-platform` to `uv pip check` ([#&#8203;15486](astral-sh/uv#15486))
- Add an environment variable for `UV_ISOLATED` ([#&#8203;15428](astral-sh/uv#15428))
- Add logging to the uv build backend ([#&#8203;15533](astral-sh/uv#15533))
- Allow more trailing null bytes in zip files ([#&#8203;15452](astral-sh/uv#15452))
- Allow pinning managed Python versions to specific build versions ([#&#8203;15314](astral-sh/uv#15314))
- Cache PyTorch wheels by default ([#&#8203;15481](astral-sh/uv#15481))
- Reject already-installed wheels that don't match the target platform ([#&#8203;15484](astral-sh/uv#15484))
- Add `--no-install-local` option to `uv sync`, `uv add` and `uv export`  ([#&#8203;15328](astral-sh/uv#15328))
- Include cycle error message in `uv pip` CLI ([#&#8203;15453](astral-sh/uv#15453))

##### Preview features

- Fix format of `{version}` on `uv format` failure ([#&#8203;15527](astral-sh/uv#15527))
- Lock during installs in `uv format` to prevent races ([#&#8203;15551](astral-sh/uv#15551))
- Respect `--project` in `uv format` ([#&#8203;15438](astral-sh/uv#15438))
- Run `uv format` in the project root ([#&#8203;15440](astral-sh/uv#15440))

##### Configuration

- Add file-to-CLI overrides for build isolation configuration ([#&#8203;15437](astral-sh/uv#15437))
- Add file-to-CLI overrides for reinstall configuration ([#&#8203;15426](astral-sh/uv#15426))

##### Performance

- Cache `WHEEL` and `METADATA` reads in installed distributions ([#&#8203;15489](astral-sh/uv#15489))

##### Bug fixes

- Avoid erroring when creating `venv` in current working directory ([#&#8203;15537](astral-sh/uv#15537))
- Avoid introducing unnecessary system dependency on CUDA ([#&#8203;15449](astral-sh/uv#15449))
- Clear discovered site packages when creating virtual environment ([#&#8203;15522](astral-sh/uv#15522))
- Read index credentials from the environment during `uv publish` checks ([#&#8203;15545](astral-sh/uv#15545))
- Refuse to remove non-virtual environments in `uv venv` ([#&#8203;15538](astral-sh/uv#15538))
- Stop setting `CLICOLOR_FORCE=1` when calling build backends ([#&#8203;15472](astral-sh/uv#15472))
- Support file or directory removal for Windows symlinks ([#&#8203;15543](astral-sh/uv#15543))

##### Documentation

- Fix GitHub guide highlight lines ([#&#8203;15443](astral-sh/uv#15443))
- Move Resolver to new Internals section in the Reference ([#&#8203;15465](astral-sh/uv#15465))
- Split the "Authentication" page into sections ([#&#8203;15575](astral-sh/uv#15575))
- Update uninstall docs to mention `uvw.exe` needs to be removed ([#&#8203;15536](astral-sh/uv#15536))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS44OC4wIiwidXBkYXRlZEluVmVyIjoiNDEuODguMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv format should respect --project

2 participants