Skip to content

Commit 7eb2dd1

Browse files
Take into account PATHEXT on Windows
This env var contains extensions of executable files, separated by ';' (so it looks like ".exe;.bat;…"). It should be taken into account when looking for executables in PATH on Windows.
1 parent 2554d9e commit 7eb2dd1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/scala/ai/kien/python/Python.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ai.kien.python
22

33
import java.io.{File, FileNotFoundException}
44
import java.nio.file.{FileSystem, FileSystems, Files}
5-
import scala.collection.compat.immutable.LazyList
65
import scala.util.{Properties, Success, Try}
76

87
/** A class for extracting the necessary configuration properties for embedding a specific Python
@@ -95,11 +94,16 @@ class Python private[python] (
9594
private val pathSeparator =
9695
isWindows.map(if (_) ";" else ":").getOrElse(File.pathSeparator)
9796

98-
private def existsInPath(exec: String): Boolean = path
99-
.split(pathSeparator)
100-
.to(LazyList)
101-
.map(fs.getPath(_))
102-
.exists(path => Files.exists(path.resolve(exec)))
97+
private def existsInPath(exec: String): Boolean = {
98+
val pathExts = getEnv("PATHEXT").getOrElse("").split(pathSeparator)
99+
val l = for {
100+
elem <- path.split(pathSeparator).iterator
101+
elemPath = fs.getPath(elem)
102+
ext <- pathExts.iterator
103+
} yield Files.exists(elemPath.resolve(exec + ext))
104+
105+
l.contains(true)
106+
}
103107

104108
private lazy val python: Try[String] = Try(
105109
if (existsInPath("python3"))

0 commit comments

Comments
 (0)