Repository navigation
Support frozen exports without workspace manifests - #22007
Conversation
uv test inventory changesThis PR changes the tests when compared with the
|
1446866 to
3601b32
Compare
3601b32 to
28f893c
Compare
cc1f44e to
4cf4469
Compare
4cf4469 to
4ddfc23
Compare
4ddfc23 to
d685fac
Compare
d685fac to
ae9e91a
Compare
56fefa9 to
0eee342
Compare
0eee342 to
f3cd968
Compare
f3cd968 to
e562104
Compare
e562104 to
41c08b2
Compare
| .filter_map(|(name, path)| { | ||
| let path = uv_fs::normalize_path(self.root.join(path)).into_owned(); | ||
| let path = fs_err::canonicalize(&path).unwrap_or(path); | ||
| project_dir.starts_with(&path).then_some((name, path)) | ||
| }) | ||
| .max_by_key(|(_, path)| path.components().count()) | ||
| .map(|(name, _)| name) | ||
| .or_else(|| self.lock.root().map(Package::name)) |
There was a problem hiding this comment.
Do we do this elsewhere? It's a bit complicated and we should consolidate if so
There was a problem hiding this comment.
I guess VirtualProject::discover and FrozenWorkspace::discover have some overlap but not exactly?
There was a problem hiding this comment.
Yeah the rules are a little different, hmm...
|
Was reviewing this and found a differential with codex's help: #!/usr/bin/env bash
set -e
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
cd "$tmpdir"
cat >pyproject.toml <<EOF
[project]
name = "root"
version = "1.0"
requires-python = ">=3.9"
[dependency-groups]
root-only = ["dep"]
[tool.uv.workspace]
members = ["a", "b", "dep"]
[tool.uv.sources]
dep = { workspace = true }
EOF
for package in a b dep; do
mkdir "$package"
printf '[project]\nname = "%s"\nversion = "1.0"\n' "$package" >"$package/pyproject.toml"
done
cat >>dep/pyproject.toml <<EOF
[build-system]
requires = []
build-backend = "example"
EOF
uv lock --offline --quiet
args=(export --frozen --offline --preview-features frozen-lockfile
--no-header --no-annotate --no-hashes
--package a --package b --only-group root-only)
set +e -x
uv "${args[@]}"
printf 'exit: %d\n' "$?" >&2
rm pyproject.toml
uv "${args[@]}"
printf 'exit: %d\n' "$?" >&2outputs: We have enough information to print the same error but instead we just print nothing and succeed. (full review coming shortly) |
| } else if let LockCheck::Enabled(lock_check) = lock_check { | ||
| LockMode::Locked(interpreter.as_ref().unwrap(), lock_check) | ||
| } else if let ExportTarget::Script(script) = target | ||
| && !LockTarget::Script(script).lock_path().try_exists()? |
There was a problem hiding this comment.
Why did this change to use try_exists from is_file? Kind of a weird change?
| )) | ||
| } | ||
| Self::Script { script, .. } => Either::Right( | ||
| Self::Script { script, .. } => Either::Right(Either::Left( |
There was a problem hiding this comment.
Starting to get a bit excessive?
| let absolute = std::path::absolute(project_dir)?; | ||
| let project_dir = uv_fs::normalize_path(&absolute); | ||
| let mut manifest_root = None; | ||
| for directory in project_dir.ancestors() { |
There was a problem hiding this comment.
I know we do this elsewhere, so it makes sense to match here, but generally speaking I think the expectation is that any "upwards from this point" traversal is logical not lexical. i.e. it in effect traverses through ...
But I think we don't really focus on supporting weird symlink arrangements in workspaces right now, so not urgent and not really something for this PR.
| if pyproject.is_workspace_root() { | ||
| return Ok(None); | ||
| } | ||
| manifest_root.get_or_insert(directory); |
There was a problem hiding this comment.
One more tricky case:
#!/usr/bin/env bash
set -e
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
cd "$tmpdir"
mkdir -p nested/member
cat >pyproject.toml <<EOF
[tool.uv.workspace]
members = ["nested/member"]
EOF
for project in nested nested/member; do
cat >"$project/pyproject.toml" <<EOF
[project]
name = "${project##*/}"
version = "1.0"
requires-python = ">=3.9"
[build-system]
requires = []
build-backend = "example"
EOF
done
uv lock --offline --quiet
args=(export --frozen --offline --preview-features frozen-lockfile
--no-default-groups --no-header --no-annotate --no-hashes
--project nested/member)
set +e -x
uv "${args[@]}"
printf 'exit: %d\n' "$?" >&2
rm pyproject.toml
uv "${args[@]}"
printf 'exit: %d\n' "$?" >&2outputs:
+ uv export --frozen --offline --preview-features frozen-lockfile --no-default-groups --no-header --no-annotate --no-hashes --project nested/member
error: Unable to find lockfile at `uv.lock`, but `--frozen` was provided. To create a lockfile, run `uv lock` or `uv sync` without the flag.
+ printf 'exit: %d\n' 1
exit: 1
+ rm pyproject.toml
+ uv export --frozen --offline --preview-features frozen-lockfile --no-default-groups --no-header --no-annotate --no-hashes --project nested/member
-e ./nested/member
+ printf 'exit: %d\n' 0
exit: 0
+ rm -rf .../tmp.TPHLLgq8qD
But I really have no idea what the correct answer is here...
These double-nested pyproject.toml cases might not have good answers...
Summary
We allow
uv export --frozento discoveruv.lockwhenpyproject.tomlis unavailable. We emit a preview warning unless--preview-features frozen-lockfileis enabled. When the manifest is present, we use its configuration, including index and find-links settings.A lockfile-only export requires revision 5 or later. We use the recorded default groups for the selected workspace member or project-less root. When the default selection is omitted, revision 5 implies
["dev"]for both members and project-less roots.For example, we can export a member using only its lockfile metadata:
uv export --frozen --package member--emit-index-urland--emit-find-linksrequirepyproject.tomlbecause their configuration is not recorded in the lockfile.