Skip to content
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: mojopproject.toml support #2

Draft
wants to merge 8 commits into
base: zbowling/pixi-dir
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ rustflags = [
"link-arg=/STACK:8000000",
]

# Required for `dist` to work with linux arm targets: https://github.com/axodotdev/cargo-dist/issues/74#issuecomment-2053680080
[env]
PIXI_CONFIG_DIR = "pixi"
PIXI_DEFAULT_CHANNELS = "conda-forge"
PIXI_DIR = ".pixi"
PIXI_PROJECT_LOCK_FILE = "pixi.lock"
# Required for `dist` to work with linux arm targets: https://github.com/axodotdev/cargo-dist/issues/74#issuecomment-2053680080
CC_aarch64_unknown_linux_musl = "aarch64-linux-gnu-gcc"

[target.aarch64-unknown-linux-musl]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ strip = false
async-trait = { workspace = true }
fake = "3.0.1"
http = { workspace = true }
insta = { workspace = true, features = ["yaml", "glob"] }
insta = { workspace = true, features = ["yaml", "glob", "filters"] }
rstest = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
Expand Down
15 changes: 10 additions & 5 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ pub fn get_cache_dir() -> miette::Result<PathBuf> {
.map(PathBuf::from)
.or_else(|| std::env::var("RATTLER_CACHE_DIR").map(PathBuf::from).ok())
.or_else(|| {
let pixi_cache_dir = dirs::cache_dir().map(|d| d.join("pixi"));

let pixi_cache_dir = dirs::cache_dir().map(|d| d.join(consts::PIXI_DIR));
// Only use the xdg cache pixi directory when it exists
pixi_cache_dir.and_then(|d| d.exists().then_some(d))
})
Expand Down Expand Up @@ -964,7 +963,13 @@ impl Config {
if self.default_channels.is_empty() {
consts::DEFAULT_CHANNELS
.iter()
.map(|s| NamedChannelOrUrl::Name(s.to_string()))
.map(|s| {
if s.starts_with("http://") || s.starts_with("https://") {
NamedChannelOrUrl::Url(Url::parse(s).unwrap())
} else {
NamedChannelOrUrl::Name(s.to_string())
}
})
.collect()
} else {
self.default_channels.clone()
Expand Down Expand Up @@ -1256,13 +1261,13 @@ pub fn config_path_system() -> PathBuf {
#[cfg(not(target_os = "windows"))]
let base_path = PathBuf::from("/etc");

base_path.join("pixi").join(consts::CONFIG_FILE)
base_path.join(consts::CONFIG_DIR).join(consts::CONFIG_FILE)
}

/// Returns the path(s) to the global pixi config file.
pub fn config_path_global() -> Vec<PathBuf> {
vec![
dirs::config_dir().map(|d| d.join("pixi").join(consts::CONFIG_FILE)),
dirs::config_dir().map(|d| d.join(consts::CONFIG_DIR).join(consts::CONFIG_FILE)),
pixi_home().map(|d| d.join(consts::CONFIG_FILE)),
]
.into_iter()
Expand Down
42 changes: 36 additions & 6 deletions crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use console::Style;
use lazy_static::lazy_static;
use std::fmt::{Display, Formatter};
use std::{
ffi::OsStr,
fmt::{Display, Formatter},
path::Path,
};
use url::Url;

pub const DEFAULT_ENVIRONMENT_NAME: &str = "default";
Expand All @@ -9,9 +13,7 @@ pub const PYPROJECT_PIXI_PREFIX: &str = "tool.pixi";

pub const PROJECT_MANIFEST: &str = "pixi.toml";
pub const PYPROJECT_MANIFEST: &str = "pyproject.toml";
pub const PROJECT_LOCK_FILE: &str = "pixi.lock";
pub const CONFIG_FILE: &str = "config.toml";
pub const PIXI_DIR: &str = ".pixi";
pub const PIXI_VERSION: &str = match option_env!("PIXI_VERSION") {
Some(v) => v,
None => "0.39.4",
Expand All @@ -36,13 +38,41 @@ pub const _CACHED_BUILD_ENVS_DIR: &str = "cached-build-envs-v0";
pub const CACHED_BUILD_TOOL_ENVS_DIR: &str = "cached-build-tool-envs-v0";
pub const CACHED_GIT_DIR: &str = "git-cache-v0";

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

pub const CONFIG_DIR: &str = match option_env!("PIXI_CONFIG_DIR") {
Some(dir) => dir,
None => "pixi",
};
pub const PROJECT_LOCK_FILE: &str = match option_env!("PIXI_PROJECT_LOCK_FILE") {
Some(file) => file,
None => "pixi.lock",
};
pub const PIXI_DIR: &str = match option_env!("PIXI_DIR") {
Some(dir) => dir,
None => ".pixi",
};

lazy_static! {
/// The default channels to use for a new project.
pub static ref DEFAULT_CHANNELS: Vec<String> = match option_env!("PIXI_DEFAULT_CHANNELS") {
Some(channels) => channels.split(',').map(|s| s.to_string()).collect(),
None => vec!["conda-forge".to_string()],
};

/// The name of the binary.
pub static ref PIXI_BIN_NAME: String = std::env::args().next()
.as_ref()
.map(Path::new)
.and_then(Path::file_name)
.and_then(OsStr::to_str)
.map(String::from).unwrap_or("pixi".to_string());
}

pub const CONDA_INSTALLER: &str = "conda";

pub const ONE_TIME_MESSAGES_DIR: &str = "one-time-messages";

/// The default channels to use for a new project.
pub const DEFAULT_CHANNELS: &[&str] = &["conda-forge"];

pub const ENVIRONMENT_FILE_NAME: &str = "pixi";

lazy_static! {
Expand Down
7 changes: 6 additions & 1 deletion crates/pixi_manifest/src/manifests/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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::Pixi),
_ => None,
}
}
Expand Down Expand Up @@ -94,6 +95,7 @@ impl Manifest {
match self.source {
ManifestSource::PixiToml(_) => consts::PROJECT_MANIFEST,
ManifestSource::PyProjectToml(_) => consts::PYPROJECT_MANIFEST,
ManifestSource::MojoProjectToml(_) => consts::MOJOPROJECT_MANIFEST,
}
}

Expand Down Expand Up @@ -378,7 +380,10 @@ impl Manifest {
) -> miette::Result<bool> {
// Determine the name of the package to add
let (Some(name), spec) = spec.clone().into_nameless() else {
miette::bail!("pixi does not support wildcard dependencies")
miette::bail!(format!(
"{} does not support wildcard dependencies",
consts::PIXI_BIN_NAME.as_str()
));
};
let spec = PixiSpec::from_nameless_matchspec(spec, channel_config);
let mut any_added = false;
Expand Down
8 changes: 8 additions & 0 deletions crates/pixi_manifest/src/manifests/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ use crate::{
/// Discriminates between a 'pixi.toml' and a 'pyproject.toml' manifest.
#[derive(Debug, Clone)]
pub enum ManifestSource {
MojoProjectToml(TomlDocument),
PyProjectToml(TomlDocument),
PixiToml(TomlDocument),
}

impl fmt::Display for ManifestSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ManifestSource::MojoProjectToml(document) => write!(f, "{}", document),
ManifestSource::PyProjectToml(document) => write!(f, "{}", document),
ManifestSource::PixiToml(document) => write!(f, "{}", document),
}
Expand All @@ -44,20 +46,23 @@ impl ManifestSource {
#[cfg(test)]
fn file_name(&self) -> &'static str {
match self {
ManifestSource::MojoProjectToml(_) => "mojoproject.toml",
ManifestSource::PyProjectToml(_) => "pyproject.toml",
ManifestSource::PixiToml(_) => "pixi.toml",
}
}

fn table_prefix(&self) -> Option<&'static str> {
match self {
ManifestSource::MojoProjectToml(_) => None,
ManifestSource::PyProjectToml(_) => Some(PYPROJECT_PIXI_PREFIX),
ManifestSource::PixiToml(_) => None,
}
}

fn manifest_mut(&mut self) -> &mut TomlDocument {
match self {
ManifestSource::MojoProjectToml(document) => document,
ManifestSource::PyProjectToml(document) => document,
ManifestSource::PixiToml(document) => document,
}
Expand All @@ -66,6 +71,7 @@ impl ManifestSource {
/// Returns the inner TOML document
pub fn manifest(&self) -> &TomlDocument {
match self {
ManifestSource::MojoProjectToml(document) => document,
ManifestSource::PyProjectToml(document) => document,
ManifestSource::PixiToml(document) => document,
}
Expand Down Expand Up @@ -99,6 +105,7 @@ impl ManifestSource {

fn as_table_mut(&mut self) -> &mut Table {
match self {
ManifestSource::MojoProjectToml(document) => document.as_table_mut(),
ManifestSource::PyProjectToml(document) => document.as_table_mut(),
ManifestSource::PixiToml(document) => document.as_table_mut(),
}
Expand Down Expand Up @@ -244,6 +251,7 @@ impl ManifestSource {
// - When a specific platform is requested, as markers are not supported (https://github.com/prefix-dev/pixi/issues/2149)
// - When an editable install is requested
if matches!(self, ManifestSource::PixiToml(_))
|| matches!(self, ManifestSource::MojoProjectToml(_))
|| matches!(location, Some(PypiDependencyLocation::PixiPypiDependencies))
|| platform.is_some()
|| editable.is_some_and(|e| e)
Expand Down
Loading
Loading