Skip to content

Commit e364131

Browse files
authored
feat: add missing CLI arguments for find command with env var fallbacks (#356)
Adds CLI arguments to the `find` command that mirror the JSONRPC server's `configure` options, with `PET_*` environment variable fallbacks via clap's `env` attribute. ## Changes - Add `--conda-executable` / `PET_CONDA_EXECUTABLE` to `find` - Add `--pipenv-executable` / `PET_PIPENV_EXECUTABLE` to `find` - Add `--poetry-executable` / `PET_POETRY_EXECUTABLE` to `find` - Add `--environment-directories` / `PET_ENVIRONMENT_DIRECTORIES` (comma-delimited) to `find` - Add `PET_CACHE_DIRECTORY` env var fallback to existing `--cache-directory` on both `find` and `resolve` - Wire new options through `FindOptions` → `create_config()` → `Configuration` - Pass user-provided conda/poetry executables to `find_and_report_missing_envs` (previously hardcoded to `None`) - Enable clap `env` feature in Cargo.toml Fixes #353
1 parent a7fb3b8 commit e364131

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

crates/pet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pet-uv = { path = "../pet-uv" }
4343
log = "0.4.21"
4444
tracing = "0.1"
4545
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
46-
clap = { version = "4.5.4", features = ["derive", "cargo"] }
46+
clap = { version = "4.5.4", features = ["derive", "cargo", "env"] }
4747
serde = { version = "1.0.152", features = ["derive"] }
4848
serde_json = "1.0.93"
4949
env_logger = "0.10.2"

crates/pet/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub struct FindOptions {
7575
pub cache_directory: Option<PathBuf>,
7676
pub kind: Option<PythonEnvironmentKind>,
7777
pub json: bool,
78+
pub conda_executable: Option<PathBuf>,
79+
pub pipenv_executable: Option<PathBuf>,
80+
pub poetry_executable: Option<PathBuf>,
81+
pub environment_directories: Option<Vec<PathBuf>>,
7882
}
7983

8084
pub fn find_and_report_envs_stdio(options: FindOptions) {
@@ -161,6 +165,14 @@ fn create_config(options: &FindOptions) -> Configuration {
161165
.collect(),
162166
);
163167

168+
config.conda_executable = options.conda_executable.clone();
169+
config.pipenv_executable = options.pipenv_executable.clone();
170+
config.poetry_executable = options.poetry_executable.clone();
171+
config.environment_directories = options
172+
.environment_directories
173+
.clone()
174+
.map(|dirs| dirs.into_iter().filter(|p| p.is_dir()).collect());
175+
164176
config
165177
}
166178

@@ -185,8 +197,10 @@ fn find_envs(
185197
// By now all conda envs have been found
186198
// Spawn conda
187199
// & see if we can find more environments by spawning conda.
188-
let _ = conda_locator.find_and_report_missing_envs(&reporter, None);
189-
let _ = poetry_locator.find_and_report_missing_envs(&reporter, None);
200+
let _ =
201+
conda_locator.find_and_report_missing_envs(&reporter, options.conda_executable.clone());
202+
let _ = poetry_locator
203+
.find_and_report_missing_envs(&reporter, options.poetry_executable.clone());
190204
}
191205

192206
if options.print_summary {
@@ -292,8 +306,10 @@ fn find_envs_json(
292306

293307
find_and_report_envs(&reporter, config, locators, environment, search_scope);
294308
if options.report_missing {
295-
let _ = conda_locator.find_and_report_missing_envs(&reporter, None);
296-
let _ = poetry_locator.find_and_report_missing_envs(&reporter, None);
309+
let _ =
310+
conda_locator.find_and_report_missing_envs(&reporter, options.conda_executable.clone());
311+
let _ = poetry_locator
312+
.find_and_report_missing_envs(&reporter, options.poetry_executable.clone());
297313
}
298314

299315
let managers = collect_reporter

crates/pet/src/main.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum Commands {
3333
list: bool,
3434

3535
/// Directory to cache the environment information after spawning Python.
36-
#[arg(short, long)]
36+
#[arg(short, long, env = "PET_CACHE_DIRECTORY")]
3737
cache_directory: Option<PathBuf>,
3838

3939
/// Display verbose output (defaults to warnings).
@@ -57,6 +57,23 @@ enum Commands {
5757
/// Output results as JSON.
5858
#[arg(short, long)]
5959
json: bool,
60+
61+
/// Path to the conda or mamba executable.
62+
#[arg(long, env = "PET_CONDA_EXECUTABLE")]
63+
conda_executable: Option<PathBuf>,
64+
65+
/// Path to the pipenv executable.
66+
#[arg(long, env = "PET_PIPENV_EXECUTABLE")]
67+
pipenv_executable: Option<PathBuf>,
68+
69+
/// Path to the poetry executable.
70+
#[arg(long, env = "PET_POETRY_EXECUTABLE")]
71+
poetry_executable: Option<PathBuf>,
72+
73+
/// Additional directories where virtual environments can be found.
74+
/// Use comma-separated values when setting via the environment variable.
75+
#[arg(long, env = "PET_ENVIRONMENT_DIRECTORIES", value_delimiter = ',')]
76+
environment_directories: Option<Vec<PathBuf>>,
6077
},
6178
/// Resolves & reports the details of the the environment to the standard output.
6279
Resolve {
@@ -65,7 +82,7 @@ enum Commands {
6582
executable: PathBuf,
6683

6784
/// Directory to cache the environment information after spawning Python.
68-
#[arg(short, long)]
85+
#[arg(short, long, env = "PET_CACHE_DIRECTORY")]
6986
cache_directory: Option<PathBuf>,
7087

7188
/// Whether to display verbose output (defaults to warnings).
@@ -92,6 +109,10 @@ fn main() {
92109
cache_directory: None,
93110
kind: None,
94111
json: false,
112+
conda_executable: None,
113+
pipenv_executable: None,
114+
poetry_executable: None,
115+
environment_directories: None,
95116
}) {
96117
Commands::Find {
97118
list,
@@ -102,6 +123,10 @@ fn main() {
102123
cache_directory,
103124
kind,
104125
json,
126+
conda_executable,
127+
pipenv_executable,
128+
poetry_executable,
129+
environment_directories,
105130
} => {
106131
let mut workspace_only = workspace;
107132
if search_paths.clone().is_some()
@@ -124,6 +149,10 @@ fn main() {
124149
cache_directory,
125150
kind,
126151
json,
152+
conda_executable,
153+
pipenv_executable,
154+
poetry_executable,
155+
environment_directories,
127156
});
128157
}
129158
Commands::Resolve {

0 commit comments

Comments
 (0)