-
-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically include license files in .dist-info/license_files
#862
Changes from 7 commits
2c16890
beeffd8
b1c18ca
e654d26
971d70a
11dde2e
62aa103
318e233
0121c15
0c1a530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,25 @@ impl Metadata21 { | |
} | ||
} | ||
|
||
// Until PEP 639 is approved with metadata 2.3, we can assume a | ||
// dynamic license-files (also awaiting full 2.2 metadata support) | ||
// We're already emitting the License-Files metadata without issue. | ||
// license-files.globs = ["LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*"] | ||
let license_include_targets = ["LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*"]; | ||
for pattern in license_include_targets.iter() { | ||
for license_path in glob::glob(&manifest_path.join(pattern).to_string_lossy()) | ||
.expect("No license files found for pattern") | ||
.filter_map(Result::ok) | ||
{ | ||
// if the pyproject.toml specified the license file, | ||
// then we won't list it as automatically included | ||
if !self.license_files.contains(&license_path) { | ||
println!("📦 Including license file \"{}\"", license_path.display()); | ||
self.license_files.push(license_path); | ||
} | ||
} | ||
} | ||
|
||
if let Some(authors) = &project.authors { | ||
let mut names = Vec::with_capacity(authors.len()); | ||
let mut emails = Vec::with_capacity(authors.len()); | ||
|
@@ -835,4 +854,44 @@ mod test { | |
"text/markdown; charset=UTF-8; variant=GFM" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_merge_metadata_from_pyproject_dynamic_license_test() { | ||
let manifest_path = PathBuf::from("test-crates").join("license-test"); | ||
let cargo_toml_str = fs_err::read_to_string(&manifest_path.join("Cargo.toml")).unwrap(); | ||
let cargo_toml: CargoToml = toml_edit::easy::from_str(&cargo_toml_str).unwrap(); | ||
let metadata = Metadata21::from_cargo_toml(&cargo_toml, &manifest_path).unwrap(); | ||
|
||
// verify Cargo.toml value came through | ||
assert_eq!(metadata.license.as_ref().unwrap(), "MIT"); | ||
|
||
let license_files_strings: Vec<_> = metadata | ||
.license_files | ||
.iter() | ||
.map(|v| v.to_str().unwrap()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can just keep everything as PathBuf and drop the unwrap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed fix, thank you! |
||
.collect(); | ||
|
||
// verify we have the total number of expected licenses | ||
assert_eq!(4, license_files_strings.len()); | ||
|
||
// Verify pyproject.toml license = {file = ...} worked | ||
assert_eq!( | ||
license_files_strings[0], | ||
manifest_path.join("LICENCE.txt").to_str().unwrap() | ||
); | ||
|
||
// Verify the default licenses were included | ||
assert_eq!( | ||
license_files_strings[1], | ||
manifest_path.join("LICENSE").to_str().unwrap() | ||
); | ||
assert_eq!( | ||
license_files_strings[2], | ||
manifest_path.join("NOTICE.md").to_str().unwrap() | ||
); | ||
assert_eq!( | ||
license_files_strings[3], | ||
manifest_path.join("AUTHORS.txt").to_str().unwrap() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AUTHORS |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "license-test" | ||
version = "0.1.0" | ||
authors = ["konstin <konstin@mailbox.org>"] | ||
edition = "2018" | ||
license = "MIT" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LICENCE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LICENSE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# NOTICE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AUTHORS |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# COPYING |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LICENCE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LICENSE-APACHE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NOTICE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LICENSE-BSD |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# NOTICE |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from subprocess import check_output | ||
|
||
|
||
def main(): | ||
output = check_output(["hello-world"]).decode("utf-8").strip() | ||
if not output == "Hello, world!": | ||
raise Exception(output) | ||
print("SUCCESS") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build-system] | ||
requires = ["maturin>=0.12,<0.13"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "license-test" | ||
license = { file = "LICENCE.txt" } | ||
|
||
[tool.maturin] | ||
bindings = "bin" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
manifest_path
needs to be escaped withglob::escape
or it'll become part of the pattern. The expect shouldn't happen anyway, but a?
would be better than possibly panickingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a fix for the
?
usage instead of theexpect
. I followed the pattern from source_distribution.rs#L317-L328. I can update the code to usedPattern::escape
if you like.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@konstin Is this what you are looking for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep that looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@konstin Just pushed the change. Thanks for the tip.