@@ -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