Skip to content

Commit

Permalink
Accept single string for backend-path
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 25, 2024
1 parent 0f1377b commit 47b82fa
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions crates/uv-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use std::{env, iter};

use fs_err as fs;
use indoc::formatdoc;
use itertools::Itertools;
use itertools::{Either, Itertools};
use once_cell::sync::Lazy;
use pyproject_toml::{BuildSystem, Project};
use pyproject_toml::Project;
use regex::Regex;
use serde::{Deserialize, Serialize};
use tempfile::{tempdir_in, TempDir};
Expand Down Expand Up @@ -183,6 +183,37 @@ pub struct PyProjectToml {
pub project: Option<Project>,
}

/// The `[build-system]` section of a pyproject.toml as specified in PEP 517.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct BuildSystem {
/// PEP 508 dependencies required to execute the build system.
pub requires: Vec<Requirement>,
/// A string naming a Python object that will be used to perform the build.
pub build_backend: Option<String>,
/// Specify that their backend code is hosted in-tree, this key contains a list of directories.
pub backend_path: Option<BackendPath>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum BackendPath {
/// A list of paths (matching the schema).
List(Vec<String>),
/// A single path, included for compatibility (see, e.g., `flit_core==2.3.0`, which uses
/// `backend-path = "."`).
String(String),
}

impl BackendPath {
fn iter(&self) -> impl Iterator<Item = &str> {
match self {
BackendPath::List(list) => Either::Left(list.iter().map(std::string::String::as_str)),
BackendPath::String(s) => Either::Right(iter::once(s.as_str())),
}
}
}

/// `[build-backend]` from pyproject.toml
#[derive(Debug, Clone, PartialEq, Eq)]
struct Pep517Backend {
Expand All @@ -194,7 +225,7 @@ struct Pep517Backend {
/// `build-backend.requirements` in pyproject.toml
requirements: Vec<Requirement>,
/// <https://peps.python.org/pep-0517/#in-tree-build-backends>
backend_path: Option<Vec<String>>,
backend_path: Option<BackendPath>,
}

impl Pep517Backend {
Expand All @@ -207,9 +238,8 @@ impl Pep517Backend {

let backend_path_encoded = self
.backend_path
.clone()
.unwrap_or_default()
.iter()
.flat_map(BackendPath::iter)
.map(|path| {
// Turn into properly escaped python string
'"'.to_string()
Expand Down

0 comments on commit 47b82fa

Please sign in to comment.