@@ -13,7 +13,11 @@ import scala.util.{Properties, Success, Try}
1313
1414object 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