Skip to content

Commit

Permalink
properly set cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
ducky64 committed Aug 8, 2024
1 parent efdd9f4 commit c7f7271
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/main/scala/edg_ide/runner/CompileProcessHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import edg.wir.DesignPath
import edg_ide.edgir_graph.ElkEdgirGraphUtils
import edg_ide.ui.{BlockVisualizerService, EdgCompilerService, EdgSettingsState}
import edg_ide.util.ExceptionNotifyImplicits.ExceptNotify
import edg_ide.util.{DesignAnalysisUtils, exceptable}
import edg_ide.util.exceptable
import edgir.elem.elem
import edgir.ref.ref
import edgir.schema.schema
Expand Down Expand Up @@ -75,8 +75,8 @@ class DesignTopRunParams(workingDirectory: String, sdkHome: String, moduleName:
}

// a PythonInterface that uses the on-event hooks to log to the console
class LoggingPythonInterface(interpreter: String, pythonPaths: Seq[String], console: ConsoleView)
extends ProtobufStdioSubprocess(interpreter = interpreter, pythonPaths = pythonPaths) {
class LoggingPythonInterface(interpreter: String, cwd: Option[File], pythonPaths: Seq[String], console: ConsoleView)
extends ProtobufStdioSubprocess(interpreter = interpreter, cwd = cwd, pythonPaths = pythonPaths) {
def forwardProcessOutput(): Unit = {
StreamUtils.forAvailable(outputStream) { data =>
console.print(new String(data), ConsoleViewContentType.NORMAL_OUTPUT)
Expand Down Expand Up @@ -170,9 +170,9 @@ class LoggingCompilerInterface(interface: LoggingPythonInterface, console: Conso
}

object CompileProcessHandler {
// Returns the interpreter executable from the SDK, Python paths, and the SDK name,
// Returns the interpreter executable from the SDK, working directory, Python paths, and the SDK name,
// for the Python class associated with the design
def getPythonInterpreter(project: Project, designName: String): Errorable[(String, Seq[String], String)] =
def getPythonInterpreter(project: Project, designName: String): Errorable[(String, String, Seq[String], String)] =
exceptable {
ReadAction.compute(() => {
val pyPsi = PyPsiFacade.getInstance(project)
Expand All @@ -183,16 +183,17 @@ object CompileProcessHandler {
val module = ModuleUtilCore.findModuleForPsiElement(pyClass).exceptNull("can't find project module")
val sdk = PythonSdkUtil.findPythonSdk(module).exceptNull("can't find Python SDK")

val workingDir = pyClass.getContainingFile.getContainingDirectory.getVirtualFile.getPath
val runParams = new DesignTopRunParams(
pyClass.getContainingFile.getVirtualFile.getPath,
workingDir,
sdk.getHomePath,
module.getName
)
val pythonCommand = PythonCommandLineState
.getInterpreterPath(project, runParams)
.exceptNull("can't get interpreter path")
val pythonPaths = PythonCommandLineState.collectPythonPath(module)
(pythonCommand, pythonPaths.asScala.toSeq, sdk.getName)
(pythonCommand, workingDir, pythonPaths.asScala.toSeq, sdk.getName)
})
}
}
Expand Down Expand Up @@ -314,7 +315,7 @@ class CompileProcessHandler(
var exitCode: Int = -1

try {
val (pythonCommand, pythonPaths, sdkName) =
val (pythonCommand, workingDir, pythonPaths, sdkName) =
CompileProcessHandler
.getPythonInterpreter(project, options.designName)
.mapErr(msg => s"while getting Python interpreter path: $msg")
Expand All @@ -323,7 +324,7 @@ class CompileProcessHandler(
s"Using interpreter from configured SDK '$sdkName': $pythonCommand\n",
ConsoleViewContentType.LOG_INFO_OUTPUT
)
val pythonProcess = new LoggingPythonInterface(pythonCommand, pythonPaths, console)
val pythonProcess = new LoggingPythonInterface(pythonCommand, Some(new File(workingDir)), pythonPaths, console)
val pythonInterface = new LoggingCompilerInterface(pythonProcess, console)
pythonProcessOpt = Some(pythonProcess)

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/edg_ide/runner/DseProcessHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class DseProcessHandler(project: Project, options: DseRunConfigurationOptions, v
var exitCode: Int = -1

try {
val (pythonCommand, pythonPaths, sdkName) =
val (pythonCommand, workingDir, pythonPaths, sdkName) =
CompileProcessHandler
.getPythonInterpreter(project, options.designName)
.mapErr(msg => s"while getting Python interpreter path: $msg")
Expand All @@ -164,7 +164,7 @@ class DseProcessHandler(project: Project, options: DseRunConfigurationOptions, v
ConsoleViewContentType.LOG_INFO_OUTPUT
)

val pythonProcess = new LoggingPythonInterface(pythonCommand, pythonPaths, console)
val pythonProcess = new LoggingPythonInterface(pythonCommand, Some(new File(workingDir)), pythonPaths, console)
val pythonInterface = new LoggingCompilerInterface(pythonProcess, console)
pythonProcessOpt = Some(pythonProcess)

Expand Down

0 comments on commit c7f7271

Please sign in to comment.