Skip to content

Commit 20515e2

Browse files
authored
Update preference order for local venv in poetry environment (#338)
Fixes #335 Revise the order of preference for using a local virtual environment in the poetry configuration to prioritize project-level settings over environment variables and global settings.
1 parent 4dc8f73 commit 20515e2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/pet-poetry/src/environment_locations.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn list_all_environments_from_project_config(
105105

106106
// Check if we're allowed to use .venv as a poetry env
107107
// This can be configured in global, project or env variable.
108-
// Order of preference is Global, EnvVariable & Project (project wins)
108+
// Order of preference is Project (local config) > EnvVariable > Global
109109
if should_use_local_venv_as_poetry_env(global, &local, env) {
110110
// If virtualenvs are in the project, then look for .venv
111111
let venv = path.join(".venv");
@@ -121,21 +121,21 @@ fn should_use_local_venv_as_poetry_env(
121121
local: &Option<Config>,
122122
env: &EnvVariables,
123123
) -> bool {
124-
// Given preference to env variable.
125-
if let Some(poetry_virtualenvs_in_project) = env.poetry_virtualenvs_in_project {
124+
// Give preference to setting in local config file (project-level).
125+
if let Some(poetry_virtualenvs_in_project) =
126+
local.clone().and_then(|c| c.virtualenvs_in_project)
127+
{
126128
trace!(
127-
"Poetry virtualenvs_in_project from Env Variable: {}",
129+
"Poetry virtualenvs_in_project from local config file: {}",
128130
poetry_virtualenvs_in_project
129131
);
130132
return poetry_virtualenvs_in_project;
131133
}
132134

133-
// Give preference to setting in local config file.
134-
if let Some(poetry_virtualenvs_in_project) =
135-
local.clone().and_then(|c| c.virtualenvs_in_project)
136-
{
135+
// Then check env variable.
136+
if let Some(poetry_virtualenvs_in_project) = env.poetry_virtualenvs_in_project {
137137
trace!(
138-
"Poetry virtualenvs_in_project from local config file: {}",
138+
"Poetry virtualenvs_in_project from Env Variable: {}",
139139
poetry_virtualenvs_in_project
140140
);
141141
return poetry_virtualenvs_in_project;

0 commit comments

Comments
 (0)