Skip to content

Commit 4705979

Browse files
committed
remove older lib-graalpython things and fix minimal running
1 parent cbe46bf commit 4705979

File tree

4 files changed

+69
-133
lines changed

4 files changed

+69
-133
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ private static String[] initializeCoreFiles() {
358358
// Order matters!
359359
List<String> coreFiles = new ArrayList<>(Arrays.asList(
360360
"type",
361-
"function",
362361
"__graalpython__",
363362
"_weakref",
364363
"faulthandler",

graalpython/lib-graalpython/builtins.py

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,73 @@
4444
def __gr__(self, name, mode='r', closefd=True, opener=None):
4545
pass
4646

47-
def __bootstrap_import__(filename, module_name):
48-
import sys, _imp, posix
49-
module = sys.modules[module_name]
50-
if filename.startswith("%s"):
51-
full_filename = filename % __graalpython__.core_home
52-
filename = filename[len("%s"):]
53-
elif filename.startswith(__graalpython__.stdlib_home):
54-
full_filename = filename
55-
filename = filename[len(__graalpython__.stdlib_home):]
56-
else:
57-
raise RuntimeError("There was an import during bootstrap outside the core or stdlib home.")
58-
59-
# If we can, avoid opening the file and use our cached code
60-
if not __graalpython__.has_cached_code(filename):
61-
content = __graalpython__.read_file(full_filename)
62-
code = compile(content, filename, "exec")
63-
else:
64-
# n.b.: for these builtin modules, there's never a full path and none of
65-
# them can be packages
66-
code = __graalpython__.get_cached_code(filename)
67-
68-
exec(code, module.__dict__)
69-
return module
70-
71-
72-
# # TODO(fa): This was formerly located in 'property.py' which has been intrinsified but seemingly other modules rely
73-
# # on 'descriptor'. We should revisit that.
47+
48+
# TODO(fa): This was formerly located in 'property.py' which has been intrinsified but seemingly other modules rely
49+
# on 'descriptor'. We should revisit that.
7450
def _f(): pass
7551
FunctionType = type(_f)
7652
descriptor = type(FunctionType.__code__)
7753

78-
__bootstrap_import__("%s/functions.py", "builtins")
54+
55+
from sys import _getframe as __getframe__
56+
57+
58+
@__graalpython__.builtin
59+
def vars(*obj):
60+
"""Return a dictionary of all the attributes currently bound in obj. If
61+
called with no argument, return the variables bound in local scope."""
62+
if len(obj) == 0:
63+
# TODO inlining _caller_locals().items() in the dict comprehension does not work for now, investigate!
64+
return __getframe__(0).f_locals
65+
elif len(obj) != 1:
66+
raise TypeError("vars() takes at most 1 argument.")
67+
try:
68+
return obj[0].__dict__
69+
except AttributeError:
70+
raise TypeError("vars() argument must have __dict__ attribute")
71+
72+
73+
@__graalpython__.builtin
74+
def input(prompt=None):
75+
import sys
76+
if(not hasattr(sys, "stdin")):
77+
raise RuntimeError('input(): lost sys.stdin')
78+
if(not hasattr(sys, "stdout")):
79+
raise RuntimeError('input(): lost sys.stdout')
80+
if(not hasattr(sys, "stderr")):
81+
raise RuntimeError('input(): lost sys.stderr')
82+
83+
if prompt is not None:
84+
print(prompt, end="", flush=hasattr(sys.stdout, "flush"))
85+
86+
result = []
87+
while True:
88+
ch = sys.stdin.read(1)
89+
if ch:
90+
if ch == "\n":
91+
break
92+
result.append(ch)
93+
else:
94+
if(len(result) == 0):
95+
raise EOFError('EOF when reading a line')
96+
break
97+
return "".join(result)
98+
99+
100+
class filter(object):
101+
def __init__(self, predicateOrNone, iterable):
102+
self.predicateOrNone = predicateOrNone
103+
self.iterable = iter(iterable)
104+
105+
def __iter__(self):
106+
return self
107+
108+
def __next__(self):
109+
while True:
110+
item = next(self.iterable)
111+
if self.predicateOrNone is None:
112+
if item:
113+
return item
114+
else:
115+
if self.predicateOrNone(item):
116+
return item

graalpython/lib-graalpython/functions.py

Lines changed: 0 additions & 101 deletions
This file was deleted.

mx.graalpython/mx_graalpython.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ def python(args, **kwargs):
140140
do_run_python(args, **kwargs)
141141

142142

143-
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None, cp_prefix=None, cp_suffix=None, main_class=GRAALPYTHON_MAIN_CLASS, minimal=False, **kwargs):
143+
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None, cp_prefix=None, cp_suffix=None, main_class=GRAALPYTHON_MAIN_CLASS, minimal=True, **kwargs):
144144
experimental_opt_added = False
145-
if not any(arg.startswith("--python.CAPI") for arg in args):
145+
if not minimal and not any(arg.startswith("--python.CAPI") for arg in args):
146146
capi_home = _get_capi_home()
147147
args.insert(0, "--python.CAPI=%s" % capi_home)
148148
args.insert(0, "--experimental-options")
149149
experimental_opt_added = True
150150

151-
if not any(arg.startswith("--python.JNIHome") for arg in args):
151+
if not minimal and not any(arg.startswith("--python.JNIHome") for arg in args):
152152
args.insert(0, "--python.JNIHome=" + _get_jni_home())
153153
if not experimental_opt_added:
154154
args.insert(0, "--experimental-options")

0 commit comments

Comments
 (0)