diff --git a/crates/pet-core/src/lib.rs b/crates/pet-core/src/lib.rs index 8e4287f2..437b0d27 100644 --- a/crates/pet-core/src/lib.rs +++ b/crates/pet-core/src/lib.rs @@ -24,7 +24,7 @@ pub struct LocatorResult { #[derive(Debug, Default, Clone)] pub struct Configuration { /// These are paths like workspace folders, where we can look for environments. - pub project_directories: Option>, + pub workspace_directories: Option>, pub conda_executable: Option, pub poetry_executable: Option, /// Custom locations where environments can be found. diff --git a/crates/pet-poetry/src/environment_locations.rs b/crates/pet-poetry/src/environment_locations.rs index ac44409e..d25fd6b3 100644 --- a/crates/pet-poetry/src/environment_locations.rs +++ b/crates/pet-poetry/src/environment_locations.rs @@ -25,23 +25,23 @@ lazy_static! { pub fn list_environments( env: &EnvVariables, - project_dirs: &[PathBuf], + workspace_dirs: &[PathBuf], manager: Option, ) -> Option> { - if project_dirs.is_empty() { + if workspace_dirs.is_empty() { return None; } - let project_dirs = project_dirs + let workspace_dirs = workspace_dirs .iter() - .map(|project_dir| (project_dir, PyProjectToml::find(project_dir))) - .filter_map(|(project_dir, pyproject_toml)| { - pyproject_toml.map(|pyproject_toml| (project_dir, pyproject_toml)) + .map(|workspace_dir| (workspace_dir, PyProjectToml::find(workspace_dir))) + .filter_map(|(workspace_dir, pyproject_toml)| { + pyproject_toml.map(|pyproject_toml| (workspace_dir, pyproject_toml)) }) .collect::>(); // We're only interested in directories that have a pyproject.toml - if project_dirs.is_empty() { + if workspace_dirs.is_empty() { return None; } @@ -53,17 +53,17 @@ pub fn list_environments( global_envs = list_all_environments_from_config(&config).unwrap_or_default(); } - for (project_dir, pyproject_toml) in project_dirs { - let virtualenv_prefix = generate_env_name(&pyproject_toml.name, project_dir); + for (workspace_dir, pyproject_toml) in workspace_dirs { + let virtualenv_prefix = generate_env_name(&pyproject_toml.name, workspace_dir); trace!( "Found pyproject.toml ({}): {:?} in {:?}", virtualenv_prefix, pyproject_toml.name, - project_dir + workspace_dir ); for virtual_env in [ - list_all_environments_from_project_config(&global_config, project_dir, env) + list_all_environments_from_project_config(&global_config, workspace_dir, env) .unwrap_or_default(), global_envs.clone(), ] @@ -78,7 +78,7 @@ pub fn list_environments( // Look for .venv as well, in case we create the virtual envs in the local project folder. if name.starts_with(&virtualenv_prefix) || name.starts_with(".venv") { if let Some(env) = - create_poetry_env(&virtual_env, project_dir.clone(), manager.clone()) + create_poetry_env(&virtual_env, workspace_dir.clone(), manager.clone()) { envs.push(env); } diff --git a/crates/pet-poetry/src/environment_locations_spawn.rs b/crates/pet-poetry/src/environment_locations_spawn.rs index 2551fe55..6e696424 100644 --- a/crates/pet-poetry/src/environment_locations_spawn.rs +++ b/crates/pet-poetry/src/environment_locations_spawn.rs @@ -16,15 +16,15 @@ lazy_static! { pub fn list_environments( executable: &PathBuf, - project_dirs: &Vec, + workspace_dirs: &Vec, manager: &PoetryManager, ) -> Vec { let mut envs = vec![]; - for project_dir in project_dirs { - if let Some(project_envs) = get_environments(executable, project_dir) { - for project_env in project_envs { + for workspace_dir in workspace_dirs { + if let Some(workspace_envs) = get_environments(executable, workspace_dir) { + for workspace_env in workspace_envs { if let Some(env) = - create_poetry_env(&project_env, project_dir.clone(), Some(manager.clone())) + create_poetry_env(&workspace_env, workspace_dir.clone(), Some(manager.clone())) { envs.push(env); } @@ -34,19 +34,19 @@ pub fn list_environments( envs } -fn get_environments(executable: &PathBuf, project_dir: &PathBuf) -> Option> { +fn get_environments(executable: &PathBuf, workspace_dir: &PathBuf) -> Option> { let start = SystemTime::now(); let result = std::process::Command::new(executable) .arg("env") .arg("list") .arg("--full-path") - .current_dir(project_dir) + .current_dir(workspace_dir) .output(); trace!( "Executed Poetry ({}ms): {:?} env list --full-path for {:?}", start.elapsed().unwrap_or_default().as_millis(), executable, - project_dir + workspace_dir ); match result { Ok(output) => { @@ -89,10 +89,11 @@ pub struct PoetryConfig { pub virtualenvs_path: Option, } -pub fn get_config(executable: &PathBuf, project_dir: &PathBuf) -> PoetryConfig { - let cache_dir = get_config_path(executable, project_dir, "cache-dir"); - let virtualenvs_path = get_config_path(executable, project_dir, "virtualenvs.path"); - let virtualenvs_in_project = get_config_bool(executable, project_dir, "virtualenvs.in-project"); +pub fn get_config(executable: &PathBuf, workspace_dir: &PathBuf) -> PoetryConfig { + let cache_dir = get_config_path(executable, workspace_dir, "cache-dir"); + let virtualenvs_path = get_config_path(executable, workspace_dir, "virtualenvs.path"); + let virtualenvs_in_project = + get_config_bool(executable, workspace_dir, "virtualenvs.in-project"); PoetryConfig { cache_dir, virtualenvs_in_project, @@ -100,8 +101,8 @@ pub fn get_config(executable: &PathBuf, project_dir: &PathBuf) -> PoetryConfig { } } -fn get_config_bool(executable: &PathBuf, project_dir: &PathBuf, setting: &str) -> Option { - match get_config_value(executable, project_dir, setting) { +fn get_config_bool(executable: &PathBuf, workspace_dir: &PathBuf, setting: &str) -> Option { + match get_config_value(executable, workspace_dir, setting) { Some(output) => { let output = output.trim(); if output.starts_with("true") { @@ -115,19 +116,27 @@ fn get_config_bool(executable: &PathBuf, project_dir: &PathBuf, setting: &str) - None => None, } } -fn get_config_path(executable: &PathBuf, project_dir: &PathBuf, setting: &str) -> Option { - get_config_value(executable, project_dir, setting).map(|output| PathBuf::from(output.trim())) +fn get_config_path( + executable: &PathBuf, + workspace_dir: &PathBuf, + setting: &str, +) -> Option { + get_config_value(executable, workspace_dir, setting).map(|output| PathBuf::from(output.trim())) } -fn get_config_value(executable: &PathBuf, project_dir: &PathBuf, setting: &str) -> Option { +fn get_config_value( + executable: &PathBuf, + workspace_dir: &PathBuf, + setting: &str, +) -> Option { let start = SystemTime::now(); let result = std::process::Command::new(executable) .arg("config") .arg(setting) - .current_dir(project_dir) + .current_dir(workspace_dir) .output(); trace!( - "Executed Poetry ({}ms): {executable:?} config {setting} {project_dir:?}", + "Executed Poetry ({}ms): {executable:?} config {setting} {workspace_dir:?}", start.elapsed().unwrap_or_default().as_millis(), ); match result { @@ -137,7 +146,7 @@ fn get_config_value(executable: &PathBuf, project_dir: &PathBuf, setting: &str) } else { let stderr = String::from_utf8_lossy(&output.stderr).to_string(); trace!( - "Failed to get Poetry config {setting} using exe {executable:?} in {project_dir:?}, due to ({}) {}", + "Failed to get Poetry config {setting} using exe {executable:?} in {workspace_dir:?}, due to ({}) {}", output.status.code().unwrap_or_default(), stderr ); diff --git a/crates/pet-poetry/src/lib.rs b/crates/pet-poetry/src/lib.rs index 89de0c39..0838d0e5 100644 --- a/crates/pet-poetry/src/lib.rs +++ b/crates/pet-poetry/src/lib.rs @@ -40,7 +40,7 @@ pub trait PoetryLocator: Send + Sync { } pub struct Poetry { - pub project_directories: Arc>>, + pub workspace_directories: Arc>>, pub env_vars: EnvVariables, pub poetry_executable: Arc>>, searched: AtomicBool, @@ -52,7 +52,7 @@ impl Poetry { Poetry { searched: AtomicBool::new(false), search_result: Arc::new(Mutex::new(None)), - project_directories: Arc::new(Mutex::new(vec![])), + workspace_directories: Arc::new(Mutex::new(vec![])), env_vars: EnvVariables::from(environment), poetry_executable: Arc::new(Mutex::new(None)), } @@ -76,10 +76,10 @@ impl Poetry { if let Some(manager) = &manager { result.managers.push(manager.to_manager()); } - if let Ok(values) = self.project_directories.lock() { - let project_dirs = values.clone(); + if let Ok(values) = self.workspace_directories.lock() { + let workspace_dirs = values.clone(); drop(values); - let envs = list_environments(&self.env_vars, &project_dirs.clone(), manager) + let envs = list_environments(&self.env_vars, &workspace_dirs.clone(), manager) .unwrap_or_default(); result.environments.extend(envs.clone()); } @@ -112,10 +112,10 @@ impl PoetryLocator for Poetry { let manager = PoetryManager::find(poetry_executable.clone(), &self.env_vars)?; let poetry_executable = manager.executable.clone(); - let project_dirs = self.project_directories.lock().unwrap().clone(); + let workspace_dirs = self.workspace_directories.lock().unwrap().clone(); let environments_using_spawn = environment_locations_spawn::list_environments( &poetry_executable, - &project_dirs, + &workspace_dirs, &manager, ); @@ -123,7 +123,7 @@ impl PoetryLocator for Poetry { let _ = report_missing_envs( reporter, &poetry_executable, - project_dirs, + workspace_dirs, &self.env_vars, &environments_using_spawn, result, @@ -139,13 +139,13 @@ impl Locator for Poetry { "Poetry" } fn configure(&self, config: &Configuration) { - if let Some(project_directories) = &config.project_directories { - self.project_directories.lock().unwrap().clear(); - if !project_directories.is_empty() { - self.project_directories + if let Some(workspace_directories) = &config.workspace_directories { + self.workspace_directories.lock().unwrap().clear(); + if !workspace_directories.is_empty() { + self.workspace_directories .lock() .unwrap() - .extend(project_directories.clone()); + .extend(workspace_directories.clone()); } } if let Some(exe) = &config.poetry_executable { diff --git a/crates/pet-poetry/src/telemetry.rs b/crates/pet-poetry/src/telemetry.rs index 8aa3df55..bbcf7714 100644 --- a/crates/pet-poetry/src/telemetry.rs +++ b/crates/pet-poetry/src/telemetry.rs @@ -16,16 +16,16 @@ use crate::{config::Config, env_variables::EnvVariables, environment_locations_s pub fn report_missing_envs( reporter: &dyn Reporter, executable: &PathBuf, - project_dirs: Vec, + workspace_dirs: Vec, env_vars: &EnvVariables, envs_discovered_by_poetry: &[PythonEnvironment], envs_discovered_by_us: Option, user_provided_poetry_exe: bool, ) -> Option<()> { - for projec_dir in project_dirs { - let config = get_config(executable, &projec_dir); + for workspace_dir in workspace_dirs { + let config = get_config(executable, &workspace_dir); let global_config = Config::find_global(env_vars); - let local_config = Config::find_local(&projec_dir, env_vars); + let local_config = Config::find_local(&workspace_dir, env_vars); let global_virtualenvs_path = global_config.clone().map(|c| c.virtualenvs_path.clone()); let local_virtualenvs_path = local_config.clone().map(|c| c.virtualenvs_path.clone()); @@ -47,12 +47,12 @@ pub fn report_missing_envs( .map(|e| e.environments.clone()) .unwrap_or_default() .iter() - .filter(|e| e.project == Some(projec_dir.clone())) + .filter(|e| e.project == Some(workspace_dir.clone())) .flat_map(|e| e.prefix.clone()) .collect(); let envs_discovered_by_poetry: HashSet<_> = envs_discovered_by_poetry .iter() - .filter(|e| e.project == Some(projec_dir.clone())) + .filter(|e| e.project == Some(workspace_dir.clone())) .flat_map(|e| e.prefix.clone()) .collect(); @@ -118,7 +118,7 @@ pub fn report_missing_envs( } warn!( "Missing Poetry envs: {:?} for {:?}", - missing_envs, projec_dir + missing_envs, workspace_dir ); let missing_info = MissingPoetryEnvironments { diff --git a/crates/pet/src/find.rs b/crates/pet/src/find.rs index b7cd6580..8af41ff6 100644 --- a/crates/pet/src/find.rs +++ b/crates/pet/src/find.rs @@ -27,7 +27,7 @@ pub struct Summary { pub find_locators_time: Duration, pub find_path_time: Duration, pub find_global_virtual_envs_time: Duration, - pub find_search_paths_time: Duration, + pub find_workspace_directories_time: Duration, } pub fn find_and_report_envs( @@ -42,13 +42,13 @@ pub fn find_and_report_envs( find_locators_time: Duration::from_secs(0), find_path_time: Duration::from_secs(0), find_global_virtual_envs_time: Duration::from_secs(0), - find_search_paths_time: Duration::from_secs(0), + find_workspace_directories_time: Duration::from_secs(0), })); let start = std::time::Instant::now(); // From settings let environment_directories = configuration.environment_directories.unwrap_or_default(); - let project_directories = configuration.project_directories.unwrap_or_default(); + let workspace_directories = configuration.workspace_directories.unwrap_or_default(); thread::scope(|s| { // 1. Find using known global locators. s.spawn(|| { @@ -129,20 +129,20 @@ pub fn find_and_report_envs( // & users can have a lot of workspace folders and can have a large number fo files/directories // that could the discovery. s.spawn(|| { - if project_directories.is_empty() { + if workspace_directories.is_empty() { return; } trace!( "Searching for environments in custom folders: {:?}", - project_directories + workspace_directories ); let start = std::time::Instant::now(); find_python_environments_in_workspace_folders_recursive( - project_directories, + workspace_directories, reporter, locators, ); - summary.lock().unwrap().find_search_paths_time = start.elapsed(); + summary.lock().unwrap().find_workspace_directories_time = start.elapsed(); }); }); summary.lock().unwrap().time = start.elapsed(); diff --git a/crates/pet/src/jsonrpc.rs b/crates/pet/src/jsonrpc.rs index 27522471..4c1ca541 100644 --- a/crates/pet/src/jsonrpc.rs +++ b/crates/pet/src/jsonrpc.rs @@ -62,23 +62,50 @@ pub fn start_jsonrpc_server() { }; let mut handlers = HandlersKeyedByMethodName::new(Arc::new(context)); + handlers.add_request_handler("configure", handle_configure); handlers.add_request_handler("refresh", handle_refresh); handlers.add_request_handler("resolve", handle_resolve); start_server(&handlers) } #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct RequestOptions { +#[serde(rename_all = "camelCase")] +pub struct ConfigureOptions { /// These are paths like workspace folders, where we can look for environments. - pub project_directories: Option>, + pub workspace_directories: Option>, pub conda_executable: Option, pub poetry_executable: Option, - /// Custom locations where environments can be found. - /// These are different from search_paths, as these are specific directories where environments are expected. - /// search_paths on the other hand can be any directory such as a workspace folder, where envs might never exist. + /// Custom locations where environments can be found. Generally global locations where virtualenvs & the like can be found. + /// Workspace directories should not be included into this list. pub environment_directories: Option>, } +pub fn handle_configure(context: Arc, id: u32, params: Value) { + match serde_json::from_value::(params.clone()) { + Ok(configure_options) => { + // Start in a new thread, we can have multiple requests. + thread::spawn(move || { + let mut cfg = context.configuration.write().unwrap(); + cfg.workspace_directories = configure_options.workspace_directories; + cfg.conda_executable = configure_options.conda_executable; + cfg.environment_directories = configure_options.environment_directories; + cfg.poetry_executable = configure_options.poetry_executable; + trace!("Configuring locators: {:?}", cfg); + drop(cfg); + let config = context.configuration.read().unwrap().clone(); + for locator in context.locators.iter() { + locator.configure(&config); + } + send_reply(id, None::<()>); + }); + } + Err(e) => { + send_reply(id, None::); + error!("Failed to parse configure options {:?}: {}", params, e); + } + } +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct RefreshResult { duration: u128, @@ -92,97 +119,78 @@ impl RefreshResult { } } -pub fn handle_refresh(context: Arc, id: u32, params: Value) { - match serde_json::from_value::(params.clone()) { - Ok(request_options) => { - // Start in a new thread, we can have multiple requests. +pub fn handle_refresh(context: Arc, id: u32, _params: Value) { + // Start in a new thread, we can have multiple requests. + thread::spawn(move || { + let config = context.configuration.read().unwrap().clone(); + trace!("Start refreshing environments, config: {:?}", config); + let summary = find_and_report_envs( + context.reporter.as_ref(), + config, + &context.locators, + context.os_environment.deref(), + ); + let summary = summary.lock().unwrap(); + for locator in summary.find_locators_times.iter() { + info!("Locator {} took {:?}", locator.0, locator.1); + } + info!( + "Environments found using locators in {:?}", + summary.find_locators_time + ); + info!("Environments in PATH found in {:?}", summary.find_path_time); + info!( + "Environments in global virtual env paths found in {:?}", + summary.find_global_virtual_envs_time + ); + info!( + "Environments in workspace folders found in {:?}", + summary.find_workspace_directories_time + ); + trace!("Finished refreshing environments in {:?}", summary.time); + send_reply(id, Some(RefreshResult::new(summary.time))); + + // Find an report missing envs for the first launch of this process. + if MISSING_ENVS_REPORTED + .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) + .ok() + .unwrap_or_default() + { + // By now all conda envs have been found + // Spawn conda in a separate thread. + // & see if we can find more environments by spawning conda. + // But we will not wait for this to complete. + let conda_locator = context.conda_locator.clone(); + let conda_executable = context + .configuration + .read() + .unwrap() + .conda_executable + .clone(); + let reporter = context.reporter.clone(); thread::spawn(move || { - let mut cfg = context.configuration.write().unwrap(); - cfg.project_directories = request_options.project_directories; - cfg.conda_executable = request_options.conda_executable; - cfg.environment_directories = request_options.environment_directories; - cfg.poetry_executable = request_options.poetry_executable; - trace!("Start refreshing environments, config: {:?}", cfg); - drop(cfg); - let config = context.configuration.read().unwrap().clone(); - for locator in context.locators.iter() { - locator.configure(&config); - } - let summary = find_and_report_envs( - context.reporter.as_ref(), - config, - &context.locators, - context.os_environment.deref(), - ); - let summary = summary.lock().unwrap(); - for locator in summary.find_locators_times.iter() { - info!("Locator {} took {:?}", locator.0, locator.1); - } - info!( - "Environments found using locators in {:?}", - summary.find_locators_time - ); - info!("Environments in PATH found in {:?}", summary.find_path_time); - info!( - "Environments in global virtual env paths found in {:?}", - summary.find_global_virtual_envs_time - ); - info!( - "Environments in custom search paths found in {:?}", - summary.find_search_paths_time - ); - trace!("Finished refreshing environments in {:?}", summary.time); - send_reply(id, Some(RefreshResult::new(summary.time))); - - // Find an report missing envs for the first launch of this process. - if MISSING_ENVS_REPORTED - .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) - .ok() - .unwrap_or_default() - { - // By now all conda envs have been found - // Spawn conda in a separate thread. - // & see if we can find more environments by spawning conda. - // But we will not wait for this to complete. - let conda_locator = context.conda_locator.clone(); - let conda_executable = context - .configuration - .read() - .unwrap() - .conda_executable - .clone(); - let reporter = context.reporter.clone(); - thread::spawn(move || { - conda_locator - .find_and_report_missing_envs(reporter.as_ref(), conda_executable); - Some(()) - }); - - // By now all poetry envs have been found - // Spawn poetry exe in a separate thread. - // & see if we can find more environments by spawning poetry. - // But we will not wait for this to complete. - let poetry_locator = context.poetry_locator.clone(); - let poetry_executable = context - .configuration - .read() - .unwrap() - .poetry_executable - .clone(); - let reporter = context.reporter.clone(); - thread::spawn(move || { - poetry_locator - .find_and_report_missing_envs(reporter.as_ref(), poetry_executable); - Some(()) - }); - } + conda_locator.find_and_report_missing_envs(reporter.as_ref(), conda_executable); + Some(()) + }); + + // By now all poetry envs have been found + // Spawn poetry exe in a separate thread. + // & see if we can find more environments by spawning poetry. + // But we will not wait for this to complete. + let poetry_locator = context.poetry_locator.clone(); + let poetry_executable = context + .configuration + .read() + .unwrap() + .poetry_executable + .clone(); + let reporter = context.reporter.clone(); + thread::spawn(move || { + poetry_locator.find_and_report_missing_envs(reporter.as_ref(), poetry_executable); + Some(()) }); } - Err(e) => { - send_reply(id, None::); - error!("Failed to parse request options {:?}: {}", params, e); - } - } + }); } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -199,7 +207,7 @@ pub fn handle_resolve(context: Arc, id: u32, params: Value) { .read() .unwrap() .clone() - .project_directories; + .workspace_directories; let search_paths = search_paths.unwrap_or_default(); // Start in a new thread, we can have multiple resolve requests. let environment = context.os_environment.clone(); diff --git a/crates/pet/src/lib.rs b/crates/pet/src/lib.rs index 42285a8c..ee6d12b1 100644 --- a/crates/pet/src/lib.rs +++ b/crates/pet/src/lib.rs @@ -36,7 +36,7 @@ pub fn find_and_report_envs_stdio( let mut config = Configuration::default(); if let Ok(cwd) = env::current_dir() { - config.project_directories = Some(vec![cwd]); + config.workspace_directories = Some(vec![cwd]); } let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { @@ -75,7 +75,7 @@ pub fn find_and_report_envs_stdio( ); println!( "{:<20} : {:?}", - "Custom search paths", summary.find_search_paths_time + "Workspace folders", summary.find_workspace_directories_time ); println!(); let summary = stdio_reporter.get_summary(); diff --git a/crates/pet/tests/ci_poetry.rs b/crates/pet/tests/ci_poetry.rs index e40532f2..04f2da08 100644 --- a/crates/pet/tests/ci_poetry.rs +++ b/crates/pet/tests/ci_poetry.rs @@ -20,13 +20,13 @@ fn verify_ci_poetry_global() { use pet_reporter::test; use std::{env, path::PathBuf, sync::Arc}; - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); let reporter = test::create_reporter(); let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); let mut config = Configuration::default(); - config.project_directories = Some(vec![project_dir.clone()]); + config.workspace_directories = Some(vec![workspace_dir.clone()]); let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); @@ -50,7 +50,8 @@ fn verify_ci_poetry_global() { let poetry_envs = environments .iter() .filter(|e| { - e.kind == Some(PythonEnvironmentKind::Poetry) && e.project == Some(project_dir.clone()) + e.kind == Some(PythonEnvironmentKind::Poetry) + && e.project == Some(workspace_dir.clone()) }) .collect::>(); @@ -81,13 +82,13 @@ fn verify_ci_poetry_project() { use pet_reporter::test; use std::{env, path::PathBuf, sync::Arc}; - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); let reporter = test::create_reporter(); let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); let mut config = Configuration::default(); - config.project_directories = Some(vec![project_dir.clone()]); + config.workspace_directories = Some(vec![workspace_dir.clone()]); let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); @@ -111,7 +112,8 @@ fn verify_ci_poetry_project() { let poetry_envs = environments .iter() .filter(|e| { - e.kind == Some(PythonEnvironmentKind::Poetry) && e.project == Some(project_dir.clone()) + e.kind == Some(PythonEnvironmentKind::Poetry) + && e.project == Some(workspace_dir.clone()) }) .collect::>(); @@ -127,6 +129,6 @@ fn verify_ci_poetry_project() { ); assert_eq!( poetry_envs[0].prefix.clone().unwrap_or_default(), - project_dir.join(".venv") + workspace_dir.join(".venv") ); } diff --git a/crates/pet/tests/ci_test.rs b/crates/pet/tests/ci_test.rs index 19523d30..59952053 100644 --- a/crates/pet/tests/ci_test.rs +++ b/crates/pet/tests/ci_test.rs @@ -67,13 +67,13 @@ fn verify_validity_of_discovered_envs() { setup(); - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); let reporter = test::create_reporter(); let environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&environment)); let poetry_locator = Arc::new(Poetry::from(&environment)); let mut config = Configuration::default(); - config.project_directories = Some(vec![project_dir.clone()]); + config.workspace_directories = Some(vec![workspace_dir.clone()]); let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment); for locator in locators.iter() { locator.configure(&config); @@ -188,12 +188,12 @@ fn check_if_pipenv_exists() { let result = reporter.get_result(); let environments = result.environments; - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); environments .iter() .find(|env| { env.kind == Some(PythonEnvironmentKind::Pipenv) - && env.project == Some(project_dir.clone()) + && env.project == Some(workspace_dir.clone()) }) .expect(format!("Pipenv environment not found, found {environments:?}").as_str()); } @@ -336,13 +336,13 @@ fn verify_we_can_get_same_env_info_using_from_with_exe( use pet_core::{os_environment::EnvironmentApi, Configuration}; use std::{env, sync::Arc}; - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); let os_environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&os_environment)); let poetry_locator = Arc::new(Poetry::from(&os_environment)); let mut config = Configuration::default(); - let search_paths = vec![project_dir.clone()]; - config.project_directories = Some(search_paths.clone()); + let search_paths = vec![workspace_dir.clone()]; + config.workspace_directories = Some(search_paths.clone()); let locators = create_locators( conda_locator.clone(), poetry_locator.clone(), @@ -359,7 +359,7 @@ fn verify_we_can_get_same_env_info_using_from_with_exe( &env, &locators, &global_env_search_paths, - Some(project_dir.clone()), + Some(workspace_dir.clone()), ) .expect(format!("Failed to resolve environment using `resolve` for {environment:?}").as_str()); trace!( @@ -528,12 +528,12 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe( use pet_core::{os_environment::EnvironmentApi, Configuration}; use std::{env, sync::Arc}; - let project_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); + let workspace_dir = PathBuf::from(env::var("GITHUB_WORKSPACE").unwrap_or_default()); let os_environment = EnvironmentApi::new(); let conda_locator = Arc::new(Conda::from(&os_environment)); let poetry_locator = Arc::new(Poetry::from(&os_environment)); let mut config = Configuration::default(); - config.project_directories = Some(vec![project_dir.clone()]); + config.workspace_directories = Some(vec![workspace_dir.clone()]); let locators = create_locators( conda_locator.clone(), poetry_locator.clone(), @@ -546,7 +546,7 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe( let env = resolve_environment( &executable, &locators, - vec![project_dir.clone()], + vec![workspace_dir.clone()], &os_environment, ) .expect(format!("Failed to resolve environment using `resolve` for {environment:?}").as_str());