Skip to content

Support frozen exports without workspace manifests - #22007

Merged
charliermarsh merged 5 commits into
mainfrom
charlie/frozen-lockfile-commands
Oct 3, 2026
Merged

charliermarsh merged 5 commits into
mainfrom
charlie/frozen-lockfile-commands

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Summary

We allow uv export --frozen to discover uv.lock when pyproject.toml is unavailable. We emit a preview warning unless --preview-features frozen-lockfile is 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-url and --emit-find-links require pyproject.toml because their configuration is not recorded in the lockfile.

@astral-sh-bot

astral-sh-bot Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 16
  • Removed tests: 0
  • Changed suites: 1
uv::project: +16 / -0

Added:

  • uv::project::export::frozen_lockfile_current_project
  • uv::project::export::frozen_lockfile_empty_member_group
  • uv::project::export::frozen_lockfile_member_inside_project
  • uv::project::export::frozen_lockfile_member_manifest
  • uv::project::export::frozen_lockfile_metadata_free_default_groups
  • uv::project::export::frozen_lockfile_nested_project
  • uv::project::export::frozen_lockfile_non_editable_root
  • uv::project::export::frozen_lockfile_non_project_workspace
  • uv::project::export::frozen_lockfile_project_index_emission
  • uv::project::export::frozen_lockfile_recorded_default_groups
  • uv::project::export::frozen_lockfile_rejects_index_emission
  • uv::project::export::frozen_lockfile_requires_revision
  • uv::project::export::frozen_lockfile_root_default_groups
  • uv::project::export::frozen_lockfile_single_project
  • uv::project::export::frozen_lockfile_without_manifests
  • uv::project::export::frozen_lockfile_workspace_root_without_lock

Removed: none

@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 1446866 to 3601b32 Compare September 27, 2026 23:37
@charliermarsh
charliermarsh changed the base branch from main to charlie/lockfile-default-groups September 27, 2026 23:37
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 3601b32 to 28f893c Compare September 27, 2026 23:54
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from cc1f44e to 4cf4469 Compare September 28, 2026 00:05
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 4cf4469 to 4ddfc23 Compare September 28, 2026 00:24
@charliermarsh charliermarsh changed the title Support frozen commands directly from lockfiles Support frozen exports directly from lockfiles Sep 28, 2026
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 4ddfc23 to d685fac Compare September 28, 2026 00:43
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from d685fac to ae9e91a Compare September 28, 2026 00:51
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 56fefa9 to 0eee342 Compare September 28, 2026 19:12
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from 0eee342 to f3cd968 Compare September 28, 2026 19:32
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from f3cd968 to e562104 Compare September 28, 2026 19:42
@charliermarsh
charliermarsh force-pushed the charlie/frozen-lockfile-commands branch from e562104 to 41c08b2 Compare September 28, 2026 19:52
Comment on lines +109 to +116
.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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we do this elsewhere? It's a bit complicated and we should consolidate if so

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess VirtualProject::discover and FrozenWorkspace::discover have some overlap but not exactly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah the rules are a little different, hmm...

@EliteTK

EliteTK commented Oct 1, 2026

Copy link
Copy Markdown
Member

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' "$?" >&2

outputs:

+ uv export --frozen --offline --preview-features frozen-lockfile --no-header --no-annotate --no-hashes --package a --package b --only-group root-only
error: Group `root-only` is not defined in any project's `dependency-groups` table
+ printf 'exit: %d\n' 2
exit: 2
+ rm pyproject.toml
+ uv export --frozen --offline --preview-features frozen-lockfile --no-header --no-annotate --no-hashes --package a --package b --only-group root-only
+ printf 'exit: %d\n' 0
exit: 0
+ rm -rf .../tmp.o6ijWQ7DRK

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()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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' "$?" >&2

outputs:

+ 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...

This branch was previously deployed

1 inactive deployment
automations — b627bbee Deployed Oct 2, 2026 by charliermarsh via review / security review #48941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to existing functionality preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址