Skip to content

Commit

Permalink
Apply pixi tweaks needed for magic
Browse files Browse the repository at this point in the history
  • Loading branch information
frspokan authored and zbowling committed Feb 13, 2025
1 parent fc3e1a8 commit f7ff38d
Show file tree
Hide file tree
Showing 16 changed files with 1,671 additions and 702 deletions.
2 changes: 2 additions & 0 deletions crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub static DEFAULT_CHANNELS: LazyLock<Vec<NamedChannelOrUrl>> =
}
});

pub const MOJOPROJECT_MANIFEST: &str = "mojoproject.toml";

pub const CONDA_INSTALLER: &str = "conda";

pub const ONE_TIME_MESSAGES_DIR: &str = "one-time-messages";
Expand Down
10 changes: 8 additions & 2 deletions crates/pixi_manifest/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Manifests {
// Parse the manifest as a workspace based on the type of manifest.
let manifest_dir = provenance.path.parent().expect("a file must have a parent");
let parsed_manifests = match provenance.kind {
ManifestKind::Pixi => TomlManifest::deserialize(&mut toml)
ManifestKind::Pixi | ManifestKind::MojoProject => TomlManifest::deserialize(&mut toml)
.map_err(TomlError::from)
.and_then(|manifest| {
manifest.into_workspace_manifest(
Expand Down Expand Up @@ -344,7 +344,7 @@ impl WorkspaceDiscoverer {
// Parse the workspace manifest.
let manifest_dir = provenance.path.parent().expect("a file must have a parent");
let parsed_manifest = match provenance.kind {
ManifestKind::Pixi => {
ManifestKind::Pixi | ManifestKind::MojoProject => {
if closest_package_manifest.is_some() && toml.pointer("/workspace").is_none() {
// The manifest does not contain a workspace section, and we don't care
// about the package section.
Expand Down Expand Up @@ -493,13 +493,19 @@ impl WorkspaceDiscoverer {
fn provenance_from_dir(dir: &Path) -> Option<ManifestProvenance> {
let pixi_toml_path = dir.join(consts::PROJECT_MANIFEST);
let pyproject_toml_path = dir.join(consts::PYPROJECT_MANIFEST);
let mojoproject_toml_path = dir.join(consts::MOJOPROJECT_MANIFEST);
if pixi_toml_path.is_file() {
Some(ManifestProvenance::new(pixi_toml_path, ManifestKind::Pixi))
} else if pyproject_toml_path.is_file() {
Some(ManifestProvenance::new(
pyproject_toml_path,
ManifestKind::Pyproject,
))
} else if mojoproject_toml_path.is_file() {
Some(ManifestProvenance::new(
mojoproject_toml_path,
ManifestKind::Pixi,
))
} else {
None
}
Expand Down
9 changes: 9 additions & 0 deletions crates/pixi_manifest/src/manifests/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ use crate::{
pub enum ManifestDocument {
PyProjectToml(TomlDocument),
PixiToml(TomlDocument),
MojoProjectToml(TomlDocument),
}

impl fmt::Display for ManifestDocument {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ManifestDocument::PyProjectToml(document) => write!(f, "{}", document),
ManifestDocument::PixiToml(document) => write!(f, "{}", document),
ManifestDocument::MojoProjectToml(document) => write!(f, "{}", document),
}
}
}
Expand Down Expand Up @@ -99,6 +101,7 @@ impl ManifestDocument {
let document = match self {
ManifestDocument::PyProjectToml(document) => document,
ManifestDocument::PixiToml(document) => document,
ManifestDocument::MojoProjectToml(document) => document,
};
document
.to_string()
Expand Down Expand Up @@ -131,6 +134,7 @@ impl ManifestDocument {
match provenance.kind {
ManifestKind::Pyproject => Ok(ManifestDocument::PyProjectToml(toml)),
ManifestKind::Pixi => Ok(ManifestDocument::PixiToml(toml)),
ManifestKind::MojoProject => Ok(ManifestDocument::MojoProjectToml(toml)),
}
}

Expand All @@ -139,6 +143,7 @@ impl ManifestDocument {
match self {
ManifestDocument::PyProjectToml(_) => ManifestKind::Pyproject,
ManifestDocument::PixiToml(_) => ManifestKind::Pixi,
ManifestDocument::MojoProjectToml(_) => ManifestKind::MojoProject,
}
}

Expand All @@ -152,13 +157,15 @@ impl ManifestDocument {
match self {
ManifestDocument::PyProjectToml(_) => Some(consts::PYPROJECT_PIXI_PREFIX),
ManifestDocument::PixiToml(_) => None,
ManifestDocument::MojoProjectToml(_) => None,
}
}

fn manifest_mut(&mut self) -> &mut TomlDocument {
match self {
ManifestDocument::PyProjectToml(document) => document,
ManifestDocument::PixiToml(document) => document,
ManifestDocument::MojoProjectToml(document) => document,
}
}

Expand All @@ -167,6 +174,7 @@ impl ManifestDocument {
match self {
ManifestDocument::PyProjectToml(document) => document,
ManifestDocument::PixiToml(document) => document,
ManifestDocument::MojoProjectToml(document) => document,
}
}

Expand Down Expand Up @@ -213,6 +221,7 @@ impl ManifestDocument {
match self {
ManifestDocument::PyProjectToml(document) => document.as_table_mut(),
ManifestDocument::PixiToml(document) => document.as_table_mut(),
ManifestDocument::MojoProjectToml(document) => document.as_table_mut(),
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/pixi_manifest/src/manifests/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ManifestProvenance {
match self.kind {
ManifestKind::Pixi => Ok(ManifestSource::PixiToml(contents)),
ManifestKind::Pyproject => Ok(ManifestSource::PyProjectToml(contents)),
ManifestKind::MojoProject => Ok(ManifestSource::MojoProjectToml(contents)),
}
}

Expand All @@ -75,6 +76,7 @@ impl From<ManifestKind> for ManifestProvenance {
pub enum ManifestKind {
Pixi,
Pyproject,
MojoProject,
}

impl ManifestKind {
Expand All @@ -83,6 +85,7 @@ impl ManifestKind {
match path.file_name().and_then(OsStr::to_str)? {
consts::PROJECT_MANIFEST => Some(Self::Pixi),
consts::PYPROJECT_MANIFEST => Some(Self::Pyproject),
consts::MOJOPROJECT_MANIFEST => Some(Self::MojoProject),
_ => None,
}
}
Expand All @@ -92,6 +95,7 @@ impl ManifestKind {
match self {
ManifestKind::Pixi => consts::PROJECT_MANIFEST,
ManifestKind::Pyproject => consts::PYPROJECT_MANIFEST,
ManifestKind::MojoProject => consts::MOJOPROJECT_MANIFEST,
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/pixi_manifest/src/manifests/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use miette::{NamedSource, SourceCode};
pub enum ManifestSource<S> {
PyProjectToml(S),
PixiToml(S),
MojoProjectToml(S),
}

impl<S> AsRef<S> for ManifestSource<S> {
fn as_ref(&self) -> &S {
match self {
ManifestSource::PyProjectToml(source) => source,
ManifestSource::PixiToml(source) => source,
ManifestSource::MojoProjectToml(source) => source,
}
}
}
Expand All @@ -23,6 +25,7 @@ impl<S> ManifestSource<S> {
match self {
ManifestSource::PyProjectToml(source) => source,
ManifestSource::PixiToml(source) => source,
ManifestSource::MojoProjectToml(source) => source,
}
}

Expand All @@ -31,6 +34,7 @@ impl<S> ManifestSource<S> {
match self {
ManifestSource::PyProjectToml(_) => ManifestKind::Pyproject,
ManifestSource::PixiToml(_) => ManifestKind::Pixi,
ManifestSource::MojoProjectToml(_) => ManifestKind::MojoProject,
}
}

Expand All @@ -39,6 +43,7 @@ impl<S> ManifestSource<S> {
match self {
ManifestSource::PyProjectToml(source) => ManifestSource::PyProjectToml(f(source)),
ManifestSource::PixiToml(source) => ManifestSource::PixiToml(f(source)),
ManifestSource::MojoProjectToml(source) => ManifestSource::MojoProjectToml(f(source)),
}
}

Expand Down
27 changes: 20 additions & 7 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::workspace::WorkspaceMut;
pub enum ManifestFormat {
Pixi,
Pyproject,
Mojoproject,
}

/// Creates a new workspace
Expand All @@ -50,7 +51,7 @@ pub struct Args {
pub env_file: Option<PathBuf>,

/// The manifest format to create.
#[arg(long, conflicts_with_all = ["env_file", "pyproject_toml"], ignore_case = true)]
#[arg(long, conflicts_with_all = ["env_file", "pyproject_toml", "mojoproject_toml"], ignore_case = true)]
pub format: Option<ManifestFormat>,

/// Create a pyproject.toml manifest instead of a pixi.toml manifest
Expand All @@ -61,9 +62,14 @@ pub struct Args {
/// Source Control Management used for this project
#[arg(short = 's', long = "scm", ignore_case = true)]
pub scm: Option<GitAttributes>,

/// Create a mojoproject.toml manifest instead of a pixi.toml manifest
// BREAK (Magic alpha): Remove this option from the cli in favor of the `format` option.
#[arg(long, conflicts_with_all = ["env_file", "format"], alias = "mojoproject", hide = true)]
pub mojoproject_toml: bool,
}

/// The pixi.toml template
/// The pixi.toml/mojoproject.toml template
///
/// This uses a template just to simplify the flexibility of emitting it.
const PROJECT_TEMPLATE: &str = r#"[project]
Expand Down Expand Up @@ -192,6 +198,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let dir = args.path.canonicalize().into_diagnostic()?;
let pixi_manifest_path = dir.join(consts::PROJECT_MANIFEST);
let pyproject_manifest_path = dir.join(consts::PYPROJECT_MANIFEST);
let mojoproject_manifest_path = dir.join(consts::MOJOPROJECT_MANIFEST);
let gitignore_path = dir.join(".gitignore");
let gitattributes_path = dir.join(".gitattributes");
let config = Config::load_global();
Expand Down Expand Up @@ -429,9 +436,15 @@ pub async fn execute(args: Args) -> miette::Result<()> {

// Create a 'pixi.toml' manifest
} else {
// Check if the 'pixi.toml' file doesn't already exist. We don't want to
// overwrite it.
if pixi_manifest_path.is_file() {
let path = if args.mojoproject_toml || args.format == Some(ManifestFormat::Mojoproject)
{
mojoproject_manifest_path
} else {
pixi_manifest_path
};

// Check if the manifest file doesn't already exist. We don't want to overwrite it.
if path.is_file() {
miette::bail!("{} already exists", consts::PROJECT_MANIFEST);
}
let rv = render_project(
Expand All @@ -445,7 +458,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
&extra_index_urls,
None,
);
save_manifest_file(&pixi_manifest_path, rv)?;
save_manifest_file(&path, rv)?;
};
}

Expand Down Expand Up @@ -528,7 +541,7 @@ fn get_name_from_dir(path: &Path) -> miette::Result<String> {

// When the specific template is not in the file or the file does not exist.
// Make the file and append the template to the file.
fn create_or_append_file(path: &Path, template: &str) -> std::io::Result<()> {
pub fn create_or_append_file(path: &Path, template: &str) -> std::io::Result<()> {
let file = fs_err::read_to_string(path).unwrap_or_default();

if !file.contains(template) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing_subscriber::{
};

pub mod add;
mod build;
pub mod build;
pub mod clean;
pub mod cli_config;
pub mod completion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: src/cli/completion.rs
expression: result
snapshot_kind: text
---
# Runs task in project
export extern "pixi run" [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: src/cli/completion.rs
expression: result
---

(add)
_arguments "${_arguments_options[@]}" \
'--manifest-path=[The path to '\''pixi.toml'\'']:MANIFEST_PATH:_files' \
Expand Down Expand Up @@ -44,5 +43,3 @@ _arguments "${_arguments_options[@]}" \
_arguments "${_arguments_options[@]}" \
&& ret=0
;;


Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: src/global/project/parsed_manifest.rs
expression: manifest.unwrap_err()
assertion_line: 418
expression: remove_ansi_escape_sequences(&err)
---
Duplicated exposed names found: python, python3
2 changes: 1 addition & 1 deletion src/install_pypi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn update_python_distributions(
let python_record = pixi_records
.iter()
.find(|r| is_python_record(r))
.ok_or_else(|| miette::miette!("could not resolve pypi dependencies because no python interpreter is added to the dependencies of the project.\nMake sure to add a python interpreter to the [dependencies] section of the {manifest}, or run:\n\n\tpixi add python", manifest=consts::PROJECT_MANIFEST))?;
.ok_or_else(|| miette::miette!("could not resolve pypi dependencies because no python interpreter is added to the dependencies of the project.\nMake sure to add a python interpreter to the [dependencies] section of the {manifest}, or run:\n\n\t{executable} add python", manifest=consts::PROJECT_MANIFEST, executable=pixi_utils::executable_name()))?;
let tags = get_pypi_tags(
platform,
system_requirements,
Expand Down
1 change: 1 addition & 0 deletions src/lock_file/package_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use uv_normalize::{ExtraName, InvalidNameError};
/// Defines information about a Pypi package extracted from either a python
/// package or from a conda package. That can be used for comparison in both
#[derive(Debug)]
#[allow(dead_code)]
pub struct PypiPackageIdentifier {
pub name: PyPiPackageName,
pub version: pep440_rs::Version,
Expand Down
1 change: 0 additions & 1 deletion src/lock_file/records_by_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl HasNameVersion for PypiRecord {
&self.0.version
}
}

impl HasNameVersion for RepoDataRecord {
type N = rattler_conda_types::PackageName;
type V = VersionWithSource;
Expand Down
Loading

0 comments on commit f7ff38d

Please sign in to comment.