Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pet-conda/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl CondaEnvironment {
}
}
// This is a root env.
let builder = PythonEnvironmentBuilder::new(PythonEnvironmentKind::Conda)
let builder = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Conda))
.executable(self.executable.clone())
.version(self.version.clone())
.prefix(Some(self.prefix.clone()))
Expand Down
14 changes: 7 additions & 7 deletions crates/pet-conda/tests/ci_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn detect_conda_root() {
.unwrap();
assert_eq!(env.prefix, conda_dir.clone().into());
assert_eq!(env.name, Some("base".into()));
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, Some(conda_dir.join("bin").join("python")));
assert_eq!(env.version, Some(get_version(&info.python_version)));

Expand Down Expand Up @@ -93,7 +93,7 @@ fn detect_conda_root_from_path() {

assert_eq!(env.prefix, conda_dir.clone().into());
assert_eq!(env.name, Some("base".into()));
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, Some(conda_dir.join("bin").join("python")));
assert_eq!(env.version, Some(get_version(&info.python_version)));
}
Expand Down Expand Up @@ -144,7 +144,7 @@ fn detect_new_conda_env() {
let prefix = conda_dir.clone().join("envs").join(env_name);
assert_eq!(env.prefix, prefix.clone().into());
assert_eq!(env.name, Some(env_name.into()));
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, prefix.join("bin").join("python").into());
assert!(
env.version.clone().unwrap_or_default().starts_with("3.10"),
Expand Down Expand Up @@ -193,7 +193,7 @@ fn detect_conda_env_from_path() {

assert_eq!(env.prefix, prefix.clone().into());
assert_eq!(env.name, Some(env_name.into()));
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, exe.clone().into());
assert!(
env.version.clone().unwrap_or_default().starts_with("3.10"),
Expand Down Expand Up @@ -245,7 +245,7 @@ fn detect_new_conda_env_without_python() {
let prefix = conda_dir.clone().join("envs").join(env_name);
assert_eq!(env.prefix, prefix.clone().into());
assert_eq!(env.name, Some(env_name.into()));
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable.is_none(), true);
assert_eq!(env.version.is_none(), true);

Expand Down Expand Up @@ -293,7 +293,7 @@ fn detect_new_conda_env_created_with_p_flag_without_python() {

assert_eq!(env.prefix, prefix.clone().into());
assert_eq!(env.name, None);
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable.is_none(), true);
assert_eq!(env.version.is_none(), true);

Expand Down Expand Up @@ -345,7 +345,7 @@ fn detect_new_conda_env_created_with_p_flag_with_python() {

assert_eq!(env.prefix, prefix.clone().into());
assert_eq!(env.name, None);
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, exe.into());
assert!(
env.version.clone().unwrap_or_default().starts_with("3.10"),
Expand Down
4 changes: 2 additions & 2 deletions crates/pet-conda/tests/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn find_conda_env_without_manager() {

assert_eq!(env.prefix, path.clone().into());
assert_eq!(env.arch, Architecture::X64.into());
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, path.join("bin").join("python").into());
assert_eq!(env.version, "3.12.2".to_string().into());
assert_eq!(env.manager, None);
Expand Down Expand Up @@ -75,7 +75,7 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() {

assert_eq!(env.prefix, path.clone().into());
assert_eq!(env.arch, Architecture::X64.into());
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
assert_eq!(env.executable, path.join("bin").join("python").into());
assert_eq!(env.version, "3.12.2".to_string().into());
assert_eq!(
Expand Down
37 changes: 8 additions & 29 deletions crates/pet-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl PartialOrd for PythonEnvironmentKind {

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
#[derive(Debug)]
#[derive(Debug, Default)]
// Python environment.
// Any item that has information is known to be accurate, if an item is missing it is unknown.
pub struct PythonEnvironment {
Expand All @@ -51,7 +51,7 @@ pub struct PythonEnvironment {
pub name: Option<String>,
// Python executable, can be empty in the case of conda envs that do not have Python installed in them.
pub executable: Option<PathBuf>,
pub kind: PythonEnvironmentKind,
pub kind: Option<PythonEnvironmentKind>,
pub version: Option<String>,
// SysPrefix for the environment.
pub prefix: Option<PathBuf>,
Expand Down Expand Up @@ -93,31 +93,10 @@ impl PartialOrd for PythonEnvironment {
}
}

impl Default for PythonEnvironment {
fn default() -> Self {
Self {
display_name: None,
name: None,
executable: None,
// Sometimes we might not know the env type.
// Lets never default these to System/Global or others as thats not true.
// Not knowing does not mean it is a system env.
kind: PythonEnvironmentKind::Unknown,
version: None,
prefix: None,
manager: None,
project: None,
arch: None,
symlinks: None,
search_path: None,
}
}
}

impl PythonEnvironment {
pub fn new(
executable: Option<PathBuf>,
kind: PythonEnvironmentKind,
kind: Option<PythonEnvironmentKind>,
prefix: Option<PathBuf>,
manager: Option<EnvManager>,
version: Option<String>,
Expand Down Expand Up @@ -205,7 +184,7 @@ pub struct PythonEnvironmentBuilder {
display_name: Option<String>,
name: Option<String>,
executable: Option<PathBuf>,
kind: PythonEnvironmentKind,
kind: Option<PythonEnvironmentKind>,
version: Option<String>,
prefix: Option<PathBuf>,
manager: Option<EnvManager>,
Expand All @@ -216,7 +195,7 @@ pub struct PythonEnvironmentBuilder {
}

impl PythonEnvironmentBuilder {
pub fn new(kind: PythonEnvironmentKind) -> Self {
pub fn new(kind: Option<PythonEnvironmentKind>) -> Self {
Self {
kind,
display_name: None,
Expand Down Expand Up @@ -359,11 +338,11 @@ impl PythonEnvironmentBuilder {
// Given a list of executables, return the one with the shortest path.
// The shortest path is the most likely to be most user friendly.
fn get_shortest_executable(
kind: &PythonEnvironmentKind,
kind: &Option<PythonEnvironmentKind>,
exes: &Option<Vec<PathBuf>>,
) -> Option<PathBuf> {
// For windows store, the exe should always be the one in the WindowsApps folder.
if *kind == PythonEnvironmentKind::WindowsStore {
if *kind == Some(PythonEnvironmentKind::WindowsStore) {
if let Some(exes) = exes {
if let Some(exe) = exes.iter().find(|e| {
e.to_string_lossy().contains("AppData")
Expand Down Expand Up @@ -398,7 +377,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {
Some(exe.clone())
} else if let Some(prefix) = &env.prefix {
// If this is a conda env without Python, then the exe will be prefix/bin/python
if env.kind == PythonEnvironmentKind::Conda {
if env.kind == Some(PythonEnvironmentKind::Conda) {
Some(prefix.join("bin").join(if cfg!(windows) {
"python.exe"
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-core/src/telemetry/inaccurate_python_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::python_environment::PythonEnvironmentKind;
/// And we will not report that as an inaccuracy.
pub struct InaccuratePythonEnvironmentInfo {
/// Python Env kind
pub kind: PythonEnvironmentKind,
pub kind: Option<PythonEnvironmentKind>,
/// Whether the actual exe is not what we expected.
pub invalid_executable: Option<bool>,
/// Whether the actual exe was not even in the list of symlinks that we expected.
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-homebrew/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn get_python_info(
symlinks.sort();
symlinks.dedup();

let env = PythonEnvironmentBuilder::new(PythonEnvironmentKind::Homebrew)
let env = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Homebrew))
.executable(Some(python_exe_from_bin_dir.to_path_buf()))
.version(version)
.prefix(get_prefix(resolved_exe))
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-linux-global-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn get_python_in_bin(env: &PythonEnv, is_64bit: bool) -> Option<PythonEnvironmen
symlinks.dedup();

Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::LinuxGlobal)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::LinuxGlobal))
.executable(Some(executable))
.version(env.version.clone())
.arch(if is_64bit {
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-mac-commandlinetools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Locator for MacCmdLineTools {
}

Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::MacCommandLineTools)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::MacCommandLineTools))
.executable(Some(env.executable.clone()))
.version(version)
.prefix(prefix)
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-mac-python-org/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Locator for MacPythonOrg {
symlinks.dedup();

Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::MacPythonOrg)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::MacPythonOrg))
.executable(Some(executable.clone()))
.version(Some(version))
.prefix(Some(prefix.to_path_buf()))
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-mac-xcode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Locator for MacXCode {
}

Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::MacXCode)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::MacXCode))
.executable(Some(env.executable.clone()))
.version(version)
.prefix(prefix)
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-pipenv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Locator for PipEnv {
}
}
Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::Pipenv)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Pipenv))
.executable(Some(env.executable.clone()))
.version(version)
.prefix(prefix)
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-poetry/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn create_poetry_env(
}
let version = version::from_creator_for_virtual_env(prefix);
Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::Poetry)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Poetry))
.executable(Some(executables[0].clone()))
.prefix(Some(prefix.clone()))
.version(version)
Expand Down
4 changes: 2 additions & 2 deletions crates/pet-pyenv/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn get_generic_python_environment(
};

Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::Pyenv)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Pyenv))
.executable(Some(executable.to_path_buf()))
.version(version)
.prefix(Some(path.to_path_buf()))
Expand All @@ -119,7 +119,7 @@ pub fn get_virtual_env_environment(
) -> Option<PythonEnvironment> {
let version = version::from_pyvenv_cfg(path)?;
Some(
PythonEnvironmentBuilder::new(PythonEnvironmentKind::PyenvVirtualEnv)
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::PyenvVirtualEnv))
.executable(Some(executable.to_path_buf()))
.version(Some(version))
.prefix(Some(path.to_path_buf()))
Expand Down
26 changes: 13 additions & 13 deletions crates/pet-pyenv/tests/pyenv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.9.9/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.9.9".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -178,7 +178,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])),
kind: PythonEnvironmentKind::PyenvVirtualEnv,
kind: Some(PythonEnvironmentKind::PyenvVirtualEnv),
version: Some("3.10.13".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -200,7 +200,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.12.1".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -222,7 +222,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.13-dev/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.13-dev".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -244,7 +244,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1a3/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.12.1a3".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -266,7 +266,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/nogil-3.9.10-1/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.9.10".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -288,7 +288,7 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/pypy3.9-7.3.15/bin/python",
])),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.9.18".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -308,7 +308,7 @@ fn find_pyenv_envs() {
project: None,
name: Some("base".to_string()),
executable: Some(conda_dir.join("bin").join("python")),
kind: PythonEnvironmentKind::Conda,
kind: Some(PythonEnvironmentKind::Conda),
version: Some("3.11.5".to_string()),
prefix: Some(conda_dir.clone()),
manager: Some(expected_conda_manager.clone()),
Expand All @@ -321,7 +321,7 @@ fn find_pyenv_envs() {
project: None,
name: Some("one".to_string()),
executable: Some(conda_dir.join("envs").join("one").join("python")),
kind: PythonEnvironmentKind::Conda,
kind: Some(PythonEnvironmentKind::Conda),
version: Some("3.11.1".to_string()),
prefix: Some(conda_dir.join("envs").join("one")),
manager: Some(expected_conda_manager.clone()),
Expand All @@ -334,7 +334,7 @@ fn find_pyenv_envs() {
project: None,
name: Some("two".to_string()),
executable: Some(conda_dir.join("envs").join("two").join("python")),
kind: PythonEnvironmentKind::Conda,
kind: Some(PythonEnvironmentKind::Conda),
version: Some("3.11.1".to_string()),
prefix: Some(conda_dir.join("envs").join("two")),
manager: Some(expected_conda_manager.clone()),
Expand Down Expand Up @@ -401,7 +401,7 @@ fn resolve_pyenv_environment() {
project: None,
name: None,
executable: Some(executable.clone()),
kind: PythonEnvironmentKind::Pyenv,
kind: Some(PythonEnvironmentKind::Pyenv),
version: Some("3.9.9".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand All @@ -420,7 +420,7 @@ fn resolve_pyenv_environment() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])),
kind: PythonEnvironmentKind::PyenvVirtualEnv,
kind: Some(PythonEnvironmentKind::PyenvVirtualEnv),
version: Some("3.10.13".to_string()),
prefix: Some(resolve_test_path(&[
home.to_str().unwrap(),
Expand Down Expand Up @@ -491,5 +491,5 @@ fn resolve_pyenv_environment() {
));

assert_eq!(result.is_some(), true);
assert_eq!(result.unwrap().kind, PythonEnvironmentKind::Conda);
assert_eq!(result.unwrap().kind, Some(PythonEnvironmentKind::Conda));
}
2 changes: 1 addition & 1 deletion crates/pet-reporter/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {
Some(exe.clone())
} else if let Some(prefix) = &env.prefix {
// If this is a conda env without Python, then the exe will be prefix/bin/python
if env.kind == PythonEnvironmentKind::Conda {
if env.kind == Some(PythonEnvironmentKind::Conda) {
Some(prefix.join("bin").join(if cfg!(windows) {
"python.exe"
} else {
Expand Down
Loading