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

fix: pixi init for pyproject.toml #1947

Merged
merged 4 commits into from
Sep 3, 2024
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
27 changes: 26 additions & 1 deletion src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use clap::{Parser, ValueEnum};
use miette::IntoDiagnostic;
use miette::{Context, IntoDiagnostic};
use minijinja::{context, Environment};
use pixi_config::{get_default_author, Config};
use pixi_consts::consts;
Expand All @@ -15,6 +15,7 @@ use pixi_manifest::{
};
use pixi_utils::conda_environment_file::CondaEnvFile;
use rattler_conda_types::{NamedChannelOrUrl, Platform};
use tokio::fs::OpenOptions;
use url::Url;

use crate::Project;
Expand Down Expand Up @@ -349,6 +350,30 @@ pub async fn execute(args: Args) -> miette::Result<()> {
)
.unwrap();
save_manifest_file(&pyproject_manifest_path, rv)?;
let src_dir = dir.join("src").join(default_name);
tokio::fs::create_dir_all(&src_dir)
.await
.into_diagnostic()
.wrap_err_with(|| format!("Could not create directory {}.", src_dir.display()))?;

let init_file = src_dir.join("__init__.py");
match OpenOptions::new()
.write(true)
.create_new(true)
.open(&init_file)
.await
{
Ok(_) => (),
Err(e) if e.kind() == ErrorKind::AlreadyExists => {
// If the file already exists, do nothing
}
Err(e) => {
return Err(e).into_diagnostic().wrap_err_with(|| {
format!("Could not create file {}.", init_file.display())
});
}
};

// Create a 'pixi.toml' manifest
} else {
// Check if the 'pixi.toml' file doesn't already exist. We don't want to
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,11 @@ def test_simple_project_setup(tmp_path: Path) -> None:
ExitCode.SUCCESS,
stderr_contains=["osx-arm64", "test", "Removed"],
)


def test_pixi_init_pyproject(tmp_path: Path) -> None:
manifest_path = tmp_path / "pyproject.toml"
# Create a new project
verify_cli_command(f"pixi init {tmp_path} --pyproject-toml", ExitCode.SUCCESS)
# Verify that install works
verify_cli_command(f"pixi install --manifest-path {manifest_path}", ExitCode.SUCCESS)
Loading