Skip to content

Commit 492dadd

Browse files
committed
Initial cut a maven->python version number converter.
1 parent 7b65fed commit 492dadd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

project/PythonBuildPlugin.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ object PythonBuildPlugin extends AutoPlugin {
3737
val pythonCommand = settingKey[String]("Python command. Defaults to 'python'")
3838
val pySetup = inputKey[Int]("Run 'python setup.py <args>'. Returns exit code.")
3939
val pyWhl = taskKey[File]("Builds the Python wheel distribution")
40+
val maven2PEP440: String => String = {
41+
case VersionNumber(numbers, tags, extras) =>
42+
if (numbers.isEmpty) throw new MessageOnlyException("Version string is not convertible to PEP440.")
43+
val rc = "^[Rr][Cc](\\d+)$".r
44+
val base = numbers.mkString(".")
45+
val tag = tags match {
46+
case Seq("SNAPSHOT") => ".dev"
47+
case Seq(rc(num)) => ".rc" + num
48+
case Seq(other) => ".dev+" + other
49+
case many => ".dev" + "+" + many.mkString(".")
50+
}
51+
val ssep = if (tag.contains("+")) "." else "+"
52+
val ext = if (extras.nonEmpty)
53+
extras.map(_.replaceAllLiterally("+", "")).mkString(ssep, ".", "")
54+
else ""
55+
base + tag + ext
56+
}
4057
}
4158
import autoImport._
4259

@@ -121,6 +138,7 @@ object PythonBuildPlugin extends AutoPlugin {
121138
inConfig(Python)(Seq(
122139
sourceDirectory := (Compile / sourceDirectory).value / "python",
123140
sourceDirectories := Seq((Python / sourceDirectory).value),
141+
version ~= maven2PEP440,
124142
target := (Compile / target).value / "python",
125143
includeFilter := "*",
126144
excludeFilter := HiddenFileFilter || "__pycache__" || "*.egg-info",

0 commit comments

Comments
 (0)