-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: pixi project export conda
to export project to conda environment.yml's
#1427
Changes from 2 commits
abcc0de
ffb776b
6243e53
4b10624
763bcd6
47a9c69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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()) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise the following channel would be exported as channels = ["https://fast.prefix.dev/conda-forge"] |
||||||||||
.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(()) | ||||||||||
} |
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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good that you prepared for future options! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not gonna promise that I'm gonna be the one to write all of them though! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dare you 😝 |
||||||
#[clap(alias = "c")] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Conda(conda::Args), | ||||||
} | ||||||
|
||||||
/// Commands 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(()) | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,22 @@ use itertools::Itertools; | |
use miette::IntoDiagnostic; | ||
use rattler_conda_types::ParseStrictness::Lenient; | ||
use rattler_conda_types::{Channel, MatchSpec}; | ||
use serde::Deserialize; | ||
use serde::{Deserialize, Serialize}; | ||
use std::str::FromStr; | ||
use std::{io::BufRead, path::Path, sync::Arc}; | ||
|
||
use crate::config::Config; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct CondaEnvFile { | ||
#[serde(default)] | ||
name: Option<String>, | ||
pub name: Option<String>, | ||
#[serde(default)] | ||
channels: Vec<String>, | ||
dependencies: Vec<CondaEnvDep>, | ||
pub channels: Vec<String>, | ||
pub dependencies: Vec<CondaEnvDep>, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
#[serde(untagged)] | ||
pub enum CondaEnvDep { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you implement a You already have the So it should be easy to create a let spec = MatchSpec::from_nameless(nameless_spec, Some(package_name)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm able to quickly get some of the specs to render ok with For pixi's name: pixi-default-osx-arm64
channels:
- conda-forge
dependencies:
- pre-commit~=3.3.0
- rust~=1.77.0
- openssl3.*
- pkg-config0.29.*
- git2.42.0.*
- cffconvert>=2.0.0,<2.1
- tbump>=6.9.0,<6.10 I haven't tried writing an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without an name: pixi-default-osx-arm64
channels:
- conda-forge
dependencies:
- pre-commit ~=3.3.0
- rust ~=1.77.0
- openssl 3.*
- pkg-config 0.29.*
- git 2.42.0.*
- cffconvert >=2.0.0,<2.1
- tbump >=6.9.0,<6.10 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, if there is a space and no leading operator, does that get interpreted as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I believe so |
||
Conda(String), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To align with other cli's.