@@ -6,11 +6,14 @@ use tracing::debug;
66use uv_cache:: Cache ;
77use uv_client:: BaseClientBuilder ;
88use uv_configuration:: {
9- Concurrency , DependencyGroups , DryRun , ExtrasSpecification , InstallOptions ,
9+ Concurrency , DependencyGroups , DependencyGroupsWithDefaults , DryRun , ExtrasSpecification ,
10+ InstallOptions ,
1011} ;
1112use uv_normalize:: DefaultExtras ;
1213use uv_preview:: { Preview , PreviewFeature } ;
13- use uv_python:: { PythonDownloads , PythonPreference , PythonRequest } ;
14+ use uv_python:: {
15+ EnvironmentPreference , PythonDownloads , PythonInstallation , PythonPreference , PythonRequest ,
16+ } ;
1417use uv_settings:: { MalwareCheckSettings , PythonInstallMirrors } ;
1518use uv_warnings:: warn_user;
1619use uv_workspace:: { DiscoveryOptions , VirtualProject , WorkspaceCache , WorkspaceError } ;
@@ -20,8 +23,10 @@ use crate::commands::pip::operations::Modifications;
2023use crate :: commands:: project:: install_target:: InstallTarget ;
2124use crate :: commands:: project:: lock:: LockMode ;
2225use crate :: commands:: project:: {
23- ProjectEnvironment , ProjectError , UniversalState , default_dependency_groups,
26+ ProjectEnvironment , ProjectError , UniversalState , WorkspacePython , default_dependency_groups,
27+ validate_project_requires_python,
2428} ;
29+ use crate :: commands:: reporters:: PythonDownloadReporter ;
2530use crate :: commands:: { ExitStatus , diagnostics, project} ;
2631use crate :: printer:: Printer ;
2732use crate :: settings:: { FrozenSource , LockCheck , ResolverInstallerSettings } ;
@@ -35,6 +40,7 @@ pub(crate) async fn check(
3540 lock_check : LockCheck ,
3641 frozen : Option < FrozenSource > ,
3742 no_sync : bool ,
43+ isolated : bool ,
3844 extras : ExtrasSpecification ,
3945 groups : DependencyGroups ,
4046 python : Option < String > ,
@@ -117,30 +123,97 @@ pub(crate) async fn check(
117123 . map ( |p| p. root ( ) . to_owned ( ) )
118124 . unwrap_or_else ( || project_dir. to_owned ( ) ) ;
119125
120- // If we found a project, sync the environment before running checks.
121- let venv_path = if let Some ( project) = & project {
122- let default_groups = default_dependency_groups ( project. pyproject_toml ( ) ) ?;
123- let default_extras = DefaultExtras :: default ( ) ;
124- let groups = groups. with_defaults ( default_groups) ;
125- let extras = extras. with_defaults ( default_extras) ;
126+ let groups = if let Some ( project) = & project {
127+ groups. with_defaults ( default_dependency_groups ( project. pyproject_toml ( ) ) ?)
128+ } else {
129+ DependencyGroupsWithDefaults :: none ( )
130+ } ;
126131
127- let venv = ProjectEnvironment :: get_or_init (
128- project. workspace ( ) ,
129- & groups,
132+ // Create an isolated environment, if requested.
133+ let temp_dir;
134+ let isolated_venv = if isolated {
135+ debug ! ( "Creating isolated virtual environment" ) ;
136+
137+ let workspace = project. as_ref ( ) . map ( VirtualProject :: workspace) ;
138+ let WorkspacePython {
139+ source,
140+ python_request,
141+ requires_python,
142+ } = WorkspacePython :: from_request (
130143 python. as_deref ( ) . map ( PythonRequest :: parse) ,
131- & install_mirrors,
132- & client_builder,
144+ workspace,
145+ & groups,
146+ project_dir,
147+ no_config,
148+ )
149+ . await ?;
150+
151+ let reporter = PythonDownloadReporter :: single ( printer) ;
152+ let interpreter = PythonInstallation :: find_or_download (
153+ python_request. as_ref ( ) ,
154+ EnvironmentPreference :: Any ,
133155 python_preference,
134156 python_downloads,
135- no_sync,
136- no_config,
137- None ,
157+ & client_builder,
138158 cache,
139- DryRun :: Disabled ,
140- printer,
159+ Some ( & reporter) ,
160+ install_mirrors. python_install_mirror . as_deref ( ) ,
161+ install_mirrors. pypy_install_mirror . as_deref ( ) ,
162+ install_mirrors. python_downloads_json_url . as_deref ( ) ,
141163 )
142164 . await ?
143- . into_environment ( ) ?;
165+ . into_interpreter ( ) ;
166+
167+ if let Some ( requires_python) = requires_python. as_ref ( ) {
168+ validate_project_requires_python (
169+ & interpreter,
170+ workspace,
171+ & groups,
172+ requires_python,
173+ & source,
174+ ) ?;
175+ }
176+
177+ temp_dir = cache. venv_dir ( ) ?;
178+ Some ( uv_virtualenv:: create_venv (
179+ temp_dir. path ( ) ,
180+ interpreter,
181+ uv_virtualenv:: Prompt :: None ,
182+ false ,
183+ uv_virtualenv:: OnExisting :: Remove ( uv_virtualenv:: RemovalReason :: TemporaryEnvironment ) ,
184+ false ,
185+ false ,
186+ false ,
187+ ) ?)
188+ } else {
189+ None
190+ } ;
191+
192+ // Select an environment and, if we found a project, sync it before running checks.
193+ let venv_path = if let Some ( project) = & project {
194+ let extras = extras. with_defaults ( DefaultExtras :: default ( ) ) ;
195+
196+ let venv = if let Some ( venv) = isolated_venv {
197+ venv
198+ } else {
199+ ProjectEnvironment :: get_or_init (
200+ project. workspace ( ) ,
201+ & groups,
202+ python. as_deref ( ) . map ( PythonRequest :: parse) ,
203+ & install_mirrors,
204+ & client_builder,
205+ python_preference,
206+ python_downloads,
207+ no_sync,
208+ no_config,
209+ None ,
210+ cache,
211+ DryRun :: Disabled ,
212+ printer,
213+ )
214+ . await ?
215+ . into_environment ( ) ?
216+ } ;
144217
145218 if no_sync {
146219 debug ! ( "Skipping environment synchronization due to `--no-sync`" ) ;
@@ -160,6 +233,8 @@ pub(crate) async fn check(
160233 LockMode :: Frozen ( frozen_source. into ( ) )
161234 } else if let LockCheck :: Enabled ( lock_check) = lock_check {
162235 LockMode :: Locked ( venv. interpreter ( ) , lock_check)
236+ } else if isolated {
237+ LockMode :: DryRun ( venv. interpreter ( ) )
163238 } else {
164239 LockMode :: Write ( venv. interpreter ( ) )
165240 } ;
@@ -245,7 +320,7 @@ pub(crate) async fn check(
245320
246321 Some ( venv. root ( ) . to_owned ( ) )
247322 } else {
248- None
323+ isolated_venv . map ( |venv| venv . root ( ) . to_owned ( ) )
249324 } ;
250325
251326 let exclude_newer = settings
0 commit comments