Skip to content

Commit 292ed15

Browse files
committed
Support option to explicity set python version
1 parent 8a5af02 commit 292ed15

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ resolvers ++= Seq(
1515

1616
libraryDependencies ++= Seq(
1717
"com.typesafe.play" %% "play-json" % "2.3.8",
18-
"com.codacy" %% "codacy-engine-scala-seed" % "2.7.7"
18+
"com.codacy" %% "codacy-engine-scala-seed" % "2.7.8"
1919
)
2020

2121
enablePlugins(JavaAppPackaging)

src/main/scala/codacy/pylint/Pylint.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import scala.util.{Properties, Success, Try}
1313

1414
object Pylint extends Tool {
1515

16-
def apply(source: Source.Directory, configuration: Option[List[Pattern.Definition]], files: Option[Set[Source.File]])
16+
private val pythonVersionKey = Configuration.Key("python_version")
17+
private val python3 = "3"
18+
19+
def apply(source: Source.Directory, configuration: Option[List[Pattern.Definition]], files: Option[Set[Source.File]],
20+
options: Map[Configuration.Key, Configuration.Value])
1721
(implicit specification: Tool.Specification): Try[List[Result]] = {
1822
val completeConf = ToolHelper.patternsToLint(configuration)
1923

@@ -41,7 +45,15 @@ object Pylint extends Tool {
4145
}
4246

4347
val collectedFiles = collectFiles(files, source)
44-
val classified = classifyFiles(collectedFiles)
48+
val classified = options.get(pythonVersionKey).fold {
49+
classifyFiles(collectedFiles)
50+
} { pythonVersion =>
51+
val validPythonVersion = Option(pythonVersion : JsValue).collect {
52+
case JsNumber(version) => version
53+
case JsString(version) => Try(version.toInt)
54+
}.map(_.toString).getOrElse(python3)
55+
Try(Map(validPythonVersion -> collectedFiles.toArray))
56+
}
4557
val commands = classified.map { item => buildFileCommands(item) }
4658
val lines_iterable = commands.map { item => item.map(getStdout) }
4759
val lines = lines_iterable.map {
@@ -137,7 +149,7 @@ object Pylint extends Tool {
137149
List("python3", tmp.toAbsolutePath.toString, scriptArgs).!!
138150
}
139151

140-
private def classifyFiles(files: List[String]) = {
152+
private def classifyFiles(files: List[String]): Try[Map[String, Array[String]]] = {
141153
Try {
142154
val output = generateClassification(files)
143155
val lines = output.split(System.lineSeparator())

0 commit comments

Comments
 (0)