Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jodersky committed Dec 10, 2024
1 parent 4f848e1 commit 0f4457b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 57 deletions.
57 changes: 0 additions & 57 deletions pythonlib/src/mill/pythonlib/PythonModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,63 +238,6 @@ trait PythonModule extends PipModule with TaskModule { outer =>
override def moduleDeps: Seq[PythonModule] = Seq(outer)
}

// def getRuff(): PathRef = Task {
// import coursier.cache.FileCache
// import coursier.util.Artifact

// val cache = FileCache()
// val file = cache
// .file(Artifact(""))
// .run
// .unsafeRun()(cache.ec)
// .fold(ex => throw new Exception(ex), identity)
// os.unzip(os.Path(file), T.dest)
// PathRef(T.dest)
// }

// Move these into a RuffModule, and consolidate all tasks into one.
/** Command line options to pass the the black code formatter.
*
* This is the way to configure black in mill, since mill doesn't use a
* pyproject.toml file.
*/
def blackOptions: T[Seq[String]] = Task { Seq.empty[String] }

/** Reformat all source files of this module. */
def reformat(): Command[Unit] = Task.Command {
runner().run(
// format: off
(
"-m", "ruff",
"format",
blackOptions(),
sources().map(_.path)
),
// format: on
workingDir = T.dest
)
}

/** Check the format of all source files of this module. */
def checkFormat(): Command[Unit] = Task.Command {
runner().run(
// format: off
(
"-m", "ruff",
"format",
"--check",
blackOptions(),
sources().map(_.path)
),
// format: on
workingDir = T.dest
)
}

def fix(): Command[Unit] = ???

def check(): Command[Unit] = ???

}

object PythonModule {
Expand Down
54 changes: 54 additions & 0 deletions pythonlib/src/mill/pythonlib/RuffModule.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package mill.pythonlib

import mill._
import mill.define.ExternalModule
import mill.define.Discover
import mill.TaskModule

trait RuffModule extends PythonModule {

override def pythonToolDeps = Task {
super.pythonToolDeps() ++ Seq("ruff>=0.8.1")
}

/** Ad-hoc command to invoke ruff on the sources of this module.
*
* You'll need to supply any subcommand that ruff understands. For example:
*
* - format sources: ruff format
* - check format of sources: ruff format --check
* - see format diff: ruff format --diff
* - find linting errors: ruff check
* - automatically fix linting errors: ruff check --fix
*
*/
def ruff(args: String*) = Task.Command {
runner().run(
// format: off
(
"-m", "ruff",
args,
sources().map(_.path)
),
// format: on
workingDir = Task.dest
)
}

}

/**
* Includes some common tasks to reformat and check all sources. This mimics ScalafmtModule, so that
*
*/
object RuffModule extends ExternalModule with TaskModule {

def defaultCommandName() = "reformatAll"

lazy val millDiscover: Discover = Discover[this.type]

def reformatAll


}

0 comments on commit 0f4457b

Please sign in to comment.