Skip to content
Open
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
71 changes: 49 additions & 22 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pixi_url = { path = "crates/pixi_url" }
pixi_utils = { path = "crates/pixi_utils", default-features = false }
pixi_uv_context = { path = "crates/pixi_uv_context" }
pixi_uv_conversions = { path = "crates/pixi_uv_conversions" }
pixi_uv_reporter = { path = "crates/pixi_uv_reporter" }
pixi_variant = { path = "crates/pixi_variant" }
pypi_mapping = { path = "crates/pypi_mapping" }
pypi_modifiers = { path = "crates/pypi_modifiers" }
Expand Down
19 changes: 19 additions & 0 deletions crates/pixi_cli/src/global/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ use crate::global::global_specs::GlobalSpecs;
use crate::global::revert_environment_after_error;

use clap::Parser;
use miette::IntoDiagnostic;
use pixi_config::{Config, ConfigCli};
use pixi_global::project::GlobalSpec;
use pixi_global::{EnvironmentName, Mapping, Project, StateChange, StateChanges};
use pixi_pypi_spec::{PixiPypiSpec, PypiPackageName};

/// Adds dependencies to an environment
///
/// Example:
///
/// - `pixi global add --environment python numpy`
/// - `pixi global add --environment my_env pytest pytest-cov --expose pytest=pytest`
/// - `pixi global add --environment python --pypi httpx`
#[derive(Parser, Debug, Clone)]
#[clap(arg_required_else_help = true, verbatim_doc_comment)]
pub struct Args {
Expand All @@ -29,6 +32,11 @@ pub struct Args {
#[arg(long)]
expose: Vec<Mapping>,

/// Add a PyPI package to the environment, in PEP 508 format.
/// The environment must contain a python interpreter in its dependencies.
#[arg(long)]
pypi: Vec<pep508_rs::Requirement>,

#[clap(flatten)]
config: ConfigCli,
}
Expand All @@ -49,6 +57,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
async fn apply_changes(
env_name: &EnvironmentName,
specs: &[GlobalSpec],
pypi_requirements: &[pep508_rs::Requirement],
expose: &[Mapping],
project: &mut Project,
) -> miette::Result<StateChanges> {
Expand All @@ -59,6 +68,15 @@ pub async fn execute(args: Args) -> miette::Result<()> {
project.manifest.add_dependency(env_name, spec)?;
}

// Add PyPI requirements to the manifest
for requirement in pypi_requirements {
let name = PypiPackageName::from_normalized(requirement.name.clone());
let spec = PixiPypiSpec::try_from(requirement.clone()).into_diagnostic()?;
project
.manifest
.add_pypi_dependency(env_name, &name, &spec)?;
}

// Add expose mappings to the manifest
for mapping in expose {
project.manifest.add_exposed_mapping(env_name, mapping)?;
Expand Down Expand Up @@ -116,6 +134,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
match apply_changes(
&args.environment,
&specs,
args.pypi.as_slice(),
args.expose.as_slice(),
&mut project_modified,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_cli/src/global/global_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::has_specs::HasSpecs;
#[derive(Parser, Debug, Default, Clone)]
pub struct GlobalSpecs {
/// The dependency as names, conda MatchSpecs
#[arg(num_args = 1.., required_unless_present_any = ["git", "path"], value_name = "PACKAGE")]
#[arg(num_args = 1.., required_unless_present_any = ["git", "path", "pypi"], value_name = "PACKAGE")]
pub specs: Vec<String>,

/// The git url, e.g. `https://github.com/user/repo.git`
Expand Down
24 changes: 23 additions & 1 deletion crates/pixi_cli/src/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use indexmap::IndexMap;
use clap::Parser;
use fancy_display::FancyDisplay;
use itertools::Itertools;
use miette::Report;
use miette::{IntoDiagnostic, Report};
use pixi_pypi_spec::{PixiPypiSpec, PypiPackageName};
use rattler_conda_types::{MatchSpec, NamedChannelOrUrl, Platform};

use crate::global::{global_specs::GlobalSpecs, revert_environment_after_error};
Expand All @@ -25,6 +26,7 @@ use pixi_global::{
/// - `pixi global install jupyter --with polars`
/// - `pixi global install --expose python3.8=python python=3.8`
/// - `pixi global install --environment science --expose jupyter --expose ipython jupyter ipython polars`
/// - `pixi global install python --pypi httpx --pypi "flask>=2"`
#[derive(Parser, Debug, Clone, Default)]
#[clap(arg_required_else_help = true, verbatim_doc_comment)]
pub struct Args {
Expand Down Expand Up @@ -64,6 +66,11 @@ pub struct Args {
#[arg(long)]
with: Vec<MatchSpec>,

/// Add a PyPI package to the environment, in PEP 508 format.
/// The environment must contain a python interpreter in its dependencies.
#[arg(long)]
pypi: Vec<pep508_rs::Requirement>,

#[clap(flatten)]
config: ConfigCli,

Expand Down Expand Up @@ -121,6 +128,12 @@ pub async fn execute(args: Args) -> miette::Result<()> {
miette::bail!("Can't add packages with `--with` for more than one environment");
}

if !args.pypi.is_empty() && env_to_specs.len() != 1 {
miette::bail!(
"`--pypi` requires exactly one environment; use `--environment` to specify it"
);
}

let mut env_changes = EnvChanges::default();
let mut last_updated_project = project_original;
let mut errors: Vec<(EnvironmentName, Report)> = Vec::new();
Expand Down Expand Up @@ -224,6 +237,15 @@ async fn setup_environment(
project.manifest.add_dependency(env_name, spec)?;
}

// Add the PyPI dependencies to the environment
for requirement in &args.pypi {
let name = PypiPackageName::from_normalized(requirement.name.clone());
let spec = PixiPypiSpec::try_from(requirement.clone()).into_diagnostic()?;
project
.manifest
.add_pypi_dependency(env_name, &name, &spec)?;
}

if !args.expose.is_empty() {
project.manifest.remove_all_exposed_mappings(env_name)?;
// Only add the exposed mappings that were requested
Expand Down
Loading
Loading