Skip to content
Merged
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: 3 additions & 3 deletions crates/pixi_build_frontend/tests/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn test_invalid_manifest() {
let source_dir = tempfile::TempDir::new().unwrap();
let manifest = source_dir
.path()
.join(pixi_consts::consts::PROJECT_MANIFEST);
.join(pixi_consts::consts::WORKSPACE_MANIFEST);
tokio::fs::write(&manifest, "[workspace]").await.unwrap();
let err = BuildFrontend::default()
.setup_protocol(SetupRequest {
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn test_not_a_package() {
let source_dir = tempfile::TempDir::new().unwrap();
let manifest = source_dir
.path()
.join(pixi_consts::consts::PROJECT_MANIFEST);
.join(pixi_consts::consts::WORKSPACE_MANIFEST);
tokio::fs::write(
&manifest,
r#"
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn test_invalid_backend() {
let source_dir = tempfile::TempDir::new().unwrap();
let manifest = source_dir
.path()
.join(pixi_consts::consts::PROJECT_MANIFEST);
.join(pixi_consts::consts::WORKSPACE_MANIFEST);

let toml = r#"
[workspace]
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const DEFAULT_ENVIRONMENT_NAME: &str = "default";
pub const DEFAULT_FEATURE_NAME: &str = DEFAULT_ENVIRONMENT_NAME;
pub const PYPROJECT_PIXI_PREFIX: &str = "tool.pixi";

pub const PROJECT_MANIFEST: &str = "pixi.toml";
pub const WORKSPACE_MANIFEST: &str = "pixi.toml";
pub const PYPROJECT_MANIFEST: &str = "pyproject.toml";
pub const CONFIG_FILE: &str = "config.toml";
pub const PIXI_VERSION: &str = match option_env!("PIXI_VERSION") {
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_manifest/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl WorkspaceDiscoverer {

/// Discover the workspace manifest in a directory.
fn provenance_from_dir(dir: &Path) -> Option<ManifestProvenance> {
let pixi_toml_path = dir.join(consts::PROJECT_MANIFEST);
let pixi_toml_path = dir.join(consts::WORKSPACE_MANIFEST);
let pyproject_toml_path = dir.join(consts::PYPROJECT_MANIFEST);
if pixi_toml_path.is_file() {
Some(ManifestProvenance::new(pixi_toml_path, ManifestKind::Pixi))
Expand Down
32 changes: 29 additions & 3 deletions crates/pixi_manifest/src/manifests/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ impl ManifestDocument {
/// Detect the table name to use when querying elements of the manifest.
fn detect_table_name(&self) -> &'static str {
if self.manifest().as_table().contains_key("workspace") {
// pixi.toml
"workspace"
} else if self
.manifest()
.as_table()
.get("tool")
.and_then(|t| t.get("pixi"))
.and_then(|t| t.get("workspace"))
.is_some()
{
// pyproject.toml
"workspace"
} else {
"project"
Expand Down Expand Up @@ -677,16 +688,31 @@ impl ManifestDocument {

/// Sets the name of the project
pub fn set_name(&mut self, name: &str) {
self.as_table_mut()["project"]["name"] = value(name);
let table = self.as_table_mut();
if table.contains_key("project") {
table["project"]["name"] = value(name);
} else {
table["workspace"]["name"] = value(name);
}
}

/// Sets the description of the project
pub fn set_description(&mut self, description: &str) {
self.as_table_mut()["project"]["description"] = value(description);
let table = self.as_table_mut();
if table.contains_key("project") {
table["project"]["description"] = value(description);
} else {
table["workspace"]["description"] = value(description);
}
}

/// Sets the version of the project
pub fn set_version(&mut self, version: &str) {
self.as_table_mut()["project"]["version"] = value(version);
let table = self.as_table_mut();
if table.contains_key("project") {
table["project"]["version"] = value(version);
} else {
table["workspace"]["version"] = value(version);
}
}
}
4 changes: 2 additions & 2 deletions crates/pixi_manifest/src/manifests/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ManifestKind {
/// Try to determine the type of manifest from a path
pub fn try_from_path(path: &Path) -> Option<Self> {
match path.file_name().and_then(OsStr::to_str)? {
consts::PROJECT_MANIFEST => Some(Self::Pixi),
consts::WORKSPACE_MANIFEST => Some(Self::Pixi),
consts::PYPROJECT_MANIFEST => Some(Self::Pyproject),
_ => None,
}
Expand All @@ -90,7 +90,7 @@ impl ManifestKind {
/// Returns the default file name for a manifest of a certain kind.
pub fn file_name(self) -> &'static str {
match self {
ManifestKind::Pixi => consts::PROJECT_MANIFEST,
ManifestKind::Pixi => consts::WORKSPACE_MANIFEST,
ManifestKind::Pyproject => consts::PYPROJECT_MANIFEST,
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ pub enum ManifestFormat {
/// Creates a new workspace
#[derive(Parser, Debug)]
pub struct Args {
/// Where to place the project (defaults to current path)
/// Where to place the workspace (defaults to current path)
#[arg(default_value = ".")]
pub path: PathBuf,

/// Channels to use in the project.
/// Channels to use in the workspace.
#[arg(short, long = "channel", id = "channel", conflicts_with = "env_file")]
pub channels: Option<Vec<NamedChannelOrUrl>>,

/// Platforms that the project supports.
/// Platforms that the workspace supports.
#[arg(short, long = "platform", id = "platform")]
pub platforms: Vec<String>,

/// Environment.yml file to bootstrap the project.
/// Environment.yml file to bootstrap the workspace.
#[arg(short = 'i', long = "import")]
pub env_file: Option<PathBuf>,

Expand All @@ -58,15 +58,15 @@ pub struct Args {
#[arg(long, conflicts_with_all = ["env_file", "format"], alias = "pyproject", hide = true)]
pub pyproject_toml: bool,

/// Source Control Management used for this project
/// Source Control Management used for this workspace
#[arg(short = 's', long = "scm", ignore_case = true)]
pub scm: Option<GitAttributes>,
}

/// The pixi.toml template
///
/// This uses a template just to simplify the flexibility of emitting it.
const PROJECT_TEMPLATE: &str = r#"[project]
const WORKSPACE_TEMPLATE: &str = r#"[workspace]
{%- if author %}
authors = ["{{ author[0] }} <{{ author[1] }}>"]
{%- endif %}
Expand All @@ -85,7 +85,7 @@ version = "{{ version }}"
{%- if s3 %}
{%- for key in s3 %}

[project.s3-options.{{ key }}]
[workspace.s3-options.{{ key }}]
{%- if s3[key]["endpoint-url"] %}
endpoint-url = "{{ s3[key]["endpoint-url"] }}"
{%- endif %}
Expand Down Expand Up @@ -117,7 +117,7 @@ env = { {{ env_vars }} }
///
/// This is injected into an existing pyproject.toml
const PYROJECT_TEMPLATE_EXISTING: &str = r#"
[tool.pixi.project]
[tool.pixi.workspace]
{%- if pixi_name %}
name = "{{ name }}"
{%- endif %}
Expand All @@ -138,7 +138,7 @@ default = { solve-group = "default" }
{%- if s3 %}
{%- for key in s3 %}

[tool.pixi.project.s3-options.{{ key }}]
[tool.pixi.workspace.s3-options.{{ key }}]
{%- if s3[key]["endpoint-url"] %}
endpoint-url = "{{ s3[key]["endpoint-url"] }}"
{%- endif %}
Expand Down Expand Up @@ -174,7 +174,7 @@ version = "{{ version }}"
build-backend = "hatchling.build"
requires = ["hatchling"]

[tool.pixi.project]
[tool.pixi.workspace]
channels = {{ channels }}
platforms = {{ platforms }}

Expand All @@ -189,7 +189,7 @@ platforms = {{ platforms }}
{%- if s3 %}
{%- for key in s3 %}

[tool.pixi.project.s3-options.{{ key }}]
[tool.pixi.workspace.s3-options.{{ key }}]
{%- if s3[key]["endpoint-url"] %}
endpoint-url = "{{ s3[key]["endpoint-url"] }}"
{%- endif %}
Expand Down Expand Up @@ -247,7 +247,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Fail silently if the directory already exists or cannot be created.
fs_err::create_dir_all(&args.path).ok();
let dir = args.path.canonicalize().into_diagnostic()?;
let pixi_manifest_path = dir.join(consts::PROJECT_MANIFEST);
let pixi_manifest_path = dir.join(consts::WORKSPACE_MANIFEST);
let pyproject_manifest_path = dir.join(consts::PYPROJECT_MANIFEST);
let gitignore_path = dir.join(".gitignore");
let gitattributes_path = dir.join(".gitattributes");
Expand All @@ -263,7 +263,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
);
}

let default_name = get_name_from_dir(&dir).unwrap_or_else(|_| String::from("new_project"));
let default_name = get_name_from_dir(&dir).unwrap_or_else(|_| String::from("new_workspace"));
let version = "0.1.0";
let author = get_default_author();
let platforms = if args.platforms.is_empty() {
Expand All @@ -278,7 +278,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Check if the 'pixi.toml' file doesn't already exist. We don't want to
// overwrite it.
if pixi_manifest_path.is_file() {
miette::bail!("{} already exists", consts::PROJECT_MANIFEST);
miette::bail!("{} already exists", consts::WORKSPACE_MANIFEST);
}

let env_file = CondaEnvFile::from_path(&env_file_path)?;
Expand All @@ -291,7 +291,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// TODO: Improve this:
// - Use .condarc as channel config
let (conda_deps, pypi_deps, channels) = env_file.to_manifest(&config)?;
let rendered_workspace_template = render_project(
let rendered_workspace_template = render_workspace(
&env,
name,
version,
Expand Down Expand Up @@ -372,15 +372,15 @@ pub async fn execute(args: Args) -> miette::Result<()> {
args.format == Some(ManifestFormat::Pyproject) || args.pyproject_toml
};

// Inject a tool.pixi.project section into an existing pyproject.toml file if
// there is one without '[tool.pixi.project]'
// Inject a tool.pixi.workspace section into an existing pyproject.toml file if
// there is one without '[tool.pixi.workspace]'
if pyproject && pyproject_manifest_path.is_file() {
let pyproject = PyProjectManifest::from_path(&pyproject_manifest_path)?;

// Early exit if 'pyproject.toml' already contains a '[tool.pixi.project]' table
// Early exit if 'pyproject.toml' already contains a '[tool.pixi.workspace]' table
if pyproject.has_pixi_table() {
eprintln!(
"{}Nothing to do here: 'pyproject.toml' already contains a '[tool.pixi.project]' section.",
"{}Nothing to do here: 'pyproject.toml' already contains a '[tool.pixi.workspace3]' section.",
console::style(console::Emoji("🤔 ", "")).blue(),
);
return Ok(());
Expand Down Expand Up @@ -492,9 +492,9 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Check if the 'pixi.toml' file doesn't already exist. We don't want to
// overwrite it.
if pixi_manifest_path.is_file() {
miette::bail!("{} already exists", consts::PROJECT_MANIFEST);
miette::bail!("{} already exists", consts::WORKSPACE_MANIFEST);
}
let rv = render_project(
let rv = render_workspace(
&env,
default_name,
version,
Expand Down Expand Up @@ -534,7 +534,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
}

#[allow(clippy::too_many_arguments)]
fn render_project(
fn render_workspace(
env: &Environment<'_>,
name: String,
version: &str,
Expand All @@ -560,7 +560,7 @@ fn render_project(
} else {String::new()}},
};

env.render_named_str(consts::PROJECT_MANIFEST, PROJECT_TEMPLATE, ctx)
env.render_named_str(consts::WORKSPACE_MANIFEST, WORKSPACE_TEMPLATE, ctx)
.expect("should be able to render the template")
}

Expand Down
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\tpixi add python", manifest=consts::WORKSPACE_MANIFEST))?;
let tags = get_pypi_tags(
platform,
system_requirements,
Expand Down
4 changes: 2 additions & 2 deletions src/lock_file/resolve/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub async fn resolve_pypi(
.collect::<Result<Vec<_>, _>>()
.into_diagnostic()?;

use pixi_consts::consts::PROJECT_MANIFEST;
use pixi_consts::consts::WORKSPACE_MANIFEST;
// Determine the python interpreter that is installed as part of the conda
// packages.
let python_record = locked_pixi_records
Expand All @@ -246,7 +246,7 @@ pub async fn resolve_pypi(
PixiRecord::Binary(r) => is_python_record(r),
_ => false,
})
.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 {PROJECT_MANIFEST}, or run:\n\n\tpixi add python"))?;
.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 {WORKSPACE_MANIFEST}, or run:\n\n\tpixi add python"))?;

// Construct the marker environment for the target platform
let marker_environment = determine_marker_environment(platform, python_record.as_ref())?;
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum WorkspaceLocatorError {
/// The workspace could not be located.
#[error(
"could not find {project_manifest} or {pyproject_manifest} at directory {0}",
project_manifest = consts::PROJECT_MANIFEST,
project_manifest = consts::WORKSPACE_MANIFEST,
pyproject_manifest = consts::PYPROJECT_MANIFEST
)]
WorkspaceNotFound(PathBuf),
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_python/test_main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_pixi_init_cwd(pixi: Path, tmp_pixi_workspace: Path) -> None:

# Verify that the manifest file contains expected content
manifest_content = manifest_path.read_text()
assert "[project]" in manifest_content
assert "[workspace]" in manifest_content


def test_pixi_init_non_existing_dir(pixi: Path, tmp_pixi_workspace: Path) -> None:
Expand All @@ -364,7 +364,7 @@ def test_pixi_init_non_existing_dir(pixi: Path, tmp_pixi_workspace: Path) -> Non

# Verify that the manifest file contains expected content
manifest_content = manifest_path.read_text()
assert "[project]" in manifest_content
assert "[workspace]" in manifest_content


@pytest.mark.slow
Expand Down
6 changes: 3 additions & 3 deletions tests/integration_rust/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,18 @@ impl PixiControl {
// Either pixi.toml or pyproject.toml
if self
.workspace_path()
.join(consts::PROJECT_MANIFEST)
.join(consts::WORKSPACE_MANIFEST)
.exists()
{
self.workspace_path().join(consts::PROJECT_MANIFEST)
self.workspace_path().join(consts::WORKSPACE_MANIFEST)
} else if self
.workspace_path()
.join(consts::PYPROJECT_MANIFEST)
.exists()
{
self.workspace_path().join(consts::PYPROJECT_MANIFEST)
} else {
self.workspace_path().join(consts::PROJECT_MANIFEST)
self.workspace_path().join(consts::WORKSPACE_MANIFEST)
}
}

Expand Down
Loading