From 6cd4650c1fb1bfec3d80efed96b1c5f4af8dd30e Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 27 Oct 2023 12:12:12 +0200 Subject: [PATCH] Support missing `build_system` key (#213) Reduces the number of failing projects out of the top 1000 pypi projects from 5 to 2. --- crates/puffin-build/src/lib.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/puffin-build/src/lib.rs b/crates/puffin-build/src/lib.rs index d39108d2f..55737f0fd 100644 --- a/crates/puffin-build/src/lib.rs +++ b/crates/puffin-build/src/lib.rs @@ -12,7 +12,8 @@ use flate2::read::GzDecoder; use fs_err as fs; use fs_err::{DirEntry, File}; use indoc::formatdoc; -use pyproject_toml::PyProjectToml; +use pyproject_toml::{BuildSystem, Project}; +use serde::{Deserialize, Serialize}; use tar::Archive; use tempfile::{tempdir, TempDir}; use thiserror::Error; @@ -59,6 +60,16 @@ impl Error { } } +/// A pyproject.toml as specified in PEP 517 +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] +#[serde(rename_all = "kebab-case")] +pub struct PyProjectToml { + /// Build-related data + pub build_system: Option, + /// Project metadata + pub project: Option, +} + /// `[build-backend]` from pyproject.toml struct Pep517Backend { /// The build backend string such as `setuptools.build_meta:__legacy__` or `maturin` from @@ -125,14 +136,18 @@ impl SourceDistributionBuilder { // > source tree is not using this specification, and tools should revert to the legacy // > behaviour of running setup.py (either directly, or by implicitly invoking the // > setuptools.build_meta:__legacy__ backend). - if let Some(backend) = pyproject_toml.build_system.build_backend { - pep517 = Some(Pep517Backend { - backend, - requirements: pyproject_toml.build_system.requires, - }); - }; - if pyproject_toml.build_system.backend_path.is_some() { - todo!("backend-path is not supported yet") + if let Some(build_system) = pyproject_toml.build_system { + if let Some(backend) = build_system.build_backend { + pep517 = Some(Pep517Backend { + backend, + requirements: build_system.requires, + }); + }; + if build_system.backend_path.is_some() { + return Err(Error::InvalidSourceDistribution( + "backend-path is not supported yet".to_string(), + )); + } } }