-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial scaffolding for environment managers (pip, pipx, uv).
- Loading branch information
1 parent
1ed6c68
commit c8da105
Showing
11 changed files
with
211 additions
and
42 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
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,23 @@ | ||
use std::path::PathBuf; | ||
|
||
/// Specifies the behavior of the Processing Engine. | ||
/// Currently used to determine the plugin directory and which tooling to use to initialize python, | ||
/// but will expand for other settings, such as error behavior. | ||
#[derive(Debug, clap::Parser, Clone)] | ||
pub struct ProcessingEngineConfig { | ||
#[clap(long = "plugin-dir")] | ||
pub plugin_dir: Option<PathBuf>, | ||
#[clap(long = "virtual-env-location", env = "VIRTUAL_ENV")] | ||
pub virtual_env_location: Option<PathBuf>, | ||
|
||
#[clap(long = "package-manager", default_value = "pip")] | ||
pub package_manager: PackageManager, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)] | ||
pub enum PackageManager { | ||
#[default] | ||
Pip, | ||
Pipx, | ||
UV, | ||
} |
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,95 @@ | ||
use crate::environment::PluginEnvironmentError::PluginEnvironmentDisabled; | ||
use std::fmt::Debug; | ||
use std::process::Command; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum PluginEnvironmentError { | ||
#[error("Package manager not available: {0}")] | ||
PackageManagerNotFound(String), | ||
#[error("External call failed: {0}")] | ||
InstallationFailed(#[from] std::io::Error), | ||
#[error("Plugin environment management is disabled")] | ||
PluginEnvironmentDisabled, | ||
} | ||
|
||
pub trait PythonEnvironmentManager: Debug + Send + Sync + 'static { | ||
fn install_package(&self, package_name: String) -> Result<(), PluginEnvironmentError>; | ||
|
||
fn install_requirements(&self, requirements_path: String) | ||
-> Result<(), PluginEnvironmentError>; | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct UVManager; | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct PipManager; | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct PipxManager; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct DisabledManager; | ||
|
||
impl PythonEnvironmentManager for UVManager { | ||
fn install_package(&self, package: String) -> Result<(), PluginEnvironmentError> { | ||
Command::new("uv") | ||
.args(["pip", "install", &package]) | ||
.output()?; | ||
Ok(()) | ||
} | ||
|
||
fn install_requirements( | ||
&self, | ||
requirements_path: String, | ||
) -> Result<(), PluginEnvironmentError> { | ||
Command::new("uv") | ||
.args(["pip", "install", "-r", &requirements_path]) | ||
.output()?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl PythonEnvironmentManager for PipManager { | ||
fn install_package(&self, package: String) -> Result<(), PluginEnvironmentError> { | ||
Command::new("pip").args(["install", &package]).output()?; | ||
Ok(()) | ||
} | ||
fn install_requirements( | ||
&self, | ||
requirements_path: String, | ||
) -> Result<(), PluginEnvironmentError> { | ||
Command::new("pip") | ||
.args(["install", "-r", &requirements_path]) | ||
.output()?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl PythonEnvironmentManager for PipxManager { | ||
fn install_package(&self, package: String) -> Result<(), PluginEnvironmentError> { | ||
Command::new("pipx").args(["install", &package]).output()?; | ||
Ok(()) | ||
} | ||
fn install_requirements( | ||
&self, | ||
requirements_path: String, | ||
) -> Result<(), PluginEnvironmentError> { | ||
Command::new("pipx") | ||
.args(["install", "-r", &requirements_path]) | ||
.output()?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl PythonEnvironmentManager for DisabledManager { | ||
fn install_package(&self, _package: String) -> Result<(), PluginEnvironmentError> { | ||
Err(PluginEnvironmentDisabled) | ||
} | ||
|
||
fn install_requirements( | ||
&self, | ||
_requirements_path: String, | ||
) -> Result<(), PluginEnvironmentError> { | ||
Err(PluginEnvironmentDisabled) | ||
} | ||
} |
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
Oops, something went wrong.