Skip to content

Commit ad3f98b

Browse files
committed
purge GRAAL_PYTHON_ARGS only if it ends with \v, because we're already using this to pass things to subprocesses
(cherry picked from commit d6371f1)
1 parent ab967df commit ad3f98b

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,8 @@ protected void printHelp(OptionCategory maxCategory) {
964964
" commandline. Arguments are split on whitespace - you can use \" and/or ' as required to\n" +
965965
" group them. Alternatively, if the value starts with a vertical tab character, the entire\n" +
966966
" value is split at vertical tabs and the elements are used as arguments without any further\n" +
967-
" escaping.\n" +
967+
" escaping. If the value ends with a vertical tab, it is also purged from the environment\n" +
968+
" when the interpreter runs, so that GraalPy subprocess will not pick it up\n" +
968969
" There are two special substitutions for this variable: any `$$' in the value is replaced\n" +
969970
" with the current process id, and any $UUID$ is replaced with random unique string\n" +
970971
" that may contain letters, digits, and '-'. To pass a literal `$$', you must escape the\n" +

graalpython/com.oracle.graal.python.test/src/tests/test_subprocess.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,14 @@ def test_graal_python_args(self):
169169
env = {"GRAAL_PYTHON_ARGS": """\v-c\vprint('Hello', "world")"""}
170170
result = subprocess.check_output([sys.executable], env=env, text=True)
171171
assert result == 'Hello world\n'
172+
173+
# check that the subprocess receives the args and thus it should fail because it recurses
174+
args = """\v-c\vimport os\nprint(os.environ.get("GRAAL_PYTHON_ARGS"))"""
175+
env = {"GRAAL_PYTHON_ARGS": args}
176+
result = subprocess.check_output([sys.executable], env=env, text=True)
177+
assert result == f"{args}\n"
178+
179+
# check that the subprocess does not receive the args when we end with \v
180+
env = {"GRAAL_PYTHON_ARGS": """\v-c\vimport os\nprint(os.environ.get("GRAAL_PYTHON_ARGS"))\v"""}
181+
result = subprocess.check_output([sys.executable], env=env, text=True, timeout=10)
182+
assert result == 'None\n'

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public void postInitialize(Python3Core core) {
314314
PDict environ = core.factory().createDict();
315315
String pyenvLauncherKey = "__PYVENV_LAUNCHER__";
316316
for (Entry<String, String> entry : getenv.entrySet()) {
317-
if (entry.getKey().equals("GRAAL_PYTHON_ARGS")) {
317+
if (entry.getKey().equals("GRAAL_PYTHON_ARGS") && entry.getValue().endsWith("\013")) {
318318
// was already processed at startup in GraalPythonMain and
319319
// we don't want subprocesses to pick it up
320320
continue;

graalpython/lib-graalpython/modules/standalone/app/graalpy.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ for var in "$@"; do
6262
done
6363

6464
curdir=`pwd`
65-
export GRAAL_PYTHON_ARGS=$args
66-
echo graalpy.sh is going to execute: mvn -f "${location}/pom.xml" exec:exec -Dexec.executable=$JAVA -Dexec.workingdir="${curdir}" -Dexec.args="--module-path %classpath '-Dorg.graalvm.launcher.executablename=$0' --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain"
65+
export GRAAL_PYTHON_ARGS="${args}$(printf "\v")"
6766
mvn -f "${location}/pom.xml" exec:exec -Dexec.executable="${JAVA}" -Dexec.workingdir="${curdir}" -Dexec.args="--module-path %classpath '-Dorg.graalvm.launcher.executablename=$0' --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain"

0 commit comments

Comments
 (0)