From e4bb66e278e7b30dc2dd9f23baa371b6ff1fc880 Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 30 Apr 2023 21:43:57 +0800 Subject: [PATCH] Update pyproject-toml to 0.6.0 --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 2 +- src/metadata.rs | 26 ++++++++++++++++---------- src/source_distribution.rs | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d4a3fc68..494e6eba0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,9 +265,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732ffa2b10f89dd59538349855f3eaf4032e909361ac4917a52fb43cc70fccf0" +checksum = "c8790cf1286da485c72cf5fc7aeba308438800036ec67d89425924c4807268c9" dependencies = [ "smallvec", ] @@ -662,9 +662,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", "miniz_oxide", @@ -1133,9 +1133,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] @@ -1485,9 +1485,9 @@ dependencies = [ [[package]] name = "pyproject-toml" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da59c451f2bb4052f5e2b26a1d0df40155ca089ffd67dfaffe9e4e5580a2044a" +checksum = "f04dbbb336bd88583943c7cd973a32fed323578243a7569f40cb0c7da673321b" dependencies = [ "indexmap", "pep440_rs", diff --git a/Cargo.toml b/Cargo.toml index 80190fac8..c73b63253 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ rustc_version = "0.4.0" semver = "1.0.13" target-lexicon = "0.12.0" indexmap = "1.9.3" -pyproject-toml = "0.5.2" +pyproject-toml = "0.6.0" python-pkginfo = "0.5.5" textwrap = "0.16.0" ignore = "0.4.20" diff --git a/src/metadata.rs b/src/metadata.rs index c09febb8c..b18215ffe 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -4,6 +4,7 @@ use fs_err as fs; use indexmap::IndexMap; use pep440_rs::{Version, VersionSpecifiers}; use pep508_rs::{MarkerExpression, MarkerOperator, MarkerTree, MarkerValue, Requirement}; +use pyproject_toml::License; use regex::Regex; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -180,16 +181,21 @@ impl Metadata21 { self.requires_python = Some(requires_python.clone()); } - if let Some(pyproject_toml::License { file, text }) = &project.license { - if file.is_some() && text.is_some() { - bail!("file and text fields of 'project.license' are mutually-exclusive, only one of them should be specified"); - } - if let Some(license_path) = file { - let license_path = pyproject_dir.join(license_path); - self.license_files.push(license_path); - } - if let Some(license_text) = text { - self.license = Some(license_text.clone()); + if let Some(license) = &project.license { + match license { + // TODO: switch to License-Expression core metadata, see https://peps.python.org/pep-0639/#add-license-expression-field + License::String(license_expr) => self.license = Some(license_expr.clone()), + License::Table { file, text } => match (file, text) { + (Some(_), Some(_)) => { + bail!("file and text fields of 'project.license' are mutually-exclusive, only one of them should be specified"); + } + (Some(license_path), None) => { + let license_path = pyproject_dir.join(license_path); + self.license_files.push(license_path); + } + (None, Some(license_text)) => self.license = Some(license_text.clone()), + (None, None) => {} + }, } } diff --git a/src/source_distribution.rs b/src/source_distribution.rs index db4cf4c33..084f4adaa 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -738,7 +738,7 @@ pub fn source_distribution( if let Some(pyproject_toml::ReadMe::RelativePath(readme)) = project.readme.as_ref() { writer.add_file(root_dir.join(readme), pyproject_dir.join(readme))?; } - if let Some(pyproject_toml::License { + if let Some(pyproject_toml::License::Table { file: Some(license), text: None, }) = project.license.as_ref()