Skip to content
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

Add PEP 440 local version identifier support #1037

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ cc = "1.0.72"
clap = { version = "3.2.16", features = ["derive", "env", "wrap_help"] }
clap_complete = "3.1.3"
clap_complete_fig = "3.1.0"
tracing = "0.1.36"
dunce = "1.0.2"
pep440 = "0.2.0"

# upload
bytesize = { version = "1.0.1", optional = true }
configparser = { version = "3.0.0", optional = true }
multipart = { version = "0.18.0", features = ["client"], default-features = false, optional = true }
rpassword = { version = "7.0.0", optional = true }
ureq = { version = "2.3.1", features = ["gzip", "socks-proxy"], default-features = false, optional = true }
native-tls-crate = { package = "native-tls", version = "0.2.8", optional = true }
tracing = "0.1.36"
dunce = "1.0.2"

[dev-dependencies]
indoc = "1.0.3"
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add Linux mipsel architecture support in [#1024](https://github.com/PyO3/maturin/pull/1024)
* Add Linux 32-bit powerpc architecture support in [#1026](https://github.com/PyO3/maturin/pull/1026)
* Add Linux sparc64 architecture support in [#1027](https://github.com/PyO3/maturin/pull/1027)
* Add PEP 440 local version identifier support in [#1037](https://github.com/PyO3/maturin/pull/1037)

## [0.13.1] - 2022-07-26

Expand Down
19 changes: 16 additions & 3 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Metadata21 {
let mut fields = vec![
("Metadata-Version", self.metadata_version.clone()),
("Name", self.name.clone()),
("Version", self.get_version_escaped()),
("Version", self.get_pep440_version()),
];

let mut add_vec = |name, values: &[String]| {
Expand Down Expand Up @@ -505,8 +505,21 @@ impl Metadata21 {
/// Returns the version encoded according to PEP 427, Section "Escaping
/// and Unicode"
pub fn get_version_escaped(&self) -> String {
let re = Regex::new(r"[^\w\d.]+").unwrap();
re.replace_all(&self.version, "_").to_string()
self.get_pep440_version().replace('-', "_")
}

/// Returns the version encoded according to PEP 440
///
/// See https://github.com/pypa/setuptools/blob/d90cf84e4890036adae403d25c8bb4ee97841bbf/pkg_resources/__init__.py#L1336-L1345
pub fn get_pep440_version(&self) -> String {
match pep440::Version::parse(&self.version) {
Some(ver) => ver.normalize(),
None => {
let ver = self.version.replace(' ', ".");
let re = Regex::new(r"[^A-Za-z0-9.]+").unwrap();
re.replace_all(&ver, "-").to_string()
}
}
}

/// Returns the name of the .dist-info directory as defined in the wheel specification
Expand Down
1 change: 1 addition & 0 deletions test-crates/pyo3-pure/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bindings = "pyo3"

[project]
name = "pyo3-pure"
version = "0.1.0+abc123de"
classifiers = [
"Programming Language :: Rust"
]
Expand Down