Skip to content

Commit

Permalink
Merge pull request #1585 from messense/update-pyproject-toml
Browse files Browse the repository at this point in the history
Update pyproject-toml to 0.6.0
  • Loading branch information
messense authored May 2, 2023
2 parents 67dbe8b + e4bb66e commit de44b26
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 16 additions & 10 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {}
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit de44b26

Please sign in to comment.