Skip to content

Commit 8f5b0b7

Browse files
committed
[GR-12983] [GR-12033] Some patches to get setuptools install and --help to work
PullRequest: graalpython/326
2 parents 6456c83 + f643ff7 commit 8f5b0b7

File tree

34 files changed

+763
-157
lines changed

34 files changed

+763
-157
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
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 RC11
7+
8+
* Support running setuptools to build and install various packages
9+
* Support running a source release version of NumPy out of the box
10+
* Improve performance of member access to C API objects
11+
* Improve performance of binary operations on C API objects
12+
* Add support for `yield from`
13+
* Support assignment to `object.__dict__` and ensure that managed subclasses of native types also have a `__dict__`
14+
* Fix `[]` access with non-integer keys for array-like foreign objects
15+
* Fix various performance regressions introduced in the last RC
16+
* Implement more built-in methods on the `time` module
17+
* Python no longer exposes internal languages through `polyglot.eval`
18+
* Improve performance of `os.scandir` and functions that build on it (such as `glob`)
19+
* More correct implementation of standard streams, including buffering
20+
* Properly support the `-m` switch to run modules
21+
* Support creating ZIP files through the standard `zipfile` module
22+
623
## Version 1.0.0 RC10
724

825
* Improve performance of C API upcalls

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public static void main(String[] args) {
6262
private ArrayList<String> programArgs = null;
6363
private String commandString = null;
6464
private String inputFile = null;
65-
private String module = null;
6665
private boolean ignoreEnv = false;
6766
private boolean inspectFlag = false;
6867
private boolean verboseFlag = false;
@@ -104,9 +103,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
104103
inspectFlag = true;
105104
break;
106105
case "-m":
107-
i += 1;
108-
if (i < arguments.size()) {
109-
module = arguments.get(i);
106+
if (i + 1 < arguments.size()) {
107+
// don't increment i here so that we capture the correct args
108+
String module = arguments.get(i + 1);
109+
commandString = "import runpy; runpy._run_module_as_main('" + module + "')";
110110
} else {
111111
print("Argument expected for the -m option");
112112
printShortHelp();
@@ -179,7 +179,7 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
179179
}
180180
}
181181

182-
if (inputFile != null || commandString != null || module != null) {
182+
if (inputFile != null || commandString != null) {
183183
i += 1;
184184
if (i < arguments.size()) {
185185
programArgs.addAll(arguments.subList(i, arguments.size()));
@@ -252,7 +252,7 @@ protected void launch(Builder contextBuilder) {
252252
try (Context context = contextBuilder.build()) {
253253
runVersionAction(versionAction, context.getEngine());
254254

255-
if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && module == null && stdinIsInteractive))) {
255+
if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && stdinIsInteractive))) {
256256
print("Python " + evalInternal(context, "import sys; sys.version + ' on ' + sys.platform").asString());
257257
if (!noSite) {
258258
print("Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.");

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/SpecialMethodTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void __add__0() {
3939
" def __add__(self, other):\n" + //
4040
" return Num(self.n + other.n)\n" + //
4141
" def __repr__(self):\n" + //
42-
" return self.n\n" + //
42+
" return str(self.n)\n" + //
4343
"" + //
4444
"n0 = Num(42)\n" + //
4545
"n1 = Num(1)\n" + //
@@ -55,7 +55,7 @@ public void __add__1() {
5555
" def __add__(self, other):\n" + //
5656
" return Num(self.n + other)\n" + //
5757
" def __repr__(self):\n" + //
58-
" return self.n\n" + //
58+
" return str(self.n)\n" + //
5959
"" + //
6060
"n0 = Num(42)\n" + //
6161
"print(n0 + 1)\n";
@@ -70,7 +70,7 @@ public void __add__2() {
7070
" def __radd__(self, other):\n" + //
7171
" return Num(self.n + other)\n" + //
7272
" def __repr__(self):\n" + //
73-
" return self.n\n" + //
73+
" return str(self.n)\n" + //
7474
"" + //
7575
"n0 = Num(42)\n" + //
7676
"print(1 + n0)\n";
@@ -87,7 +87,7 @@ public void __add__And__rand__Polymorphic() {
8787
" def __radd__(self, other):\n" + //
8888
" return Num(self.n + other)\n" + //
8989
" def __repr__(self):\n" + //
90-
" return self.n\n" + //
90+
" return str(self.n)\n" + //
9191
"" + //
9292
"def doAdd(left, right):\n" + //
9393
" return left + right\n" + //
@@ -104,7 +104,7 @@ public void __sub__() {
104104
" def __sub__(self, other):\n" + //
105105
" return Num(self.n - other.n)\n" + //
106106
" def __repr__(self):\n" + //
107-
" return self.n\n" + //
107+
" return str(self.n)\n" + //
108108
"" + //
109109
"n0 = Num(42)\n" + //
110110
"n1 = Num(1)\n" + //
@@ -120,7 +120,7 @@ public void __eq__() {
120120
" def __eq__(self, other):\n" + //
121121
" return type(self) == type(other) and self.n == other.n\n" + //
122122
" def __repr__(self):\n" + //
123-
" return self.n\n" + //
123+
" return str(self.n)\n" + //
124124
"" + //
125125
"n0 = Num(1)\n" + //
126126
"n1 = Num(1)\n" + //

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/module/PosixTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,22 @@ public void close() throws IOException {
153153

154154
@Test
155155
public void stdout() {
156-
assertPrints("hello", "import sys; sys.stdout.write('hello')");
156+
assertPrints("hello\n", "import sys; sys.stdout.write('hello\\n')");
157157
}
158158

159159
@Test
160160
public void stderr() {
161-
assertLastLineError("error", "import sys; sys.stderr.write('error')");
161+
assertLastLineError("error\n", "import sys; sys.stderr.write('error\\n')");
162162
}
163163

164164
@Test
165165
public void printToStdout() {
166-
assertPrints("1-2...", "import sys; print('1', '2', sep='-', file=sys.stdout, end='...')");
166+
assertPrints("1-2...", "import sys; print('1', '2', sep='-', file=sys.stdout, end='...', flush=True)");
167167
}
168168

169169
@Test
170170
public void printToStderr() {
171-
assertLastLineError("1-2...", "import sys; print('1', '2', sep='-', file=sys.stderr, end='...')");
171+
assertLastLineError("1-2...", "import sys; print('1', '2', sep='-', file=sys.stderr, end='...', flush=True)");
172172
}
173173

174174
@Test

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ def test_map2():
5858
items0 = [0, 1, 2, 3, 4]
5959
items1 = [5, 6, 7, 8, 9]
6060
assert list(map(lambda x, y: x * y, items0, items1)) == [0, 6, 14, 24, 36]
61+
62+
63+
def test_map_contains():
64+
assert 1 in map(lambda s: s, [1])
65+
assert 2 not in map(lambda s: s, [1])
66+
67+
class X():
68+
def __iter__(self):
69+
return self
70+
71+
def __next__(self):
72+
i = getattr(self, "i", 0)
73+
if i == 1:
74+
raise StopIteration
75+
else:
76+
self.i = i + 1
77+
return i
78+
79+
# the below checks that __contains__ consumes the iterator
80+
m = map(lambda s: s, X())
81+
assert 0 in m
82+
assert 0 not in m

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ def test_lambda_no_args_with_nested_lambdas():
8484
except Exception as e:
8585
no_err = False
8686
assert no_err
87+
88+
89+
def test_byte_numeric_escapes():
90+
assert eval('b"PK\\005\\006\\00\\11\\22\\08"') == b'PK\x05\x06\x00\t\x12\x008'

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_find():
5353
assert s.find('cau', MyIndexable(5), None) == 5
5454
assert s.find('cau', MyIndexable(5), MyIndexable(8)) == 5
5555
assert s.find('cau', None, MyIndexable(8)) == 5
56-
56+
5757

5858
def test_rfind():
5959
assert "test string test".rfind("test") == 12
@@ -749,7 +749,7 @@ def test_zfill(self):
749749
self.checkequal('0034', '34', 'zfill', 4)
750750

751751
self.checkraises(TypeError, '123', 'zfill')
752-
752+
753753
def test_zfill_specialization(self):
754754
self.checkequal('123', '123', 'zfill', True)
755755
self.checkequal('0123', '123', 'zfill', MyIndexable(4))
@@ -880,7 +880,7 @@ def test_count(self):
880880
if rem or r1 != r2:
881881
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
882882
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
883-
883+
884884

885885
def test_same_id():
886886
empty_ids = set([id(str()) for i in range(100)])
@@ -889,3 +889,21 @@ def test_same_id():
889889
assert len(empty_ids) == 1
890890
empty_ids = set([id(u'') for i in range(100)])
891891
assert len(empty_ids) == 1
892+
893+
894+
def test_translate():
895+
assert "abc".translate({ord("a"): "b"}) == "bbc"
896+
assert "abc".translate({ord("a"): "xxx"}) == "xxxbc"
897+
assert "abc".translate({ord("a"): ""}) == "bc"
898+
try:
899+
"abc".translate({ord("a"): 8**63})
900+
except (ValueError, TypeError) as e:
901+
assert "mapping must be in range" in str(e)
902+
else:
903+
assert False, "should raise"
904+
905+
906+
def test_splitlines():
907+
assert len(str.splitlines("\n\n")) == 2
908+
assert len(str.splitlines("\n")) == 1
909+
assert len(str.splitlines("a\nb")) == 2

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,16 @@ def test_vars():
7474
assert_raises(TypeError, vars, 42, 42)
7575
assert_raises(TypeError, vars, 42)
7676
assert vars(C_get_vars()) == {'a': 2}
77+
78+
79+
def test_vars_update():
80+
class X():
81+
pass
82+
83+
x = X()
84+
vars(x).update({"args": 42})
85+
assert vars(x)["args"] == 42
86+
assert x.__dict__["args"] == 42
87+
88+
vars().update({"arg": 12})
89+
assert locals()["arg"] == 12

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
import com.oracle.graal.python.builtins.modules.TruffleCextBuiltins;
8585
import com.oracle.graal.python.builtins.modules.UnicodeDataModuleBuiltins;
8686
import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins;
87-
import com.oracle.graal.python.builtins.modules.ZipImportModuleBuiltins;
8887
import com.oracle.graal.python.builtins.modules.ZLibModuleBuiltins;
88+
import com.oracle.graal.python.builtins.modules.ZipImportModuleBuiltins;
8989
import com.oracle.graal.python.builtins.objects.array.ArrayBuiltins;
9090
import com.oracle.graal.python.builtins.objects.bool.BoolBuiltins;
9191
import com.oracle.graal.python.builtins.objects.bytes.AbstractBytesBuiltins;
@@ -220,6 +220,7 @@ private static final String[] initializeCoreFiles() {
220220
"_socket",
221221
"_thread",
222222
"ctypes",
223+
"zlib",
223224
"zipimport"));
224225

225226
return coreFiles.toArray(new String[coreFiles.size()]);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Map.Entry;
3737
import java.util.function.BiConsumer;
3838

39+
import com.oracle.graal.python.builtins.objects.PNone;
3940
import com.oracle.graal.python.builtins.objects.function.Arity;
4041
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4142
import com.oracle.graal.python.builtins.objects.function.PythonCallable;
@@ -72,17 +73,18 @@ public void initialize(PythonCore core) {
7273
}
7374
RootCallTarget callTarget = core.getLanguage().builtinCallTargetCache.computeIfAbsent(factory.getNodeClass(),
7475
(b) -> Truffle.getRuntime().createCallTarget(new BuiltinFunctionRootNode(core.getLanguage(), builtin, factory, declaresExplicitSelf)));
76+
Object builtinDoc = builtin.doc().isEmpty() ? PNone.NONE : builtin.doc();
7577
if (builtin.constructsClass().length > 0) {
7678
assert !builtin.isGetter() && !builtin.isSetter() && !builtin.isClassmethod() && !builtin.isStaticmethod();
7779
PBuiltinFunction newFunc = core.factory().createBuiltinFunction(__NEW__, null, createArity(builtin, declaresExplicitSelf), callTarget);
7880
for (PythonBuiltinClassType type : builtin.constructsClass()) {
7981
PythonBuiltinClass builtinClass = core.lookupType(type);
8082
builtinClass.setAttributeUnsafe(__NEW__, newFunc);
81-
builtinClass.setAttribute(__DOC__, builtin.doc());
83+
builtinClass.setAttribute(__DOC__, builtinDoc);
8284
}
8385
} else {
8486
PBuiltinFunction function = core.factory().createBuiltinFunction(builtin.name(), null, createArity(builtin, declaresExplicitSelf), callTarget);
85-
function.setAttribute(__DOC__, builtin.doc());
87+
function.setAttribute(__DOC__, builtinDoc);
8688
BoundBuiltinCallable<?> callable = function;
8789
if (builtin.isGetter() || builtin.isSetter()) {
8890
assert !builtin.isClassmethod() && !builtin.isStaticmethod();

0 commit comments

Comments
 (0)