-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffcbf3f
commit 82c89df
Showing
12 changed files
with
167 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ pub enum LocatorKind { | |
MacPythonOrg, | ||
MacXCode, | ||
PipEnv, | ||
Pixi, | ||
Poetry, | ||
PyEnv, | ||
Venv, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "pet-pixi" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[target.'cfg(target_os = "windows")'.dependencies] | ||
msvc_spectre_libs = { version = "0.1.1", features = ["error"] } | ||
|
||
[dependencies] | ||
pet-conda = { path = "../pet-conda" } | ||
pet-core = { path = "../pet-core" } | ||
pet-python-utils = { path = "../pet-python-utils" } | ||
log = "0.4.21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Pixi | ||
|
||
## Notes | ||
|
||
- Pixi environments are detected by: | ||
- Searching for Python interpreters in `.pixi/envs` subdirectories within workspace folders | ||
- Checking for a `conda-meta/pixi` file in potential Pixi environment directories (`.pixi/envs/{env_name}`) | ||
- Determining the version of the Python interpreter from the `conda-meta/python-{version}.json` file | ||
|
||
This process ensures fast detection without spawning processes. | ||
Note that the Pixi locator should run before Conda since Conda could incorrectly identify Pixi environments as Conda environments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
use pet_conda::package::{CondaPackageInfo, Package}; | ||
use pet_core::{ | ||
env::PythonEnv, | ||
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentKind}, | ||
reporter::Reporter, | ||
Locator, LocatorKind, | ||
}; | ||
use pet_python_utils::executable::find_executables; | ||
|
||
pub fn is_pixi_env(path: &Path) -> bool { | ||
path.join("conda-meta").join("pixi").is_file() | ||
} | ||
|
||
fn get_pixi_prefix(env: &PythonEnv) -> Option<PathBuf> { | ||
env.prefix.clone().or_else(|| { | ||
env.executable.parent().and_then(|parent_dir| { | ||
if is_pixi_env(parent_dir) { | ||
Some(parent_dir.to_path_buf()) | ||
} else if parent_dir.ends_with("bin") || parent_dir.ends_with("Scripts") { | ||
parent_dir | ||
.parent() | ||
.filter(|parent| is_pixi_env(parent)) | ||
.map(|parent| parent.to_path_buf()) | ||
} else { | ||
None | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
pub struct Pixi {} | ||
|
||
impl Pixi { | ||
pub fn new() -> Pixi { | ||
Pixi {} | ||
} | ||
} | ||
impl Default for Pixi { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl Locator for Pixi { | ||
fn get_kind(&self) -> LocatorKind { | ||
LocatorKind::Pixi | ||
} | ||
fn supported_categories(&self) -> Vec<PythonEnvironmentKind> { | ||
vec![PythonEnvironmentKind::Pixi] | ||
} | ||
|
||
fn try_from(&self, env: &PythonEnv) -> Option<PythonEnvironment> { | ||
get_pixi_prefix(env).and_then(|prefix| { | ||
if !is_pixi_env(&prefix) { | ||
return None; | ||
} | ||
|
||
let name = prefix | ||
.file_name() | ||
.and_then(|name| name.to_str()) | ||
.unwrap_or_default() | ||
.to_string(); | ||
|
||
let symlinks = find_executables(&prefix); | ||
|
||
let version = CondaPackageInfo::from(&prefix, &Package::Python) | ||
.map(|package_info| package_info.version); | ||
|
||
Some( | ||
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Pixi)) | ||
.executable(Some(env.executable.clone())) | ||
.name(Some(name)) | ||
.prefix(Some(prefix)) | ||
.symlinks(Some(symlinks)) | ||
.version(version) | ||
.build(), | ||
) | ||
}) | ||
} | ||
|
||
fn find(&self, _reporter: &dyn Reporter) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters