feat: uv format from project root#15440
Conversation
|
|
||
| let workspace_cache = WorkspaceCache::default(); | ||
| let project = | ||
| VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache) |
There was a problem hiding this comment.
| let mut command = Command::new(&ruff_path); | ||
| command.current_dir(project_dir); | ||
| // Run ruff in the project root | ||
| command.current_dir(project.root()); |
There was a problem hiding this comment.
I wonder how this implementation behaves for a workspace with multiple package. running just uv format would always run the format from the workspace root. What is the intended way of working with specific packages of a workspace?
using uv run format --project package_a and uv run format --project package_b?
There was a problem hiding this comment.
I think if you wanted to run it in a workspace member it'd be uv format --package <name>
There was a problem hiding this comment.
Okay, perfect then!
Thanks @zanieb, I'm kind of new with uv and I'm sorry for those basic questions
crates/uv/tests/it/format.rs
Outdated
| let subdir = context.temp_dir.child("subdir"); | ||
| fs_err::create_dir_all(&subdir)?; | ||
|
|
||
| uv_snapshot!(context.filters(), context.format().current_dir("subdir"), @r" |
There was a problem hiding this comment.
Should we add another test similar to this, but using also the --project option? Maybe we could set up something like I depicted in https://github.com/astral-sh/uv/pull/15440/files#r2294435556 and have something like
.
├── main.py
├── package_a
│ ├── main.py
│ ├── pyproject.toml
│ └── README.md
├── package_b
│ ├── main.py
│ ├── pyproject.toml
│ └── README.md
├── pyproject.toml
└── README.mdand check that when running uv run format --project package_a only package_a gets formatted and package_b does not? Maybe this overlaps a bit with the current format_relative_project test so i'm not sure
Maybe I'm overthinking this 😄 but I'm open to include a test for this if this makes sense
There was a problem hiding this comment.
And also, another test such as
.
├── main.py
├── package_a
│ ├── main.py
│ ├── package_a_subdir
│ ├── pyproject.toml
│ └── README.md
├── package_b
│ ├── main.py
│ ├── pyproject.toml
│ └── README.md
├── pyproject.toml
└── README.mdand runing uv format with current dir as package_a/package_a_subdir only formats package_a files? But this may be testing VirtuslProject::discover's behaviour, so i'm also not sure
There was a problem hiding this comment.
It seems helpful to add a test case for a workspace if you're interested! Even if we don't handle workspace members "correctly" yet, having coverage for the behavior is helpful.
There was a problem hiding this comment.
Okay! Going to add that later/tomorrow (CET timezone). Feel free to merge if you don't want to wait till that, I'll open a new PR for tests if you decide to merge this before
|
Marked PR as ready! I see the CI is failing for windows https://github.com/astral-sh/uv/actions/runs/17163604154/job/48698604290?pr=15440#step:10:2995 but seems unrelated |
| } | ||
|
|
||
| #[test] | ||
| fn format_from_project_root() -> Result<()> { |
There was a problem hiding this comment.
We should also add a --no-project test case. I'd expect that to not use the project root.
There was a problem hiding this comment.
We don't support that yet actually, so that's a follow-up
There was a problem hiding this comment.
I may implement that as well! if no one takes it first 😃
zanieb
left a comment
There was a problem hiding this comment.
This looks ready to go besides my nits.
Co-authored-by: Zanie Blue <contact@zanie.dev>
Co-authored-by: Zanie Blue <contact@zanie.dev>
|
Thanks for your review @zanieb! |
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` ([#​15486](astral-sh/uv#15486)) - Add an environment variable for `UV_ISOLATED` ([#​15428](astral-sh/uv#15428)) - Add logging to the uv build backend ([#​15533](astral-sh/uv#15533)) - Allow more trailing null bytes in zip files ([#​15452](astral-sh/uv#15452)) - Allow pinning managed Python versions to specific build versions ([#​15314](astral-sh/uv#15314)) - Cache PyTorch wheels by default ([#​15481](astral-sh/uv#15481)) - Reject already-installed wheels that don't match the target platform ([#​15484](astral-sh/uv#15484)) - Add `--no-install-local` option to `uv sync`, `uv add` and `uv export` ([#​15328](astral-sh/uv#15328)) - Include cycle error message in `uv pip` CLI ([#​15453](astral-sh/uv#15453)) ##### Preview features - Fix format of `{version}` on `uv format` failure ([#​15527](astral-sh/uv#15527)) - Lock during installs in `uv format` to prevent races ([#​15551](astral-sh/uv#15551)) - Respect `--project` in `uv format` ([#​15438](astral-sh/uv#15438)) - Run `uv format` in the project root ([#​15440](astral-sh/uv#15440)) ##### Configuration - Add file-to-CLI overrides for build isolation configuration ([#​15437](astral-sh/uv#15437)) - Add file-to-CLI overrides for reinstall configuration ([#​15426](astral-sh/uv#15426)) ##### Performance - Cache `WHEEL` and `METADATA` reads in installed distributions ([#​15489](astral-sh/uv#15489)) ##### Bug fixes - Avoid erroring when creating `venv` in current working directory ([#​15537](astral-sh/uv#15537)) - Avoid introducing unnecessary system dependency on CUDA ([#​15449](astral-sh/uv#15449)) - Clear discovered site packages when creating virtual environment ([#​15522](astral-sh/uv#15522)) - Read index credentials from the environment during `uv publish` checks ([#​15545](astral-sh/uv#15545)) - Refuse to remove non-virtual environments in `uv venv` ([#​15538](astral-sh/uv#15538)) - Stop setting `CLICOLOR_FORCE=1` when calling build backends ([#​15472](astral-sh/uv#15472)) - Support file or directory removal for Windows symlinks ([#​15543](astral-sh/uv#15543)) ##### Documentation - Fix GitHub guide highlight lines ([#​15443](astral-sh/uv#15443)) - Move Resolver to new Internals section in the Reference ([#​15465](astral-sh/uv#15465)) - Split the "Authentication" page into sections ([#​15575](astral-sh/uv#15575)) - Update uninstall docs to mention `uvw.exe` needs to be removed ([#​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-->
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