Skip to content

Commit e76a8db

Browse files
authored
Always list all global poetry envs (#158)
For microsoft/vscode-python#24071
1 parent d2df753 commit e76a8db

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

crates/pet-poetry/src/config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ impl Config {
5757
}
5858

5959
fn create_config(file: Option<PathBuf>, env: &EnvVariables) -> Option<Config> {
60+
if let Some(file) = &file {
61+
trace!("Parsing Poetry config file => {:?}", file);
62+
}
63+
6064
let cfg = file.clone().and_then(|f| parse(&f));
6165
let cache_dir = get_cache_dir(&cfg, env);
6266
let virtualenvs_path_from_env_var = env
@@ -65,7 +69,6 @@ fn create_config(file: Option<PathBuf>, env: &EnvVariables) -> Option<Config> {
6569
.map(|p| resolve_virtualenvs_path(&p, &cache_dir));
6670

6771
if let Some(virtualenvs_path) = &cfg.clone().and_then(|cfg| cfg.virtualenvs_path) {
68-
trace!("Poetry virtualenvs path => {:?}", virtualenvs_path);
6972
let virtualenvs_path = resolve_virtualenvs_path(&virtualenvs_path.clone(), &cache_dir);
7073

7174
return Some(Config::new(
@@ -113,24 +116,29 @@ fn resolve_virtualenvs_path(virtualenvs_path: &Path, cache_dir: &Option<PathBuf>
113116
return virtualenvs_path;
114117
}
115118
}
119+
trace!("Poetry virtualenvs path => {:?}", virtualenvs_path);
116120
virtualenvs_path.to_path_buf()
117121
}
118122
/// Maps to DEFAULT_CACHE_DIR in poetry
119123
fn get_cache_dir(cfg: &Option<ConfigToml>, env: &EnvVariables) -> Option<PathBuf> {
120124
// Cache dir in env variables takes precedence
121125
if let Some(cache_dir) = env.poetry_cache_dir.clone() {
122126
if cache_dir.is_dir() {
127+
trace!("Poetry cache dir from env variable: {:?}", cache_dir);
123128
return Some(cache_dir);
124129
}
125130
}
126131
// Check cache dir in config.
127132
if let Some(cache_dir) = cfg.as_ref().and_then(|cfg| cfg.cache_dir.clone()) {
128133
if cache_dir.is_dir() {
134+
trace!("Poetry cache dir from config: {:?}", cache_dir);
129135
return Some(cache_dir);
130136
}
131137
}
132138

133-
Platformdirs::new(_APP_NAME.into(), false).user_cache_path()
139+
let default_cache_dir = Platformdirs::new(_APP_NAME.into(), false).user_cache_path();
140+
trace!("Poetry cache (default): {:?}", default_cache_dir);
141+
default_cache_dir
134142
}
135143

136144
/// Maps to CONFIG_DIR in poetry
@@ -163,7 +171,9 @@ struct ConfigToml {
163171

164172
fn parse(file: &Path) -> Option<ConfigToml> {
165173
let contents = fs::read_to_string(file).ok()?;
166-
parse_contents(&contents)
174+
let cfg = parse_contents(&contents);
175+
trace!("Poetry config file for {:?} is {:?}", file, cfg);
176+
cfg
167177
}
168178

169179
fn parse_contents(contents: &str) -> Option<ConfigToml> {

crates/pet-poetry/src/environment_locations.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ pub fn list_environments(
4040
})
4141
.collect::<Vec<_>>();
4242

43-
// We're only interested in directories that have a pyproject.toml
44-
if workspace_dirs.is_empty() {
45-
return None;
46-
}
47-
4843
let mut envs = vec![];
4944

5045
let global_config = Config::find_global(env);
@@ -53,6 +48,10 @@ pub fn list_environments(
5348
global_envs = list_all_environments_from_config(&config).unwrap_or_default();
5449
}
5550

51+
if workspace_dirs.is_empty() {
52+
trace!("pyproject.toml not found in any workspace directory");
53+
}
54+
5655
for (workspace_dir, pyproject_toml) in workspace_dirs {
5756
let virtualenv_prefix = generate_env_name(&pyproject_toml.name, workspace_dir);
5857
trace!(

0 commit comments

Comments
 (0)