Skip to content

Commit d24cd7b

Browse files
authored
Add support for Poetry along with some fixes to PyEnv, Conda (#44)
1 parent dc6bde9 commit d24cd7b

File tree

40 files changed

+1760
-138
lines changed

40 files changed

+1760
-138
lines changed

Cargo.lock

Lines changed: 169 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pet-conda/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ log = "0.4.21"
1818
regex = "1.10.4"
1919
pet-reporter = { path = "../pet-reporter" }
2020

21-
[dev-dependencies]
22-
2321

2422
[features]
2523
ci = []

crates/pet-conda/src/conda_rc.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
7272
// Search paths documented here
7373
// https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#searching-for-condarc
7474
fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
75+
use crate::utils::change_root_of_path;
76+
7577
let mut search_paths: Vec<PathBuf> = [
7678
"/etc/conda/.condarc",
7779
"/etc/conda/condarc",
@@ -82,16 +84,7 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
8284
]
8385
.iter()
8486
.map(PathBuf::from)
85-
.map(|p| {
86-
// This only applies in tests.
87-
// We need this, as the root folder cannot be mocked.
88-
if let Some(ref root) = env_vars.root {
89-
// Strip the first `/` (this path is only for testing purposes)
90-
root.join(&p.to_string_lossy()[1..])
91-
} else {
92-
p
93-
}
94-
})
87+
.map(|p| change_root_of_path(&p, &env_vars.root))
9588
.collect();
9689

9790
if let Some(ref conda_root) = env_vars.conda_root {

crates/pet-conda/src/env_variables.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use pet_core::os_environment::Environment;
1010
// Lets be explicit, this way we never miss a value (in Windows or Unix).
1111
pub struct EnvVariables {
1212
pub home: Option<PathBuf>,
13+
/// Only used in tests, None in production.
1314
pub root: Option<PathBuf>,
1415
pub path: Option<String>,
1516
pub userprofile: Option<String>,

crates/pet-conda/src/utils.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use std::{fs, path::Path};
4+
use std::{
5+
fs,
6+
path::{Path, PathBuf},
7+
};
58

69
// conda-meta must exist as this contains a mandatory `history` file.
710
pub fn is_conda_install(path: &Path) -> bool {
@@ -17,3 +20,24 @@ pub fn is_conda_env(path: &Path) -> bool {
1720
false
1821
}
1922
}
23+
24+
/// Only used in tests, noop in production.
25+
///
26+
/// Change the root of the path to a new root.
27+
/// Lets assume some config file is located in the root directory /etc/config/config.toml.
28+
/// We cannot test this unless we create such a file on the root of the filesystem.
29+
/// Thats very risky and not recommended (ideally we want to create stuff in separate test folders).
30+
/// The solution is to change the root of the path to a test folder.
31+
pub fn change_root_of_path(path: &Path, new_root: &Option<PathBuf>) -> PathBuf {
32+
if cfg!(windows) {
33+
return path.to_path_buf();
34+
}
35+
if let Some(new_root) = new_root {
36+
// This only applies in tests.
37+
// We need this, as the root folder cannot be mocked.
38+
// Strip the first `/` (this path is only for testing purposes)
39+
new_root.join(&path.to_string_lossy()[1..])
40+
} else {
41+
path.to_path_buf()
42+
}
43+
}

crates/pet-core/src/manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::path::PathBuf;
99
#[derive(Debug, Hash)]
1010
pub enum EnvManagerType {
1111
Conda,
12+
Poetry,
1213
Pyenv,
1314
}
1415

crates/pet-core/src/os_environment.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use pet_fs::path::norm_case;
77

88
pub trait Environment {
99
fn get_user_home(&self) -> Option<PathBuf>;
10-
/**
11-
* Only used in tests, this is the root `/`.
12-
*/
10+
/// Only used in tests, None in production.
1311
#[allow(dead_code)]
1412
fn get_root(&self) -> Option<PathBuf>;
1513
fn get_env_var(&self, key: String) -> Option<String>;

crates/pet-core/src/python_environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub enum PythonEnvironmentCategory {
1818
Pyenv, // Relates to Python installations in pyenv that are from Python org.
1919
GlobalPaths, // Python found in global locations like PATH, /usr/bin etc.
2020
PyenvVirtualEnv, // Pyenv virtualenvs.
21-
PyenvOther, // Such as pyston, stackless, nogil, etc.
2221
Pipenv,
22+
Poetry,
2323
System,
2424
MacPythonOrg,
2525
MacCommandLineTools,

0 commit comments

Comments
 (0)