Skip to content

Commit 9f6f49c

Browse files
committed
[GR-13591] install pip in venv
PullRequest: graalpython/428
2 parents e363595 + a0a3a13 commit 9f6f49c

File tree

18 files changed

+121
-91
lines changed

18 files changed

+121
-91
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
This changelog summarizes major changes between GraalVM versions of the Python
44
language runtime. The main focus is on user-observable behavior of the engine.
55

6+
## Version 1.0.0 RC14
7+
8+
* Mark a subset of the Graal Python launcher options as "stable". All other options are subject to change and need to be unlocked explicitly on the commandline.
9+
* Automatically install pip when creating a venv. The socket and ssl libraries are still not functional, so pip can only install from local sources or wheels.
10+
* Update the standard library to Python 3.7.0 from 3.6.5.
11+
* Support the `-I` flag to ignore the user environment and not add the working directory to `sys.path`
12+
* Fix an error preventing usage of the memtracer tool. If an object raised an exception in it's `__repr__` method, it would abort the execution.
13+
* Fix issues around not being able to modify function defaults, keyword defaults, or re-defining a function with a different closure.
14+
* Fix continuation prompt in the interactive Python shell when an incomplete statement was typed. Before it raised and ignored a SyntaxError.
15+
* Fix frame restarting of Python functions in the Chrome debugger. Before, functions with closures would have their cells accidentally cleared.
16+
617
## Version 1.0.0 RC13
718

819
* Support marshal.dumps and marshal.loads for code objects and some other built-in objects

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static void main(String[] args) {
6363
private ArrayList<String> programArgs = null;
6464
private String commandString = null;
6565
private String inputFile = null;
66+
private boolean isolateFlag = false;
6667
private boolean ignoreEnv = false;
6768
private boolean inspectFlag = false;
6869
private boolean verboseFlag = false;
@@ -128,6 +129,11 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
128129
case "-q":
129130
quietFlag = true;
130131
break;
132+
case "-I":
133+
noUserSite = true;
134+
ignoreEnv = true;
135+
isolateFlag = true;
136+
break;
131137
case "-s":
132138
noUserSite = true;
133139
break;
@@ -231,8 +237,10 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
231237
break;
232238
} else if (!arg.startsWith("--") && arg.length() > 2) {
233239
// short arguments can be given together
234-
for (String optionChar : arg.substring(1).split("")) {
235-
arguments.add(i + 1, "-" + optionChar);
240+
String[] split = arg.substring(1).split("");
241+
for (int j = 0; j < split.length; j++) {
242+
String optionChar = split[j];
243+
arguments.add(i + 1 + j, "-" + optionChar);
236244
}
237245
} else {
238246
// possibly a polyglot argument
@@ -396,6 +404,7 @@ protected void launch(Builder contextBuilder) {
396404
contextBuilder.option("python.AlwaysRunExcepthook", "true");
397405
contextBuilder.option("python.InspectFlag", Boolean.toString(inspectFlag));
398406
contextBuilder.option("python.VerboseFlag", Boolean.toString(verboseFlag));
407+
contextBuilder.option("python.IsolateFlag", Boolean.toString(isolateFlag));
399408
if (verboseFlag) {
400409
contextBuilder.option("log.python.level", "FINE");
401410
}
@@ -557,6 +566,7 @@ protected void printHelp(OptionCategory maxCategory) {
557566
// "-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n"
558567
// +
559568
"-q : don't print version and copyright messages on interactive startup\n" +
569+
"-I : don't add user site and script directory to sys.path; also PYTHONNOUSERSITE\n" +
560570
"-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n" +
561571
"-S : don't imply 'import site' on initialization\n" +
562572
// "-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n"

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ public static OptionsChecker[] input() {
534534
new OptionsChecker("PythonOptimizeFlag", "import sys; sys.flags.debug", "true", "false"),
535535
new OptionsChecker("PythonOptimizeFlag", "import sys; sys.flags.optimize", "true", "false"),
536536
new OptionsChecker("PythonOptimizeFlag", "__debug__", "true", "false"),
537-
new OptionsChecker("Executable", "import sys; sys.executable", "graalpython", "python3")
537+
new OptionsChecker("Executable", "import sys; sys.executable", "graalpython", "python3"),
538+
new OptionsChecker("IsolateFlag", "import sys; sys.flags.isolated", "true", "false")
538539
};
539540
}
540541

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ Object doit(PByteArray bytes,
156156
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
157157
return marshaller.execute(toBytesNode.execute(bytes), CURRENT_VERSION);
158158
}
159+
160+
@SuppressWarnings("unused")
161+
@Specialization
162+
Object doit(PMemoryView bytes,
163+
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
164+
return marshaller.execute(toBytesNode.execute(bytes), CURRENT_VERSION);
165+
}
159166
}
160167

161168
private static final char TYPE_NULL = '0';

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,11 @@ abstract static class UmaskNode extends PythonBuiltinNode {
16331633
int getAndSetUmask(int umask) {
16341634
if (umask == 0022) {
16351635
return 0022;
1636+
}
1637+
if (umask == 0) {
1638+
// TODO: change me, this does not really set the umask, workaround needed for pip
1639+
// it returns the previous mask (which in our case is always 0022)
1640+
return 0022;
16361641
} else {
16371642
throw raise(NotImplementedError, "setting the umask to anything other than the default");
16381643
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private static final class LocalData implements TruffleObject {
8585
private final List<String> history = new ArrayList<>();
8686
protected Object completer = null;
8787
public boolean autoHistory = true;
88+
public String completerDelims = null;
8889

8990
public ForeignAccess getForeignAccess() {
9091
return null;
@@ -345,4 +346,27 @@ PNone setCompleter(PythonModule self, boolean enabled,
345346
return PNone.NONE;
346347
}
347348
}
349+
350+
@Builtin(name = "set_completer_delims", minNumOfPositionalArgs = 2, declaresExplicitSelf = true)
351+
@GenerateNodeFactory
352+
abstract static class SetCompleterDelimsNode extends PythonBinaryBuiltinNode {
353+
@Specialization
354+
PNone setCompleterDelims(PythonModule self, String completerDelims,
355+
@Cached("create()") ReadAttributeFromObjectNode readNode) {
356+
LocalData data = (LocalData) readNode.execute(self, DATA);
357+
data.completerDelims = completerDelims;
358+
return PNone.NONE;
359+
}
360+
}
361+
362+
@Builtin(name = "get_completer_delims", minNumOfPositionalArgs = 1, declaresExplicitSelf = true)
363+
@GenerateNodeFactory
364+
abstract static class GetCompleterDelimsNode extends PythonBuiltinNode {
365+
@Specialization
366+
Object getCompleterDelims(PythonModule self,
367+
@Cached("create()") ReadAttributeFromObjectNode readNode) {
368+
LocalData data = (LocalData) readNode.execute(self, DATA);
369+
return (data.completerDelims != null) ? data.completerDelims : PNone.NONE;
370+
}
371+
}
348372
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ public void postInitialize(PythonCore core) {
180180
sys.setAttribute("graal_python_stdlib_home", PythonOptions.getOption(context, PythonOptions.StdLibHome));
181181
sys.setAttribute("graal_python_opaque_filesystem", PythonOptions.getOption(context, PythonOptions.OpaqueFilesystem));
182182
sys.setAttribute("graal_python_opaque_filesystem_prefix", PythonOptions.getOption(context, PythonOptions.OpaqueFilesystemPrefixes));
183-
sys.setAttribute("graal_python_unbuffered_io", PythonOptions.getOption(context, PythonOptions.UnbufferedIO));
184183
sys.setAttribute("__flags__", core.factory().createTuple(new Object[]{
185184
false, // bytes_warning
186185
!PythonOptions.getFlag(context, PythonOptions.PythonOptimizeFlag), // debug
@@ -189,7 +188,7 @@ public void postInitialize(PythonCore core) {
189188
PythonOptions.getFlag(context, PythonOptions.IgnoreEnvironmentFlag), // ignore_environment
190189
PythonOptions.getFlag(context, PythonOptions.InspectFlag), // inspect
191190
PythonOptions.getFlag(context, PythonOptions.TerminalIsInteractive), // interactive
192-
!context.isExecutableAccessAllowed(), // isolated
191+
PythonOptions.getFlag(context, PythonOptions.IsolateFlag), // isolated
193192
PythonOptions.getFlag(context, PythonOptions.NoSiteFlag), // no_site
194193
PythonOptions.getFlag(context, PythonOptions.NoUserSiteFlag), // no_user_site
195194
PythonOptions.getFlag(context, PythonOptions.PythonOptimizeFlag), // optimize
@@ -203,17 +202,21 @@ public void postInitialize(PythonCore core) {
203202
String option = PythonOptions.getOption(context, PythonOptions.PythonPath);
204203
Object[] path;
205204
int pathIdx = 0;
205+
boolean doIsolate = PythonOptions.getOption(context, PythonOptions.IsolateFlag);
206+
int defaultPaths = doIsolate ? 2 : 3;
206207
if (option.length() > 0) {
207208
String[] split = option.split(PythonCore.PATH_SEPARATOR);
208-
path = new Object[split.length + 3];
209+
path = new Object[split.length + defaultPaths];
209210
System.arraycopy(split, 0, path, 0, split.length);
210211
pathIdx = split.length;
211212
} else {
212-
path = new Object[3];
213+
path = new Object[defaultPaths];
213214
}
214-
path[pathIdx] = getScriptPath(env, args);
215-
path[pathIdx + 1] = PythonCore.getStdlibHome(env);
216-
path[pathIdx + 2] = PythonCore.getCoreHome(env) + PythonCore.FILE_SEPARATOR + "modules";
215+
if (!doIsolate) {
216+
path[pathIdx++] = getScriptPath(env, args);
217+
}
218+
path[pathIdx++] = PythonCore.getStdlibHome(env);
219+
path[pathIdx++] = PythonCore.getCoreHome(env) + PythonCore.FILE_SEPARATOR + "modules";
217220
PList sysPaths = core.factory().createList(path);
218221
sys.setAttribute("path", sysPaths);
219222
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesUtils.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -199,13 +199,18 @@ public static StringBuilder decodeEscapes(ParserErrorCallback errors, String str
199199
}
200200
throw errors.raise(ValueError, "invalid \\x escape at position %d", i);
201201
default:
202-
if (regexMode && (chr == '\\' || chr == 'g' || (chr >= '0' && chr <= '9'))) {
203-
// only allow backslashes, named group references and numbered group
204-
// references in regex mode
202+
if (regexMode) {
203+
if (chr == 'g' || (chr >= '0' && chr <= '9')) {
204+
// only allow backslashes, named group references and numbered group
205+
// references in regex mode
206+
charList.append('\\');
207+
charList.append(chr);
208+
} else {
209+
throw errors.raise(ValueError, "invalid escape sequence '\\%s' at position %d", chr, i);
210+
}
211+
} else {
205212
charList.append('\\');
206213
charList.append(chr);
207-
} else {
208-
throw errors.raise(ValueError, "invalid escape sequence '\\%s' at position %d", chr, i);
209214
}
210215
}
211216
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ private PythonOptions() {
8888
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -u flag. Force stdout and stderr to be unbuffered.", stability = OptionStability.STABLE) //
8989
public static final OptionKey<Boolean> UnbufferedIO = new OptionKey<>(false);
9090

91+
@Option(category = OptionCategory.USER, help = "Equivalent to the Python -I flag. Isolate from the users environment by not adding the cwd to the path", stability = OptionStability.STABLE) //
92+
public static final OptionKey<Boolean> IsolateFlag = new OptionKey<>(false);
93+
9194
@Option(category = OptionCategory.INTERNAL, help = "Expose internal sources as normal sources, so they will show up in the debugger and stacks") //
9295
public static final OptionKey<Boolean> ExposeInternalSources = new OptionKey<>(false);
9396

graalpython/lib-python/3/platform.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def libc_ver(executable=sys.executable, lib='', version='',
161161
The file is read and scanned in chunks of chunksize bytes.
162162
163163
"""
164+
if sys.implementation.name == "graalpython":
165+
if executable == sys.executable and not os.path.exists(executable):
166+
return lib, version
164167
if hasattr(os.path, 'realpath'):
165168
# Python 2.2 introduced os.path.realpath(); it is used
166169
# here to work around problems with Cygwin not being

0 commit comments

Comments
 (0)