Skip to content

Commit c60b315

Browse files
committed
Avoid creating lockfile
1 parent d404d8f commit c60b315

File tree

9 files changed

+397
-111
lines changed

9 files changed

+397
-111
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,19 @@ pub struct SyncArgs {
31463146
conflicts_with = "all_packages",
31473147
conflicts_with = "package",
31483148
conflicts_with = "no_install_project",
3149-
conflicts_with = "no_install_workspace"
3149+
conflicts_with = "no_install_workspace",
3150+
conflicts_with = "extra",
3151+
conflicts_with = "all_extras",
3152+
conflicts_with = "no_extra",
3153+
conflicts_with = "no_all_extras",
3154+
conflicts_with = "dev",
3155+
conflicts_with = "no_dev",
3156+
conflicts_with = "only_dev",
3157+
conflicts_with = "group",
3158+
conflicts_with = "no_group",
3159+
conflicts_with = "no_default_groups",
3160+
conflicts_with = "only_group",
3161+
conflicts_with = "all_groups"
31503162
)]
31513163
pub script: Option<PathBuf>,
31523164

crates/uv-distribution/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ pub use download::LocalWheel;
33
pub use error::Error;
44
pub use index::{BuiltWheelIndex, RegistryWheelIndex};
55
pub use metadata::{
6-
ArchiveMetadata, BuildRequires, FlatRequiresDist, LoweredRequirement, Metadata, MetadataError,
7-
RequiresDist,
6+
ArchiveMetadata, BuildRequires, FlatRequiresDist, LoweredRequirement, LoweringError, Metadata,
7+
MetadataError, RequiresDist,
88
};
99
pub use reporter::Reporter;
1010
pub use source::prune;

crates/uv-distribution/src/metadata/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use uv_workspace::WorkspaceError;
1313

1414
pub use crate::metadata::build_requires::BuildRequires;
1515
pub use crate::metadata::lowering::LoweredRequirement;
16-
use crate::metadata::lowering::LoweringError;
16+
pub use crate::metadata::lowering::LoweringError;
1717
pub use crate::metadata::requires_dist::{FlatRequiresDist, RequiresDist};
1818

1919
mod build_requires;

crates/uv/src/commands/project/mod.rs

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::borrow::Cow;
22
use std::collections::{BTreeMap, BTreeSet};
33
use std::fmt::Write;
4-
use std::ops::Deref;
54
use std::path::{Path, PathBuf};
65
use std::sync::Arc;
76

@@ -14,10 +13,10 @@ use uv_cache_key::cache_digest;
1413
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
1514
use uv_configuration::{
1615
Concurrency, Constraints, DevGroupsManifest, DevGroupsSpecification, DryRun,
17-
ExtrasSpecification, PreviewMode, Reinstall, TrustedHost, Upgrade,
16+
ExtrasSpecification, PreviewMode, Reinstall, SourceStrategy, TrustedHost, Upgrade,
1817
};
1918
use uv_dispatch::{BuildDispatch, SharedState};
20-
use uv_distribution::DistributionDatabase;
19+
use uv_distribution::{DistributionDatabase, LoweredRequirement};
2120
use uv_distribution_types::{
2221
Index, Resolution, UnresolvedRequirement, UnresolvedRequirementSpecification,
2322
};
@@ -227,6 +226,9 @@ pub(crate) enum ProjectError {
227226
#[error(transparent)]
228227
Metadata(#[from] uv_distribution::MetadataError),
229228

229+
#[error(transparent)]
230+
Lowering(#[from] uv_distribution::LoweringError),
231+
230232
#[error(transparent)]
231233
PyprojectMut(#[from] uv_workspace::pyproject_mut::Error),
232234

@@ -1224,7 +1226,7 @@ impl ProjectEnvironment {
12241226
}
12251227
}
12261228

1227-
impl Deref for ProjectEnvironment {
1229+
impl std::ops::Deref for ProjectEnvironment {
12281230
type Target = PythonEnvironment;
12291231

12301232
fn deref(&self) -> &Self::Target {
@@ -1389,7 +1391,7 @@ impl ScriptEnvironment {
13891391
}
13901392
}
13911393

1392-
impl Deref for ScriptEnvironment {
1394+
impl std::ops::Deref for ScriptEnvironment {
13931395
type Target = PythonEnvironment;
13941396

13951397
fn deref(&self) -> &Self::Target {
@@ -1911,6 +1913,7 @@ pub(crate) async fn update_environment(
19111913
native_tls: bool,
19121914
allow_insecure_host: &[TrustedHost],
19131915
cache: &Cache,
1916+
dry_run: DryRun,
19141917
printer: Printer,
19151918
preview: PreviewMode,
19161919
) -> Result<EnvironmentUpdate, ProjectError> {
@@ -2026,7 +2029,6 @@ pub(crate) async fn update_environment(
20262029
// optional on the downstream APIs.
20272030
let build_constraints = Constraints::default();
20282031
let build_hasher = HashStrategy::default();
2029-
let dry_run = DryRun::default();
20302032
let extras = ExtrasSpecification::default();
20312033
let groups = DevGroupsSpecification::default();
20322034
let hasher = HashStrategy::default();
@@ -2297,6 +2299,113 @@ pub(crate) fn detect_conflicts(
22972299
Ok(())
22982300
}
22992301

2302+
/// Determine the [`RequirementsSpecification`] for a script.
2303+
#[allow(clippy::result_large_err)]
2304+
pub(crate) fn script_specification(
2305+
script: Pep723ItemRef<'_>,
2306+
settings: ResolverSettingsRef,
2307+
) -> Result<Option<RequirementsSpecification>, ProjectError> {
2308+
let Some(dependencies) = script.metadata().dependencies.as_ref() else {
2309+
return Ok(None);
2310+
};
2311+
2312+
// Determine the working directory for the script.
2313+
let script_dir = match &script {
2314+
Pep723ItemRef::Script(script) => std::path::absolute(&script.path)?
2315+
.parent()
2316+
.expect("script path has no parent")
2317+
.to_owned(),
2318+
Pep723ItemRef::Stdin(..) | Pep723ItemRef::Remote(..) => std::env::current_dir()?,
2319+
};
2320+
2321+
// Collect any `tool.uv.index` from the script.
2322+
let empty = Vec::default();
2323+
let script_indexes = match settings.sources {
2324+
SourceStrategy::Enabled => script
2325+
.metadata()
2326+
.tool
2327+
.as_ref()
2328+
.and_then(|tool| tool.uv.as_ref())
2329+
.and_then(|uv| uv.top_level.index.as_deref())
2330+
.unwrap_or(&empty),
2331+
SourceStrategy::Disabled => &empty,
2332+
};
2333+
2334+
// Collect any `tool.uv.sources` from the script.
2335+
let empty = BTreeMap::default();
2336+
let script_sources = match settings.sources {
2337+
SourceStrategy::Enabled => script
2338+
.metadata()
2339+
.tool
2340+
.as_ref()
2341+
.and_then(|tool| tool.uv.as_ref())
2342+
.and_then(|uv| uv.sources.as_ref())
2343+
.unwrap_or(&empty),
2344+
SourceStrategy::Disabled => &empty,
2345+
};
2346+
2347+
let requirements = dependencies
2348+
.iter()
2349+
.cloned()
2350+
.flat_map(|requirement| {
2351+
LoweredRequirement::from_non_workspace_requirement(
2352+
requirement,
2353+
script_dir.as_ref(),
2354+
script_sources,
2355+
script_indexes,
2356+
settings.index_locations,
2357+
)
2358+
.map_ok(LoweredRequirement::into_inner)
2359+
})
2360+
.collect::<Result<_, _>>()?;
2361+
let constraints = script
2362+
.metadata()
2363+
.tool
2364+
.as_ref()
2365+
.and_then(|tool| tool.uv.as_ref())
2366+
.and_then(|uv| uv.constraint_dependencies.as_ref())
2367+
.into_iter()
2368+
.flatten()
2369+
.cloned()
2370+
.flat_map(|requirement| {
2371+
LoweredRequirement::from_non_workspace_requirement(
2372+
requirement,
2373+
script_dir.as_ref(),
2374+
script_sources,
2375+
script_indexes,
2376+
settings.index_locations,
2377+
)
2378+
.map_ok(LoweredRequirement::into_inner)
2379+
})
2380+
.collect::<Result<Vec<_>, _>>()?;
2381+
let overrides = script
2382+
.metadata()
2383+
.tool
2384+
.as_ref()
2385+
.and_then(|tool| tool.uv.as_ref())
2386+
.and_then(|uv| uv.override_dependencies.as_ref())
2387+
.into_iter()
2388+
.flatten()
2389+
.cloned()
2390+
.flat_map(|requirement| {
2391+
LoweredRequirement::from_non_workspace_requirement(
2392+
requirement,
2393+
script_dir.as_ref(),
2394+
script_sources,
2395+
script_indexes,
2396+
settings.index_locations,
2397+
)
2398+
.map_ok(LoweredRequirement::into_inner)
2399+
})
2400+
.collect::<Result<Vec<_>, _>>()?;
2401+
2402+
Ok(Some(RequirementsSpecification::from_overrides(
2403+
requirements,
2404+
constraints,
2405+
overrides,
2406+
)))
2407+
}
2408+
23002409
/// Warn if the user provides (e.g.) an `--index-url` in a requirements file.
23012410
fn warn_on_requirements_txt_setting(
23022411
spec: &RequirementsSpecification,

crates/uv/src/commands/project/run.rs

Lines changed: 7 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::borrow::Cow;
2-
use std::collections::BTreeMap;
32
use std::ffi::OsString;
43
use std::fmt::Write;
54
use std::io::Read;
@@ -18,9 +17,8 @@ use uv_cli::ExternalCommand;
1817
use uv_client::{BaseClientBuilder, Connectivity};
1918
use uv_configuration::{
2019
Concurrency, DevGroupsSpecification, DryRun, EditableMode, ExtrasSpecification, InstallOptions,
21-
PreviewMode, SourceStrategy, TrustedHost,
20+
PreviewMode, TrustedHost,
2221
};
23-
use uv_distribution::LoweredRequirement;
2422
use uv_fs::which::is_executable;
2523
use uv_fs::{PythonExt, Simplified};
2624
use uv_installer::{SatisfiesResult, SitePackages};
@@ -46,9 +44,10 @@ use crate::commands::project::install_target::InstallTarget;
4644
use crate::commands::project::lock::LockMode;
4745
use crate::commands::project::lock_target::LockTarget;
4846
use crate::commands::project::{
49-
default_dependency_groups, update_environment, validate_project_requires_python,
50-
DependencyGroupsTarget, EnvironmentSpecification, ProjectEnvironment, ProjectError,
51-
ScriptEnvironment, ScriptInterpreter, UniversalState, WorkspacePython,
47+
default_dependency_groups, script_specification, update_environment,
48+
validate_project_requires_python, DependencyGroupsTarget, EnvironmentSpecification,
49+
ProjectEnvironment, ProjectError, ScriptEnvironment, ScriptInterpreter, UniversalState,
50+
WorkspacePython,
5251
};
5352
use crate::commands::reporters::PythonDownloadReporter;
5453
use crate::commands::run::run_to_completion;
@@ -318,98 +317,8 @@ pub(crate) async fn run(
318317
);
319318
}
320319

321-
// Determine the working directory for the script.
322-
let script_dir = match &script {
323-
Pep723Item::Script(script) => std::path::absolute(&script.path)?
324-
.parent()
325-
.expect("script path has no parent")
326-
.to_owned(),
327-
Pep723Item::Stdin(..) | Pep723Item::Remote(..) => std::env::current_dir()?,
328-
};
329-
let metadata = script.metadata();
330-
331320
// Install the script requirements, if necessary. Otherwise, use an isolated environment.
332-
if let Some(dependencies) = metadata.dependencies.as_ref() {
333-
// Collect any `tool.uv.index` from the script.
334-
let empty = Vec::default();
335-
let script_indexes = match settings.sources {
336-
SourceStrategy::Enabled => metadata
337-
.tool
338-
.as_ref()
339-
.and_then(|tool| tool.uv.as_ref())
340-
.and_then(|uv| uv.top_level.index.as_deref())
341-
.unwrap_or(&empty),
342-
SourceStrategy::Disabled => &empty,
343-
};
344-
345-
// Collect any `tool.uv.sources` from the script.
346-
let empty = BTreeMap::default();
347-
let script_sources = match settings.sources {
348-
SourceStrategy::Enabled => metadata
349-
.tool
350-
.as_ref()
351-
.and_then(|tool| tool.uv.as_ref())
352-
.and_then(|uv| uv.sources.as_ref())
353-
.unwrap_or(&empty),
354-
SourceStrategy::Disabled => &empty,
355-
};
356-
357-
let requirements = dependencies
358-
.iter()
359-
.cloned()
360-
.flat_map(|requirement| {
361-
LoweredRequirement::from_non_workspace_requirement(
362-
requirement,
363-
script_dir.as_ref(),
364-
script_sources,
365-
script_indexes,
366-
&settings.index_locations,
367-
)
368-
.map_ok(LoweredRequirement::into_inner)
369-
})
370-
.collect::<Result<_, _>>()?;
371-
let constraints = metadata
372-
.tool
373-
.as_ref()
374-
.and_then(|tool| tool.uv.as_ref())
375-
.and_then(|uv| uv.constraint_dependencies.as_ref())
376-
.into_iter()
377-
.flatten()
378-
.cloned()
379-
.flat_map(|requirement| {
380-
LoweredRequirement::from_non_workspace_requirement(
381-
requirement,
382-
script_dir.as_ref(),
383-
script_sources,
384-
script_indexes,
385-
&settings.index_locations,
386-
)
387-
.map_ok(LoweredRequirement::into_inner)
388-
})
389-
.collect::<Result<Vec<_>, _>>()?;
390-
let overrides = metadata
391-
.tool
392-
.as_ref()
393-
.and_then(|tool| tool.uv.as_ref())
394-
.and_then(|uv| uv.override_dependencies.as_ref())
395-
.into_iter()
396-
.flatten()
397-
.cloned()
398-
.flat_map(|requirement| {
399-
LoweredRequirement::from_non_workspace_requirement(
400-
requirement,
401-
script_dir.as_ref(),
402-
script_sources,
403-
script_indexes,
404-
&settings.index_locations,
405-
)
406-
.map_ok(LoweredRequirement::into_inner)
407-
})
408-
.collect::<Result<Vec<_>, _>>()?;
409-
410-
let spec =
411-
RequirementsSpecification::from_overrides(requirements, constraints, overrides);
412-
321+
if let Some(spec) = script_specification((&script).into(), settings.as_ref().into())? {
413322
let environment = ScriptEnvironment::get_or_init(
414323
(&script).into(),
415324
python.as_deref().map(PythonRequest::parse),
@@ -449,6 +358,7 @@ pub(crate) async fn run(
449358
native_tls,
450359
allow_insecure_host,
451360
cache,
361+
DryRun::Disabled,
452362
printer,
453363
preview,
454364
)

0 commit comments

Comments
 (0)