Skip to content
Merged
Changes from 2 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
15 changes: 11 additions & 4 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
io::{Error, ErrorKind, Write},
path::{Path, PathBuf},
};

use std::str::FromStr;
use clap::{Parser, ValueEnum};
use miette::{Context, IntoDiagnostic};
use minijinja::{context, Environment};
Expand All @@ -17,7 +17,7 @@ use pixi_utils::conda_environment_file::CondaEnvFile;
use rattler_conda_types::{NamedChannelOrUrl, Platform};
use tokio::fs::OpenOptions;
use url::Url;

use uv_normalize::PackageName;
use crate::Project;

#[derive(Parser, Debug, Clone, PartialEq, ValueEnum)]
Expand Down Expand Up @@ -137,7 +137,7 @@ platforms = {{ platforms }}
{%- endif %}

[tool.pixi.pypi-dependencies]
{{ name }} = { path = ".", editable = true }
{{ pypi_package_name }} = { path = ".", editable = true }

[tool.pixi.tasks]

Expand Down Expand Up @@ -334,12 +334,18 @@ pub async fn execute(args: Args) -> miette::Result<()> {

// Create a 'pyproject.toml' manifest
} else if pyproject {
// Python package names cannot contain '-', so we replace them with '_'
let pypi_package_name = PackageName::from_str(&default_name)
.map(|name| name.as_dist_info_name().to_string())
.unwrap_or_else(|_| default_name.clone());

let rv = env
.render_named_str(
consts::PYPROJECT_MANIFEST,
NEW_PYROJECT_TEMPLATE,
context! {
name => default_name,
pypi_package_name,
version,
author,
channels,
Expand All @@ -350,7 +356,8 @@ 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);

let src_dir = dir.join("src").join(pypi_package_name);
tokio::fs::create_dir_all(&src_dir)
.await
.into_diagnostic()
Expand Down