forked from prefix-dev/pixi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an export command group, and a subcommand for exporting in Conda environment.yml files. Currently it just exports the direct dependency names, but I could see adding flags to include all locked dependencies. It also currently does not export the versions, but that could also be a flag to select if it should export the specs as in the manifest, or as locked. works on prefix-dev#800
- Loading branch information
Showing
4 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
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,80 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
|
||
use itertools::Itertools; | ||
use miette::IntoDiagnostic; | ||
use rattler_conda_types::Platform; | ||
|
||
use crate::utils::conda_environment_file::{CondaEnvDep, CondaEnvFile}; | ||
use crate::{HasFeatures, Project}; | ||
|
||
/// Exports a projects dependencies as an environment.yml | ||
/// | ||
/// The environment is printed to standard out | ||
#[derive(Debug, Parser)] | ||
#[clap(arg_required_else_help = false)] | ||
pub struct Args { | ||
/// The platform to list packages for. Defaults to the current platform. | ||
#[arg(long)] | ||
pub platform: Option<Platform>, | ||
|
||
/// The path to 'pixi.toml' or 'pyproject.toml' | ||
#[arg(long)] | ||
pub manifest_path: Option<PathBuf>, | ||
|
||
/// The environment to list packages for. Defaults to the default environment. | ||
#[arg(short, long)] | ||
pub environment: Option<String>, | ||
|
||
/// Name for environment | ||
#[arg(short, long)] | ||
pub name: Option<String>, | ||
} | ||
|
||
pub async fn execute(args: Args) -> miette::Result<()> { | ||
let project = Project::load_or_else_discover(args.manifest_path.as_deref())?; | ||
let environment = project.environment_from_name_or_env_var(args.environment)?; | ||
|
||
let platform = args.platform.unwrap_or_else(|| environment.best_platform()); | ||
|
||
let name = match args.name { | ||
Some(arg_name) => arg_name, | ||
None => format!("{}-{}-{}", project.name(), environment.name(), platform), | ||
}; | ||
|
||
let channels = environment | ||
.channels() | ||
.into_iter() | ||
.map(|channel| channel.name().to_string()) | ||
.collect_vec(); | ||
|
||
let mut dependencies = environment | ||
.dependencies(None, Some(platform)) | ||
.into_specs() | ||
.map(|(name, _spec)| CondaEnvDep::Conda(name.as_source().to_string())) | ||
.collect_vec(); | ||
|
||
let pypi_dependencies = environment | ||
.pypi_dependencies(Some(platform)) | ||
.into_specs() | ||
.map(|(name, _spec)| name.as_source().to_string()) | ||
.collect_vec(); | ||
|
||
if !pypi_dependencies.is_empty() { | ||
dependencies.push(CondaEnvDep::Pip { | ||
pip: pypi_dependencies, | ||
}); | ||
} | ||
|
||
let env_file = CondaEnvFile { | ||
name: Some(name), | ||
channels, | ||
dependencies, | ||
}; | ||
|
||
let env_string = serde_yaml::to_string(&env_file).into_diagnostic()?; | ||
println!("{}", env_string); | ||
|
||
Ok(()) | ||
} |
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 clap::Parser; | ||
|
||
mod conda; | ||
|
||
#[derive(Debug, Parser)] | ||
pub enum Command { | ||
#[clap(alias = "c")] | ||
Conda(conda::Args), | ||
} | ||
|
||
/// Subcommand for exporting dependencies to additional formats | ||
#[derive(Debug, Parser)] | ||
pub struct Args { | ||
#[command(subcommand)] | ||
command: Command, | ||
} | ||
|
||
pub async fn execute(cmd: Args) -> miette::Result<()> { | ||
match cmd.command { | ||
Command::Conda(args) => conda::execute(args).await?, | ||
}; | ||
Ok(()) | ||
} |
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