Skip to content

Commit 9550737

Browse files
authored
Use global preview in CondaEnvironmentKind::from_prefix_path (#19649)
## Summary This expands the usage of global preview in a key area which has wide-ranging impact. Key notes: * uv-dev needs to set up default global preview because of this. Although it seems like it should technically have been setting it up earlier? * A number of tests no longer pass `Preview::default()` but also don't use the guard. This is because they only call into the preview stuff when the relevant conda environment variables are present. Which we assume they're not (otherwise the tests would be invalid for other reasons). There's really a hermeticity issue here, but I've addressed it in a separate PR. ## Test Plan Tests have been modified, but existing coverage should be sufficient.
1 parent b82cadf commit 9550737

44 files changed

Lines changed: 59 additions & 275 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/uv-dev/src/compile.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use tracing::info;
55

66
use uv_cache::{Cache, CacheArgs};
77
use uv_configuration::Concurrency;
8-
use uv_preview::Preview;
98
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonPreference, PythonRequest};
109

1110
#[derive(Parser)]
@@ -28,7 +27,6 @@ pub(crate) async fn compile(args: CompileArgs) -> anyhow::Result<()> {
2827
EnvironmentPreference::OnlyVirtual,
2928
PythonPreference::default(),
3029
&cache,
31-
Preview::default(),
3230
)?
3331
.into_interpreter();
3432
interpreter.sys_executable().to_path_buf()

‎crates/uv-dev/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ enum Cli {
7070

7171
#[instrument] // Anchor span to check for overhead
7272
pub async fn run() -> Result<()> {
73+
uv_preview::set(uv_preview::Preview::default())?;
74+
uv_preview::finalize()?;
75+
7376
let cli = Cli::parse();
7477
let environment = EnvironmentOptions::new()?;
7578
match cli {

‎crates/uv-installer/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ url = { workspace = true }
5555
walkdir = { workspace = true }
5656

5757
[dev-dependencies]
58+
uv-preview = { workspace = true, features = ["testing"] }
59+
5860
anstream = { workspace = true }
5961
insta = { workspace = true }

‎crates/uv-installer/src/installer.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ mod tests {
222222
use super::Installer;
223223

224224
fn environment() -> PythonEnvironment {
225+
let _preview = uv_preview::test::with_features(&[]);
225226
let cache = Cache::temp().expect("cache should be available");
226227
PythonEnvironment::find(
227228
&PythonRequest::Any,
228229
EnvironmentPreference::Any,
229230
PythonPreference::System,
230231
&cache,
231-
Preview::default(),
232232
)
233233
.expect("Python environment should be available")
234234
}

‎crates/uv-python/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ windows-registry = { workspace = true }
7373
windows = { workspace = true }
7474

7575
[dev-dependencies]
76+
uv-preview = { workspace = true, features = ["testing"] }
77+
7678
anyhow = { workspace = true }
7779
assert_fs = { workspace = true }
7880
indoc = { workspace = true }

‎crates/uv-python/src/discovery.rs‎

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use uv_pep440::{
1818
LowerBound, Prerelease, UpperBound, Version, VersionSpecifier, VersionSpecifiers,
1919
release_specifiers_to_ranges,
2020
};
21-
use uv_preview::Preview;
2221
use uv_static::EnvVars;
2322
use uv_warnings::{warn_user_once, write_warning_chain};
2423
use which::{which, which_all};
@@ -308,9 +307,8 @@ impl uv_errors::Hint for Error {
308307
/// - Discovered virtual environment (e.g. `.venv` in a parent directory)
309308
///
310309
/// Notably, "system" environments are excluded. See [`python_executables_from_installed`].
311-
fn python_executables_from_virtual_environments<'a>(
312-
preview: Preview,
313-
) -> impl Iterator<Item = Result<(PythonSource, PathBuf), Error>> + 'a {
310+
fn python_executables_from_virtual_environments<'a>()
311+
-> impl Iterator<Item = Result<(PythonSource, PathBuf), Error>> + 'a {
314312
let from_active_environment = iter::once_with(|| {
315313
virtualenv_from_env()
316314
.into_iter()
@@ -321,7 +319,7 @@ fn python_executables_from_virtual_environments<'a>(
321319

322320
// N.B. we prefer the conda environment over discovered virtual environments
323321
let from_conda_environment = iter::once_with(move || {
324-
conda_environment_from_env(CondaEnvironmentKind::Child, preview)
322+
conda_environment_from_env(CondaEnvironmentKind::Child)
325323
.into_iter()
326324
.map(virtualenv_python_executable)
327325
.map(|path| Ok((PythonSource::CondaPrefix, path)))
@@ -536,7 +534,6 @@ fn python_executables<'a>(
536534
platform: PlatformRequest,
537535
environments: EnvironmentPreference,
538536
preference: PythonPreference,
539-
preview: Preview,
540537
) -> Box<dyn Iterator<Item = Result<(PythonSource, PathBuf), Error>> + 'a> {
541538
// Always read from `UV_INTERNAL__PARENT_INTERPRETER` — it could be a system interpreter
542539
let from_parent_interpreter = iter::once_with(|| {
@@ -548,14 +545,14 @@ fn python_executables<'a>(
548545

549546
// Check if the base conda environment is active
550547
let from_base_conda_environment = iter::once_with(move || {
551-
conda_environment_from_env(CondaEnvironmentKind::Base, preview)
548+
conda_environment_from_env(CondaEnvironmentKind::Base)
552549
.into_iter()
553550
.map(virtualenv_python_executable)
554551
.map(|path| Ok((PythonSource::BaseCondaPrefix, path)))
555552
})
556553
.flatten();
557554

558-
let from_virtual_environments = python_executables_from_virtual_environments(preview);
555+
let from_virtual_environments = python_executables_from_virtual_environments();
559556
let from_installed =
560557
python_executables_from_installed(version, implementation, platform, preference);
561558

@@ -757,23 +754,16 @@ fn python_installations<'a>(
757754
environments: EnvironmentPreference,
758755
preference: PythonPreference,
759756
cache: &'a Cache,
760-
preview: Preview,
761757
) -> impl Iterator<Item = Result<PythonInstallation, Error>> + 'a {
762758
let installations = python_installations_from_executables(
763759
// Perform filtering on the discovered executables based on their source. This avoids
764760
// unnecessary interpreter queries, which are generally expensive. We'll filter again
765761
// with `interpreter_satisfies_environment_preference` after querying.
766-
python_executables(
767-
version,
768-
implementation,
769-
platform,
770-
environments,
771-
preference,
772-
preview,
773-
)
774-
.filter_ok(move |(source, path)| {
775-
source_satisfies_environment_preference(*source, path, environments)
776-
}),
762+
python_executables(version, implementation, platform, environments, preference).filter_ok(
763+
move |(source, path)| {
764+
source_satisfies_environment_preference(*source, path, environments)
765+
},
766+
),
777767
cache,
778768
)
779769
.filter_ok(move |installation| {
@@ -1044,7 +1034,6 @@ pub fn find_python_installations<'a>(
10441034
environments: EnvironmentPreference,
10451035
preference: PythonPreference,
10461036
cache: &'a Cache,
1047-
preview: Preview,
10481037
) -> Box<dyn Iterator<Item = Result<FindPythonResult, Error>> + 'a> {
10491038
let sources = DiscoveryPreferences {
10501039
python_preference: preference,
@@ -1136,7 +1125,6 @@ pub fn find_python_installations<'a>(
11361125
environments,
11371126
preference,
11381127
cache,
1139-
preview,
11401128
)
11411129
.map_ok(Ok)
11421130
}),
@@ -1149,7 +1137,6 @@ pub fn find_python_installations<'a>(
11491137
environments,
11501138
preference,
11511139
cache,
1152-
preview,
11531140
)
11541141
.map_ok(Ok)
11551142
}),
@@ -1166,7 +1153,6 @@ pub fn find_python_installations<'a>(
11661153
environments,
11671154
preference,
11681155
cache,
1169-
preview,
11701156
)
11711157
.map_ok(Ok)
11721158
})
@@ -1180,7 +1166,6 @@ pub fn find_python_installations<'a>(
11801166
environments,
11811167
preference,
11821168
cache,
1183-
preview,
11841169
)
11851170
.filter_ok(|installation| implementation.matches_interpreter(&installation.interpreter))
11861171
.map_ok(Ok)
@@ -1198,7 +1183,6 @@ pub fn find_python_installations<'a>(
11981183
environments,
11991184
preference,
12001185
cache,
1201-
preview,
12021186
)
12031187
.filter_ok(|installation| {
12041188
implementation.matches_interpreter(&installation.interpreter)
@@ -1222,7 +1206,6 @@ pub fn find_python_installations<'a>(
12221206
environments,
12231207
preference,
12241208
cache,
1225-
preview,
12261209
)
12271210
.filter_ok(move |installation| {
12281211
request.satisfied_by_interpreter(&installation.interpreter)
@@ -1242,10 +1225,8 @@ pub(crate) fn find_python_installation(
12421225
environments: EnvironmentPreference,
12431226
preference: PythonPreference,
12441227
cache: &Cache,
1245-
preview: Preview,
12461228
) -> Result<FindPythonResult, Error> {
1247-
let installations =
1248-
find_python_installations(request, environments, preference, cache, preview);
1229+
let installations = find_python_installations(request, environments, preference, cache);
12491230
let mut first_prerelease = None;
12501231
let mut first_debug = None;
12511232
let mut first_managed = None;
@@ -1403,7 +1384,6 @@ pub(crate) async fn find_best_python_installation(
14031384
python_install_mirror: Option<&str>,
14041385
pypy_install_mirror: Option<&str>,
14051386
python_downloads_json_url: Option<&str>,
1406-
preview: Preview,
14071387
) -> Result<PythonInstallation, crate::Error> {
14081388
debug!("Starting Python discovery for {request}");
14091389
let original_request = request;
@@ -1438,7 +1418,7 @@ pub(crate) async fn find_best_python_installation(
14381418
String::new()
14391419
}
14401420
);
1441-
let result = find_python_installation(request, environments, preference, cache, preview);
1421+
let result = find_python_installation(request, environments, preference, cache);
14421422
let error = match result {
14431423
Ok(Ok(installation)) => {
14441424
warn_on_unsupported_python(installation.interpreter());

‎crates/uv-python/src/environment.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use tracing::debug;
99
use uv_cache::Cache;
1010
use uv_fs::{LockedFile, LockedFileError, Simplified};
1111
use uv_pep440::Version;
12-
use uv_preview::Preview;
1312

1413
use crate::discovery::find_python_installation;
1514
use crate::installation::PythonInstallation;
@@ -154,11 +153,9 @@ impl PythonEnvironment {
154153
preference: EnvironmentPreference,
155154
python_preference: PythonPreference,
156155
cache: &Cache,
157-
preview: Preview,
158156
) -> Result<Self, Error> {
159157
let installation =
160-
match find_python_installation(request, preference, python_preference, cache, preview)?
161-
{
158+
match find_python_installation(request, preference, python_preference, cache)? {
162159
Ok(installation) => installation,
163160
Err(err) => return Err(EnvironmentNotFound::from(err).into()),
164161
};

‎crates/uv-python/src/installation.rs‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use uv_cache::Cache;
1313
use uv_client::{BaseClient, BaseClientBuilder};
1414
use uv_pep440::{Prerelease, Version};
1515
use uv_platform::{Arch, Libc, Os, Platform};
16-
use uv_preview::Preview;
1716

1817
use crate::discovery::{
1918
EnvironmentPreference, PythonRequest, find_best_python_installation, find_python_installation,
@@ -64,9 +63,8 @@ impl PythonInstallation {
6463
preference: PythonPreference,
6564
download_list: &ManagedPythonDownloadList,
6665
cache: &Cache,
67-
preview: Preview,
6866
) -> Result<Self, Error> {
69-
let installation = Self::find_existing(request, environments, preference, cache, preview)?;
67+
let installation = Self::find_existing(request, environments, preference, cache)?;
7068
installation.warn_if_outdated_prerelease(request, download_list);
7169
Ok(installation)
7270
}
@@ -77,14 +75,12 @@ impl PythonInstallation {
7775
environments: EnvironmentPreference,
7876
preference: PythonPreference,
7977
cache: &Cache,
80-
preview: Preview,
8178
) -> Result<Self, Error> {
8279
Ok(find_python_installation(
8380
request,
8481
environments,
8582
preference,
8683
cache,
87-
preview,
8884
)??)
8985
}
9086

@@ -101,7 +97,6 @@ impl PythonInstallation {
10197
python_install_mirror: Option<&str>,
10298
pypy_install_mirror: Option<&str>,
10399
python_downloads_json_url: Option<&str>,
104-
preview: Preview,
105100
) -> Result<Self, Error> {
106101
let downloads_enabled = preference.allows_managed()
107102
&& python_downloads.is_automatic()
@@ -117,7 +112,6 @@ impl PythonInstallation {
117112
python_install_mirror,
118113
pypy_install_mirror,
119114
python_downloads_json_url,
120-
preview,
121115
)
122116
.await?;
123117
installation
@@ -144,11 +138,10 @@ impl PythonInstallation {
144138
python_install_mirror: Option<&str>,
145139
pypy_install_mirror: Option<&str>,
146140
python_downloads_json_url: Option<&str>,
147-
preview: Preview,
148141
) -> Result<Self, Error> {
149142
let request = request.unwrap_or(&PythonRequest::Default);
150143

151-
let err = match Self::find_existing(request, environments, preference, cache, preview) {
144+
let err = match Self::find_existing(request, environments, preference, cache) {
152145
Ok(installation) => {
153146
installation
154147
.download_and_warn_if_outdated_prerelease(

0 commit comments

Comments
 (0)