Skip to content

Commit 0f70c99

Browse files
committed
[GR-55528] Fix parsing pyvenv.cfg home property according to PEP 405
1 parent 430fcd3 commit 0f70c99

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
1212
* `polyglot.eval` now raises more meaningful exceptions. Unavaliable languages raise `ValueError`. Exceptions from the polyglot language are raised directly as interop objects (typed as `polyglot.ForeignException`). The shortcut for executing python files without specifying language has been removed, use regular `eval` for executing Python code.
1313
* In Jython emulation mode we now magically fall back to calling Java getters or setters when using Python attribute access for non-visible properties. This can help migrating away from Jython if you relied on this behavior.
1414
* The option `python.EmulateJython` to enable Jython emulation is now marked as stable, and can thus be relied upon in production.
15+
* Fixed parsing of pyvenv.cfg according to PEP 405, which is required to use [uv](https://github.com/astral-sh/uv?tab=readme-ov-file#uv) generated venvs with GraalPy.
1516

1617
## Version 24.0.0
1718
* We now provide a collection of recipes in the form of GitHub Actions to build popular native extensions on GraalPy. These provide a reproducible way for the community to build native extensions for GraalPy with the correct dependencies. See scripts/wheelbuilder/README.md for details.

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,26 @@ private void findAndApplyVenvCfg(Builder contextBuilder, String executable) {
907907
}
908908
String name = parts[0].trim();
909909
if (name.equals("home")) {
910-
contextBuilder.option("python.PythonHome", parts[1].trim());
910+
Path homeProperty = Paths.get(parts[1].trim());
911+
/*
912+
* (tfel): According to PEP 405, the home key is the directory of the Python
913+
* executable from which this virtual environment was created, that is, it
914+
* usually ends with "/bin" on a Unix system. On Windows, the base Python should
915+
* be in the top-level directory or under "\Scripts". To support running from
916+
* Maven artifacts where we don't have a working executable, we patched our
917+
* shipped venv module to set the home path without a "/bin" or "\\Scripts"
918+
* suffix, so we explicitly check for those two subfolder cases and otherwise
919+
* assume the home key is directly pointing to the Python home.
920+
*/
921+
if (homeProperty.endsWith("bin") || homeProperty.endsWith("Scripts")) {
922+
homeProperty = homeProperty.getParent();
923+
}
924+
try {
925+
contextBuilder.option("python.PythonHome", homeProperty.toString());
926+
} catch (NullPointerException ex) {
927+
// NullPointerException covers the possible null result of getParent()
928+
warn("Could not set PYTHONHOME according to the pyvenv.cfg file.");
929+
}
911930
String sysPrefix = null;
912931
try {
913932
sysPrefix = venvCfg.getParent().toAbsolutePath().toString();

0 commit comments

Comments
 (0)