@@ -931,54 +931,70 @@ private void findAndApplyVenvCfg(Builder contextBuilder, String executable) {
931931 continue ;
932932 }
933933 String name = parts [0 ].trim ();
934- if (name .equals ("home" )) {
935- try {
936- Path homeProperty = Paths .get (parts [1 ].trim ());
937- Path graalpyHome = homeProperty ;
938- /*
939- * (tfel): According to PEP 405, the home key is the directory of the Python
940- * executable from which this virtual environment was created, that is, it
941- * usually ends with "/bin" on a Unix system. On Windows, the base Python
942- * should be in the top-level directory or under "\Scripts". To support
943- * running from Maven artifacts where we don't have a working executable, we
944- * patched our shipped venv module to set the home path without a "/bin" or
945- * "\\Scripts" suffix, so we explicitly check for those two subfolder cases
946- * and otherwise assume the home key is directly pointing to the Python
947- * home.
948- */
949- if (graalpyHome .endsWith ("bin" ) || graalpyHome .endsWith ("Scripts" )) {
950- graalpyHome = graalpyHome .getParent ();
951- }
952- contextBuilder .option ("python.PythonHome" , graalpyHome .toString ());
953- /*
954- * First try to resolve symlinked executables, since that may be more
955- * accurate than assuming the executable in 'home'.
956- */
957- Path baseExecutable = null ;
934+ switch (name ) {
935+ case "home" :
958936 try {
959- Path realPath = executablePath .toRealPath ();
960- if (!realPath .equals (executablePath .toAbsolutePath ())) {
961- baseExecutable = realPath ;
937+ Path homeProperty = Paths .get (parts [1 ].trim ());
938+ Path graalpyHome = homeProperty ;
939+ /*
940+ * (tfel): According to PEP 405, the home key is the directory of the
941+ * Python executable from which this virtual environment was created,
942+ * that is, it usually ends with "/bin" on a Unix system. On Windows,
943+ * the base Python should be in the top-level directory or under
944+ * "\Scripts". To support running from Maven artifacts where we don't
945+ * have a working executable, we patched our shipped venv module to set
946+ * the home path without a "/bin" or "\\Scripts" suffix, so we
947+ * explicitly check for those two subfolder cases and otherwise assume
948+ * the home key is directly pointing to the Python home.
949+ */
950+ if (graalpyHome .endsWith ("bin" ) || graalpyHome .endsWith ("Scripts" )) {
951+ graalpyHome = graalpyHome .getParent ();
962952 }
963- } catch (IOException ex ) {
964- // Ignore
965- }
966- if (baseExecutable == null ) {
967- baseExecutable = homeProperty .resolve (executablePath .getFileName ());
968- }
969- if (Files .exists (baseExecutable )) {
970- contextBuilder .option ("python.BaseExecutable" , baseExecutable .toString ());
953+ contextBuilder .option ("python.PythonHome" , graalpyHome .toString ());
971954 /*
972- * This is needed to support the legacy GraalVM layout where the
973- * executable is a symlink into the 'languages' directory .
955+ * First try to resolve symlinked executables, since that may be more
956+ * accurate than assuming the executable in 'home' .
974957 */
975- contextBuilder .option ("python.PythonHome" , baseExecutable .getParent ().getParent ().toString ());
958+ Path baseExecutable = null ;
959+ try {
960+ Path realPath = executablePath .toRealPath ();
961+ if (!realPath .equals (executablePath .toAbsolutePath ())) {
962+ baseExecutable = realPath ;
963+ }
964+ } catch (IOException ex ) {
965+ // Ignore
966+ }
967+ if (baseExecutable == null ) {
968+ baseExecutable = homeProperty .resolve (executablePath .getFileName ());
969+ }
970+ if (Files .exists (baseExecutable )) {
971+ contextBuilder .option ("python.BaseExecutable" , baseExecutable .toString ());
972+ /*
973+ * This is needed to support the legacy GraalVM layout where the
974+ * executable is a symlink into the 'languages' directory.
975+ */
976+ contextBuilder .option ("python.PythonHome" , baseExecutable .getParent ().getParent ().toString ());
977+ }
978+ } catch (NullPointerException | InvalidPathException ex ) {
979+ // NullPointerException covers the possible null result of getParent()
980+ warn ("Could not set PYTHONHOME according to the pyvenv.cfg file." );
976981 }
977- } catch (NullPointerException | InvalidPathException ex ) {
978- // NullPointerException covers the possible null result of getParent()
979- warn ("Could not set PYTHONHOME according to the pyvenv.cfg file." );
980- }
981- break ;
982+ break ;
983+ case "venvlauncher_command" :
984+ if (!hasContextOptionSetViaCommandLine ("VenvlauncherCommand" )) {
985+ contextBuilder .option ("python.VenvlauncherCommand" , parts [1 ].trim ());
986+ }
987+ break ;
988+ case "base-prefix" :
989+ if (!hasContextOptionSetViaCommandLine ("SysBasePrefix" )) {
990+ contextBuilder .option ("python.SysBasePrefix" , parts [1 ].trim ());
991+ }
992+ break ;
993+ case "base-executable" :
994+ if (!hasContextOptionSetViaCommandLine ("BaseExecutable" )) {
995+ contextBuilder .option ("python.BaseExecutable" , parts [1 ].trim ());
996+ }
997+ break ;
982998 }
983999 }
9841000 } catch (IOException ex ) {
0 commit comments