Skip to content

Commit

Permalink
Add readme and license files specified in pyproject.toml to sdist if …
Browse files Browse the repository at this point in the history
…not included
  • Loading branch information
messense committed Sep 12, 2022
1 parent 09f0bf4 commit ac98e08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl Metadata21 {
}
if let Some(license_path) = file {
let license_path = pyproject_dir.join(license_path);
println!("license: {:?}", license_path);
self.license_files.push(license_path);
}
if let Some(license_text) = text {
Expand Down
17 changes: 17 additions & 0 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn rewrite_cargo_toml(
fn add_crate_to_source_distribution(
writer: &mut SDistWriter,
pyproject_toml_path: impl AsRef<Path>,
pyproject: &PyProjectToml,
manifest_path: impl AsRef<Path>,
prefix: impl AsRef<Path>,
known_path_deps: &HashMap<String, PathBuf>,
Expand Down Expand Up @@ -199,6 +200,20 @@ fn add_crate_to_source_distribution(
PathBuf::from("pyproject.toml"),
pyproject_toml_path.to_path_buf(),
));
// Add readme and license files
if let Some(project) = pyproject.project.as_ref() {
if let Some(pyproject_toml::ReadMe::RelativePath(readme)) = project.readme.as_ref()
{
target_source.push((PathBuf::from(readme), pyproject_dir.join(readme)));
}
if let Some(pyproject_toml::License {
file: Some(license),
text: None,
}) = project.license.as_ref()
{
target_source.push((PathBuf::from(license), pyproject_dir.join(license)));
}
}
} else {
bail!(
"pyproject.toml was not included by `cargo package`. \
Expand Down Expand Up @@ -298,6 +313,7 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&build_context.pyproject_toml_path,
pyproject,
&path_dep,
&root_dir.join(LOCAL_DEPENDENCIES_FOLDER).join(name),
&known_path_deps,
Expand All @@ -314,6 +330,7 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&build_context.pyproject_toml_path,
pyproject,
&manifest_path,
&root_dir,
&known_path_deps,
Expand Down

0 comments on commit ac98e08

Please sign in to comment.