From 31c01632cbb2bf48da10468926d7be2b6fb41b53 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Tue, 28 May 2024 19:34:56 +0200 Subject: [PATCH] correct error on windows regarding the path --- .../modelrunner/apposed/appose/Mamba.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/apposed/appose/Mamba.java b/src/main/java/io/bioimage/modelrunner/apposed/appose/Mamba.java index 87285177..91039828 100644 --- a/src/main/java/io/bioimage/modelrunner/apposed/appose/Mamba.java +++ b/src/main/java/io/bioimage/modelrunner/apposed/appose/Mamba.java @@ -973,12 +973,16 @@ public void runPythonIn( final String envName, final String... args ) throws IOE if (!installed) throw new MambaInstallException("Micromamba is not installed"); final List< String > cmd = getBaseCommand(); List argsList = new ArrayList(); - if ( envName.equals( DEFAULT_ENVIRONMENT_NAME ) ) - argsList.add( PYTHON_COMMAND ); - else if (new File(envName).isDirectory()) - argsList.add( coverArgWithDoubleQuotes(Paths.get( envName, PYTHON_COMMAND ).toString()) ); - else - argsList.add( coverArgWithDoubleQuotes(Paths.get( this.envsdir, envName, PYTHON_COMMAND ).toString()) ); + String envDir; + if (new File(envName, PYTHON_COMMAND).isFile()) { + argsList.add( coverArgWithDoubleQuotes(Paths.get( envName, PYTHON_COMMAND ).toAbsolutePath().toString()) ); + envDir = Paths.get( envName ).toAbsolutePath().toString(); + } else if (Paths.get( this.envsdir, envName, PYTHON_COMMAND ).toFile().isFile()) { + argsList.add( coverArgWithDoubleQuotes(Paths.get( this.envsdir, envName, PYTHON_COMMAND ).toAbsolutePath().toString()) ); + envDir = Paths.get( envsdir, envName ).toAbsolutePath().toString(); + } else + throw new IOException("The environment provided (" + + envName + ") does not exist or does not contain a Python executable (" + PYTHON_COMMAND + ")."); argsList.addAll( Arrays.asList( args ).stream().map(aa -> { if (aa.contains(" ") && PlatformDetection.isWindows()) return coverArgWithDoubleQuotes(aa); else return aa; @@ -992,7 +996,6 @@ else if (new File(envName).isDirectory()) if ( PlatformDetection.isWindows() ) { final Map< String, String > envs = builder.environment(); - final String envDir = Paths.get( rootdir, ENVS_NAME, envName ).toString(); envs.put( "Path", envDir + ";" + envs.get( "Path" ) ); envs.put( "Path", Paths.get( envDir, "Scripts" ).toString() + ";" + envs.get( "Path" ) ); envs.put( "Path", Paths.get( envDir, "Library" ).toString() + ";" + envs.get( "Path" ) );