Skip to content

Commit

Permalink
Merge branch 'fix/459' into astraea/release
Browse files Browse the repository at this point in the history
* fix/459:
  Fixed handling of release numbers and added better docs.
  • Loading branch information
metasim committed Mar 4, 2020
2 parents 5b7fb33 + 2c1b24d commit bb11d5a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions project/PythonBuildPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ object PythonBuildPlugin extends AutoPlugin {
val maven2PEP440: String => String = {
case VersionNumber(numbers, tags, extras) =>
if (numbers.isEmpty) throw new MessageOnlyException("Version string is not convertible to PEP440.")
val rc = "^[Rr][Cc](\\d+)$".r

// Reconstruct the primary version number
val base = numbers.mkString(".")

// Process items after the `-`. Due to PEP 440 constraints, some tags get converted
// to local version suffixes, while others map directly to prerelease suffixes.
val rc = "^[Rr][Cc](\\d+)$".r
val tag = tags match {
case Seq("SNAPSHOT") => ".dev"
case Seq(rc(num)) => ".rc" + num
case Seq(other) => ".dev+" + other
case many => ".dev" + "+" + many.mkString(".")
case many @ Seq(_, _) => ".dev+" + many.mkString(".")
case _ => ""
}

// sbt "extras" most closely map to PEP 440 local version suffixes.
// The local version components are separated by `.`, preceded by a single `+`, and not multiple `+` as in sbt.
// These next two expressions do the appropriate separator conversions while concatenating the components.
val ssep = if (tag.contains("+")) "." else "+"
val ext = if (extras.nonEmpty)
extras.map(_.replaceAllLiterally("+", "")).mkString(ssep, ".", "")
else ""

base + tag + ext
}
}
Expand Down

0 comments on commit bb11d5a

Please sign in to comment.