Skip to content

Add support for Poetry along with some fixes to PyEnv, Conda #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 24, 2024
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
182 changes: 169 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/pet-conda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ log = "0.4.21"
regex = "1.10.4"
pet-reporter = { path = "../pet-reporter" }

[dev-dependencies]


[features]
ci = []
13 changes: 3 additions & 10 deletions crates/pet-conda/src/conda_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
// Search paths documented here
// https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#searching-for-condarc
fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
use crate::utils::change_root_of_path;

let mut search_paths: Vec<PathBuf> = [
"/etc/conda/.condarc",
"/etc/conda/condarc",
Expand All @@ -82,16 +84,7 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
]
.iter()
.map(PathBuf::from)
.map(|p| {
// This only applies in tests.
// We need this, as the root folder cannot be mocked.
if let Some(ref root) = env_vars.root {
// Strip the first `/` (this path is only for testing purposes)
root.join(&p.to_string_lossy()[1..])
} else {
p
}
})
.map(|p| change_root_of_path(&p, &env_vars.root))
.collect();

if let Some(ref conda_root) = env_vars.conda_root {
Expand Down
1 change: 1 addition & 0 deletions crates/pet-conda/src/env_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use pet_core::os_environment::Environment;
// Lets be explicit, this way we never miss a value (in Windows or Unix).
pub struct EnvVariables {
pub home: Option<PathBuf>,
/// Only used in tests, None in production.
pub root: Option<PathBuf>,
pub path: Option<String>,
pub userprofile: Option<String>,
Expand Down
26 changes: 25 additions & 1 deletion crates/pet-conda/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use std::{fs, path::Path};
use std::{
fs,
path::{Path, PathBuf},
};

// conda-meta must exist as this contains a mandatory `history` file.
pub fn is_conda_install(path: &Path) -> bool {
Expand All @@ -17,3 +20,24 @@ pub fn is_conda_env(path: &Path) -> bool {
false
}
}

/// Only used in tests, noop in production.
///
/// Change the root of the path to a new root.
/// Lets assume some config file is located in the root directory /etc/config/config.toml.
/// We cannot test this unless we create such a file on the root of the filesystem.
/// Thats very risky and not recommended (ideally we want to create stuff in separate test folders).
/// The solution is to change the root of the path to a test folder.
pub fn change_root_of_path(path: &Path, new_root: &Option<PathBuf>) -> PathBuf {
if cfg!(windows) {
return path.to_path_buf();
}
if let Some(new_root) = new_root {
// This only applies in tests.
// We need this, as the root folder cannot be mocked.
// Strip the first `/` (this path is only for testing purposes)
new_root.join(&path.to_string_lossy()[1..])
} else {
path.to_path_buf()
}
}
1 change: 1 addition & 0 deletions crates/pet-core/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::PathBuf;
#[derive(Debug, Hash)]
pub enum EnvManagerType {
Conda,
Poetry,
Pyenv,
}

Expand Down
4 changes: 1 addition & 3 deletions crates/pet-core/src/os_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use pet_fs::path::norm_case;

pub trait Environment {
fn get_user_home(&self) -> Option<PathBuf>;
/**
* Only used in tests, this is the root `/`.
*/
/// Only used in tests, None in production.
#[allow(dead_code)]
fn get_root(&self) -> Option<PathBuf>;
fn get_env_var(&self, key: String) -> Option<String>;
Expand Down
2 changes: 1 addition & 1 deletion crates/pet-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub enum PythonEnvironmentCategory {
Pyenv, // Relates to Python installations in pyenv that are from Python org.
GlobalPaths, // Python found in global locations like PATH, /usr/bin etc.
PyenvVirtualEnv, // Pyenv virtualenvs.
PyenvOther, // Such as pyston, stackless, nogil, etc.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, pyston, stackless, etc will be just marked as pyenv

Pipenv,
Poetry,
System,
MacPythonOrg,
MacCommandLineTools,
Expand Down
Loading
Loading