Skip to content

Commit

Permalink
add publish task
Browse files Browse the repository at this point in the history
  • Loading branch information
jodersky committed Nov 30, 2024
1 parent 2d8c5c0 commit 93e51d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions pythonlib/src/mill/pythonlib/SetupTools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait SetupTools extends PythonModule {
}

override def pythonToolDeps = Task {
super.pythonToolDeps() ++ Seq("setuptools", "build")
super.pythonToolDeps() ++ Seq("setuptools", "build", "twine")
}

/**
Expand Down Expand Up @@ -76,7 +76,13 @@ trait SetupTools extends PythonModule {
*/
def pyproject: T[PathRef] = T{
val str =
s"""|[build-system]
s"""|[project]
|name="${publishMeta().name}"
|version="${publishVersion()}"
|description="${publishMeta().description}"
|readme="${publishReadme().path.last}"
|
|[build-system]
|requires=["setuptools"]
|build-backend="setuptools.build_meta"
|""".stripMargin
Expand All @@ -94,7 +100,11 @@ trait SetupTools extends PythonModule {
*
* @see [[pyproject]]
*/
def buildFiles: T[Map[String, PathRef]] = Task { Map.empty[String, PathRef] }
def buildFiles: T[Map[String, PathRef]] = Task {
Map(
publishReadme().path.last -> publishReadme()
)
}

/**
* The readme file to include in the published distribution.
Expand Down Expand Up @@ -239,6 +249,30 @@ trait SetupTools extends PythonModule {
PathRef(os.list(T.dest / "dist").head)
}

def repositoryUrl: T[String] = Task {
"https://test.pypi.org/legacy/"
}

def publish(
repositoryUrl: String = null,
username: String = null,
password: String = null
): Command[Unit] = Task.Command {
runner().run(
(
// format: off
"-m", "twine",
"upload",
"--non-interactive",
"--repository-url", Option(repositoryUrl).getOrElse(this.repositoryUrl()),
Option(username).toSeq.flatMap(u => Seq("--username", u)),
Option(password).toSeq.flatMap(p => Seq("--password", p)),
sdist().path, wheel().path
// format: on
)
)
}

}

object SetupTools {
Expand Down

0 comments on commit 93e51d2

Please sign in to comment.