Implement uv pip freeze --exclude flag#17045
Conversation
crates/uv/src/commands/pip/freeze.rs
Outdated
| /// Enumerate the installed packages in the current environment. | ||
| pub(crate) fn pip_freeze( | ||
| exclude_editable: bool, | ||
| exclude: &[PackageName], |
There was a problem hiding this comment.
Should this be a hash set instead?
There was a problem hiding this comment.
crates/uv/src/settings.rs
Outdated
| #[derive(Debug, Clone)] | ||
| pub(crate) struct PipFreezeSettings { | ||
| pub(crate) exclude_editable: bool, | ||
| pub(crate) exclude: Vec<PackageName>, |
There was a problem hiding this comment.
I presume we'd transform to a hash set here
crates/uv/tests/it/pip_freeze.rs
Outdated
| let requirements_txt = context.temp_dir.child("requirements.txt"); | ||
| requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?; | ||
|
|
||
| // Run `pip sync`. | ||
| context | ||
| .pip_sync() | ||
| .arg(requirements_txt.path()) | ||
| .assert() | ||
| .success(); |
There was a problem hiding this comment.
I might just pip install these packages instead since it's simpler, and you don't need to pin versions because we use exclude-newer in the test suite.
There was a problem hiding this comment.
changed to pip_install, and can also remove pins, however I just adopted that from the other test cases, so unsure how to move forward with that.
There was a problem hiding this comment.
As in https://github.com/astral-sh/uv/pull/17045/files#r2614916235 we can just open an issue to simplify some of the test cases.
crates/uv/src/settings.rs
Outdated
|
|
||
| Self { | ||
| exclude_editable, | ||
| exclude, |
There was a problem hiding this comment.
transform to hash set here seems to be how I can make it work? exclude: exclude.into_iter().collect(),
however, like pinning versions in pip_install test, I'm unsure if other similar cases should be changed, i.e. PipListSettings implements a similar exclude argument which is also currently a Vec.
There was a problem hiding this comment.
We can pursue refactoring other cases separately, want to just open an issue to track that?
crates/uv/tests/it/pip_freeze.rs
Outdated
| context | ||
| .pip_install() | ||
| .arg("-r") | ||
| .arg("requirements.txt") |
There was a problem hiding this comment.
I think you should drop the requirements.txt entirely and just use MarkupSafe and ntomli as arguments here.
6816e0f to
b3f082f
Compare
|
@zanieb Sorry for the delayed response. I have rebased on main and created two issues, let me know if anything else is missing. |
|
Thanks! |
Further simplify pip_freeze tests by passing package names directly to pip_install rather than creating temporary requirements files. This follows the suggestion from PR astral-sh#17045 review discussion.
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.9.26` → `0.9.27` | 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.9.27`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0927) [Compare Source](astral-sh/uv@0.9.26...0.9.27) Released on 2026-01-26. ##### Python - Upgrade Pyodide to 0.29.2 ([#​17652](astral-sh/uv#17652)) - Upgrade to GraalPy 25.0.2 ([#​17634](astral-sh/uv#17634)) ##### Enhancements - Add `-t` shortform for `--target` to `uv pip` subcommands ([#​17501](astral-sh/uv#17501)) - Add support for ROCm 7.0 and 7.1 accelerator backends ([#​17681](astral-sh/uv#17681)) - Further improve free-threading ABI incompatibility errors ([#​17491](astral-sh/uv#17491)) - Implement `uv pip freeze --exclude` flag ([#​17045](astral-sh/uv#17045)) - Improve warnings for `--system` and `--no-system` in `uv venv` ([#​17647](astral-sh/uv#17647)) - Make `uv pip compile` attempt to download a specified `--python-version` if it can. ([#​17249](astral-sh/uv#17249)) - Support Trusted Publishing with pyx ([#​17438](astral-sh/uv#17438)) - Fix JSON schema for `exclude-newer-package` ([#​17665](astral-sh/uv#17665)) ##### Preview features - Better detection for conflicting packages ([#​17623](astral-sh/uv#17623)) - Upgrade based on outdated build versions in `uv python upgrade` ([#​17653](astral-sh/uv#17653)) ##### Bug fixes - Change chocolatey system test to ensure uv uses the right python ([#​17533](astral-sh/uv#17533)) - Fix infinite loop when `SSL_CERT_FILE` is a directory ([#​17503](astral-sh/uv#17503)) ##### Documentation - Add cargo-xwin to the CONTRIBUTING guide ([#​17507](astral-sh/uv#17507)) - Fix typo in the documentation of UV\_PUBLISH\_INDEX ([#​17672](astral-sh/uv#17672)) - Move MSRV to platform support section ([#​17534](astral-sh/uv#17534)) - Update the testing instructions in the CONTRIBUTING guide ([#​17528](astral-sh/uv#17528)) - Use `--locked` to install `cargo-xwin` in guide ([#​17530](astral-sh/uv#17530)) - Warn about PyPy being unmaintained ([#​17643](astral-sh/uv#17643)) - docs: Correct gitlab-ci.yml to .gitlab-ci.yml ([#​17682](astral-sh/uv#17682)) ##### Other changes - Update MSRV to 1.91 ([#​17677](astral-sh/uv#17677)) </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:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Mi40IiwidXBkYXRlZEluVmVyIjoiNDIuOTIuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6OnBhdGNoIl19-->
Summary
Implements the
--excludeflag touv pip freeze, which allows to filter unwanted dependencies from the resulting requirements.txt file.part of #3141
Test Plan
Unit test with simple exclusion example of command argument(s)