Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8367,6 +8367,14 @@ pub struct MetadataArgs {
#[arg(long)]
pub sync: bool,

/// Sync dependencies to the active virtual environment.
///
/// Instead of creating or updating the virtual environment for the project or script, the
/// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
/// set.
#[arg(long)]
pub active: bool,

/// The Python interpreter to use during resolution.
///
/// A Python interpreter is required for building source distributions to determine package
Expand Down
9 changes: 5 additions & 4 deletions crates/uv/src/commands/workspace/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) async fn metadata(
dry_run: DryRun,
refresh: Refresh,
sync: bool,
active: bool,
python: Option<String>,
install_mirrors: PythonInstallMirrors,
malware_settings: MalwareCheckSettings,
Expand Down Expand Up @@ -93,7 +94,7 @@ pub(crate) async fn metadata(
&install_mirrors,
false,
config_discovery,
Some(false),
Some(active),
cache,
printer,
)
Expand All @@ -117,7 +118,7 @@ pub(crate) async fn metadata(
python_downloads,
&install_mirrors,
false,
Some(false),
Some(active),
cache,
printer,
)
Expand Down Expand Up @@ -184,7 +185,7 @@ pub(crate) async fn metadata(
python_downloads,
false,
config_discovery,
Some(false),
Some(active),
cache,
DryRun::Disabled,
LinkErrorReporting::User,
Expand All @@ -201,7 +202,7 @@ pub(crate) async fn metadata(
&install_mirrors,
false,
config_discovery,
Some(false),
Some(active),
cache,
DryRun::Disabled,
printer,
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,7 @@ pub async fn run(cli: Cli, global_initialization: GlobalInitialization) -> Resul
args.dry_run,
args.refresh,
args.sync,
args.active,
args.python,
args.install_mirrors,
args.malware_settings,
Expand Down
3 changes: 3 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ pub(crate) struct MetadataSettings {
pub(crate) frozen: Option<FrozenSource>,
pub(crate) dry_run: DryRun,
pub(crate) sync: bool,
pub(crate) active: bool,
pub(crate) python: Option<String>,
pub(crate) install_mirrors: PythonInstallMirrors,
pub(crate) refresh: Refresh,
Expand All @@ -2124,6 +2125,7 @@ impl MetadataSettings {
build,
refresh,
sync,
active,
python,
} = *args;

Expand All @@ -2147,6 +2149,7 @@ impl MetadataSettings {
frozen: resolve_frozen(frozen),
dry_run: DryRun::from_args(dry_run),
sync,
active,
python: python.and_then(Maybe::into_option),
refresh: Refresh::from(refresh),
settings: ResolverSettings::combine(
Expand Down
47 changes: 47 additions & 0 deletions crates/uv/tests/workspace/workspace_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use async_zip::{Compression, ZipEntryBuilder};
use futures::executor::block_on;
use url::Url;

use uv_static::EnvVars;
use uv_test::{copy_dir_ignore, uv_snapshot};

fn write_wheel(
Expand Down Expand Up @@ -525,6 +526,52 @@ fn workspace_metadata_sync_centralized_environment() -> Result<()> {
Ok(())
}

#[test]
fn workspace_metadata_sync_active_environment() -> Result<()> {
let context = uv_test::test_context_with_versions!(&["3.12", "3.11"]);

context.temp_dir.child("pyproject.toml").write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []
"#,
)?;

context
.venv()
.arg("--python")
.arg("3.11")
.assert()
.success();
let active = context.temp_dir.child("active");
context
.venv()
.arg(active.path())
.arg("--python")
.arg("3.12")
.assert()
.success();

let assert = context
.workspace_metadata()
.arg("--sync")
.arg("--active")
.env(EnvVars::VIRTUAL_ENV, active.path())
.assert()
.success();
let metadata: serde_json::Value = serde_json::from_slice(&assert.get_output().stdout)?;

assert_eq!(
metadata["environment"]["root"].as_str().map(Path::new),
Some(active.path())
);

Ok(())
}

#[test]
fn workspace_metadata_module_owners_from_locked_wheels() -> Result<()> {
let context = uv_test::test_context!("3.12");
Expand Down
Loading