Skip to content

Commit 2c1b24d

Browse files
committed
Fixed handling of release numbers and added better docs.
1 parent c6977d3 commit 2c1b24d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

project/PythonBuildPlugin.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,29 @@ object PythonBuildPlugin extends AutoPlugin {
4040
val maven2PEP440: String => String = {
4141
case VersionNumber(numbers, tags, extras) =>
4242
if (numbers.isEmpty) throw new MessageOnlyException("Version string is not convertible to PEP440.")
43-
val rc = "^[Rr][Cc](\\d+)$".r
43+
44+
// Reconstruct the primary version number
4445
val base = numbers.mkString(".")
46+
47+
// Process items after the `-`. Due to PEP 440 constraints, some tags get converted
48+
// to local version suffixes, while others map directly to prerelease suffixes.
49+
val rc = "^[Rr][Cc](\\d+)$".r
4550
val tag = tags match {
4651
case Seq("SNAPSHOT") => ".dev"
4752
case Seq(rc(num)) => ".rc" + num
4853
case Seq(other) => ".dev+" + other
49-
case many => ".dev" + "+" + many.mkString(".")
54+
case many @ Seq(_, _) => ".dev+" + many.mkString(".")
55+
case _ => ""
5056
}
57+
58+
// sbt "extras" most closely map to PEP 440 local version suffixes.
59+
// The local version components are separated by `.`, preceded by a single `+`, and not multiple `+` as in sbt.
60+
// These next two expressions do the appropriate separator conversions while concatenating the components.
5161
val ssep = if (tag.contains("+")) "." else "+"
5262
val ext = if (extras.nonEmpty)
5363
extras.map(_.replaceAllLiterally("+", "")).mkString(ssep, ".", "")
5464
else ""
65+
5566
base + tag + ext
5667
}
5768
}

0 commit comments

Comments
 (0)