FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
graalpython/mx.graalpython/mx_graalpython_import.py at master · oracle/graalpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
oracle
/
graalpython
Public
Notifications
You must be signed in to change notification settings
Fork
154
Star
1.6k
Code
Issues
63
Pull requests
4
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
graalpython
/
mx.graalpython
/
mx_graalpython_import.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
281 lines (244 loc) · 15.7 KB
Breadcrumbs
graalpython
/
mx.graalpython
/
mx_graalpython_import.py
Copy path
File metadata and controls
281 lines (244 loc) · 15.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import
abc
import
argparse
import
os
import
shutil
import
sys
from
textwrap
import
dedent
import
mx
SUITE
=
mx
.
suite
(
'graalpython'
)
class
AbstractRule
(
abc
.
ABC
):
def
__init__
(
self
,
source_path
):
self
.
source_path
=
source_path
@
abc
.
abstractmethod
def
copy
(
self
,
source_dir
,
graalpy_dir
,
graalpy_path
,
overrides
,
tracked_files
):
pass
def
match_overrides
(
graalpy_path
,
overrides
):
graalpy_prefix
=
f"
{
graalpy_path
}
/"
matches
=
[
f
for
f
in
overrides
if
f
==
graalpy_path
or
f
.
startswith
(
graalpy_prefix
)]
for
match
in
matches
:
overrides
.
remove
(
match
)
return
matches
class
Ignore
(
AbstractRule
):
"""
A rule that ignores a file a directory.
"""
def
__init__
(
self
):
super
().
__init__
(
None
)
def
copy
(
self
,
source_dir
,
graalpy_dir
,
graalpy_path
,
overrides
,
tracked_files
):
match_overrides
(
graalpy_path
,
overrides
)
class
CopyFrom
(
AbstractRule
):
"""
A rule that copies a file or a whole directory recursively.
"""
def
copy
(
self
,
source_dir
,
graalpy_dir
,
graalpy_path
,
overrides
,
tracked_files
):
match_overrides
(
graalpy_path
,
overrides
)
src
=
os
.
path
.
join
(
source_dir
,
self
.
source_path
)
dst
=
os
.
path
.
join
(
graalpy_dir
,
graalpy_path
)
if
os
.
path
.
isfile
(
src
):
if
self
.
source_path
not
in
tracked_files
:
sys
.
exit
(
f"Source path
{
src
}
is not tracked by git"
)
os
.
makedirs
(
os
.
path
.
dirname
(
dst
),
exist_ok
=
True
)
shutil
.
copy
(
src
,
dst
)
elif
os
.
path
.
isdir
(
src
):
source_prefix
=
f"
{
self
.
source_path
}
/"
for
source_file
in
tracked_files
:
if
source_file
.
startswith
(
source_prefix
):
relative_path
=
source_file
.
removeprefix
(
source_prefix
)
destination_file
=
os
.
path
.
join
(
dst
,
relative_path
)
os
.
makedirs
(
os
.
path
.
dirname
(
destination_file
),
exist_ok
=
True
)
shutil
.
copy
(
os
.
path
.
join
(
source_dir
,
source_file
),
destination_file
)
else
:
sys
.
exit
(
f"Source path
{
src
}
not found"
)
class
CopyFromWithOverrides
(
AbstractRule
):
"""
A rule that copies a directory using a list of files specified in the license header overrides list.
"""
def
copy
(
self
,
source_dir
,
graalpy_dir
,
graalpy_path
,
overrides
,
tracked_files
):
src
=
os
.
path
.
join
(
source_dir
,
self
.
source_path
)
if
os
.
path
.
isdir
(
src
):
graalpy_prefix
=
f"
{
graalpy_path
}
/"
matches
=
match_overrides
(
graalpy_path
,
overrides
)
for
f
in
matches
:
dst
=
os
.
path
.
join
(
graalpy_dir
,
f
)
os
.
makedirs
(
os
.
path
.
dirname
(
dst
),
exist_ok
=
True
)
src
=
os
.
path
.
join
(
source_dir
,
self
.
source_path
)
if
f
.
startswith
(
graalpy_prefix
):
src
=
os
.
path
.
join
(
src
,
f
.
removeprefix
(
graalpy_prefix
))
if
not
os
.
path
.
exists
(
src
):
sys
.
exit
(
f"File
{
f
}
from license overrides not found in
{
self
.
source_path
}
"
)
source_file
=
os
.
path
.
relpath
(
src
,
source_dir
).
replace
(
os
.
sep
,
'/'
)
if
source_file
not
in
tracked_files
:
sys
.
exit
(
f"File
{
f
}
from license overrides is not tracked by git in
{
self
.
source_path
}
"
)
shutil
.
copy
(
src
,
dst
)
elif
os
.
path
.
exists
(
src
):
sys
.
exit
(
f"
{
type
(
self
)
}
rule should only be used with directories"
)
else
:
sys
.
exit
(
f"Source path
{
src
}
not found"
)
#############################
# Source file mapping rules #
#############################
CPYTHON_SOURCES_MAPPING
=
{
# Standard library
"graalpython/lib-python/3"
:
CopyFrom
(
"Lib"
),
# hand written based on the original
"graalpython/lib-graalpython/modules/graalpy-config.py"
:
Ignore
(),
# C API
"graalpython/com.oracle.graal.python.cext/include"
:
CopyFromWithOverrides
(
"Include"
),
# Different copyright
"graalpython/com.oracle.graal.python.cext/include/dynamic_annotations.h"
:
CopyFrom
(
"Include/dynamic_annotations.h"
),
"graalpython/com.oracle.graal.python.cext/expat"
:
CopyFromWithOverrides
(
"Modules/expat"
),
"graalpython/com.oracle.graal.python.cext/modules/_sqlite"
:
CopyFrom
(
"Modules/_sqlite"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/Hacl_Hash_SHA3.c"
:
CopyFrom
(
"Modules/_hacl/Hacl_Hash_SHA3.c"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/Hacl_Hash_SHA3.h"
:
CopyFrom
(
"Modules/_hacl/Hacl_Hash_SHA3.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/Hacl_Streaming_Types.h"
:
CopyFrom
(
"Modules/_hacl/Hacl_Streaming_Types.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/FStar_UInt128_Verified.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/FStar_UInt128_Verified.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/FStar_UInt_8_16_32_64.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/FStar_UInt_8_16_32_64.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/fstar_uint128_struct_endianness.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/fstar_uint128_struct_endianness.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/internal/target.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/internal/target.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/lowstar_endianness.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/lowstar_endianness.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/include/krml/types.h"
:
CopyFrom
(
"Modules/_hacl/include/krml/types.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/internal/Hacl_Hash_SHA3.h"
:
CopyFrom
(
"Modules/_hacl/internal/Hacl_Hash_SHA3.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_hacl/python_hacl_namespaces.h"
:
CopyFrom
(
"Modules/_hacl/python_hacl_namespaces.h"
),
"graalpython/com.oracle.graal.python.cext/modules/_cpython_sre"
:
CopyFromWithOverrides
(
"Modules/_sre"
),
"graalpython/com.oracle.graal.python.cext/modules/_cpython_unicodedata.c"
:
CopyFrom
(
"Modules/unicodedata.c"
),
"graalpython/com.oracle.graal.python.cext/modules/_bz2.c"
:
CopyFrom
(
"Modules/_bz2module.c"
),
"graalpython/com.oracle.graal.python.cext/modules/_testcapi.c"
:
CopyFrom
(
"Modules/_testcapimodule.c"
),
"graalpython/com.oracle.graal.python.cext/modules/clinic/memoryobject.c.h"
:
CopyFrom
(
"Objects/clinic/memoryobject.c.h"
),
"graalpython/com.oracle.graal.python.cext/modules/clinic/sha3module.c.h"
:
CopyFrom
(
"Modules/clinic/sha3module.c.h"
),
"graalpython/com.oracle.graal.python.cext/modules"
:
CopyFromWithOverrides
(
"Modules"
),
"graalpython/com.oracle.graal.python.cext/src/getbuildinfo.c"
:
CopyFrom
(
"Modules/getbuildinfo.c"
),
"graalpython/com.oracle.graal.python.cext/src/datetime.c"
:
CopyFrom
(
"Modules/_datetimemodule.c"
),
"graalpython/com.oracle.graal.python.cext/src/getcompiler.c"
:
CopyFrom
(
"Python/getcompiler.c"
),
"graalpython/com.oracle.graal.python.cext/src/getversion.c"
:
CopyFrom
(
"Python/getversion.c"
),
"graalpython/com.oracle.graal.python.cext/src/mysnprintf.c"
:
CopyFrom
(
"Python/mysnprintf.c"
),
"graalpython/com.oracle.graal.python.cext/src/mystrtoul.c"
:
CopyFrom
(
"Python/mystrtoul.c"
),
"graalpython/com.oracle.graal.python.cext/src/pystrcmp.c"
:
CopyFrom
(
"Python/pystrcmp.c"
),
"graalpython/com.oracle.graal.python.cext/src/pystrtod.c"
:
CopyFrom
(
"Python/pystrtod.c"
),
"graalpython/com.oracle.graal.python.cext/src/pystrhex.c"
:
CopyFrom
(
"Python/pystrhex.c"
),
"graalpython/com.oracle.graal.python.cext/src/dtoa.c"
:
CopyFrom
(
"Python/dtoa.c"
),
"graalpython/com.oracle.graal.python.cext/src/errors.c"
:
CopyFrom
(
"Python/errors.c"
),
"graalpython/com.oracle.graal.python.cext/src/gcmodule.c"
:
CopyFrom
(
"Modules/gcmodule.c"
),
"graalpython/com.oracle.graal.python.cext/src/getargs.c"
:
CopyFrom
(
"Python/getargs.c"
),
"graalpython/com.oracle.graal.python.cext/src/import.c"
:
CopyFrom
(
"Python/import.c"
),
"graalpython/com.oracle.graal.python.cext/src/initconfig.c"
:
CopyFrom
(
"Python/initconfig.c"
),
"graalpython/com.oracle.graal.python.cext/src/modsupport.c"
:
CopyFrom
(
"Python/modsupport.c"
),
"graalpython/com.oracle.graal.python.cext/src/pyctype.c"
:
CopyFrom
(
"Python/pyctype.c"
),
"graalpython/com.oracle.graal.python.cext/src/pyhash.c"
:
CopyFrom
(
"Python/pyhash.c"
),
"graalpython/com.oracle.graal.python.cext/src/thread.c"
:
CopyFrom
(
"Python/thread.c"
),
"graalpython/com.oracle.graal.python.cext/src/thread_nt.h"
:
CopyFrom
(
"Python/thread_nt.h"
),
"graalpython/com.oracle.graal.python.cext/src/condvar.h"
:
CopyFrom
(
"Python/condvar.h"
),
"graalpython/com.oracle.graal.python.cext/src/thread_pthread.h"
:
CopyFrom
(
"Python/thread_pthread.h"
),
"graalpython/com.oracle.graal.python.cext/src/thread_pthread_stubs.h"
:
CopyFrom
(
"Python/thread_pthread_stubs.h"
),
"graalpython/com.oracle.graal.python.cext/src/_warnings.c"
:
CopyFrom
(
"Python/_warnings.c"
),
"graalpython/com.oracle.graal.python.cext/src/typeslots.inc"
:
CopyFrom
(
"Objects/typeslots.inc"
),
"graalpython/com.oracle.graal.python.cext/src/fileutils.c"
:
CopyFrom
(
"Python/fileutils.c"
),
"graalpython/com.oracle.graal.python.cext/src/invalid_parameter_handler.c"
:
CopyFrom
(
"PC/invalid_parameter_handler.c"
),
"graalpython/com.oracle.graal.python.cext/src/ceval.c"
:
CopyFrom
(
"Python/ceval.c"
),
"graalpython/com.oracle.graal.python.cext/src/pystate.c"
:
CopyFrom
(
"Python/pystate.c"
),
"graalpython/com.oracle.graal.python.cext/src/lock.c"
:
CopyFrom
(
"Python/lock.c"
),
"graalpython/com.oracle.graal.python.cext/src/parking_lot.c"
:
CopyFrom
(
"Python/parking_lot.c"
),
"graalpython/com.oracle.graal.python.cext/src/pytime.c"
:
CopyFrom
(
"Python/pytime.c"
),
"graalpython/com.oracle.graal.python.cext/src"
:
CopyFromWithOverrides
(
"Objects"
),
# Just few functions are taken from CPython
"graalpython/python-libposix/src/fork_exec.c"
:
Ignore
(),
# Largely rewritten
"graalpython/python-venvlauncher/src/venvlauncher.c"
:
Ignore
(),
# PEG Parser
"graalpython/com.oracle.graal.python.pegparser.generator/pegen"
:
CopyFrom
(
"Tools/peg_generator/pegen"
),
"graalpython/com.oracle.graal.python.pegparser.generator/input_files/Python.asdl"
:
CopyFrom
(
"Parser/Python.asdl"
),
"graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl.py"
:
CopyFrom
(
"Parser/asdl.py"
),
"graalpython/com.oracle.graal.python.pegparser.generator/input_files/python.gram"
:
CopyFrom
(
"Grammar/python.gram"
),
"graalpython/com.oracle.graal.python.pegparser.generator/input_files/Tokens"
:
CopyFrom
(
"Grammar/Tokens"
),
"graalpython/com.oracle.graal.python.pegparser.generator/diff_generator.py"
:
Ignore
(),
"graalpython/com.oracle.graal.python.pegparser.generator/pegjava/java_generator.py"
:
Ignore
(),
"graalpython/com.oracle.graal.python.frozen/freeze_modules.py"
:
CopyFrom
(
"Tools/build/freeze_modules.py"
),
# Others
# Test files don't need to be updated, they inline some unittest code only
"graalpython/com.oracle.graal.python.test/src/tests"
:
Ignore
(),
}
def
import_python_sources
(
args
):
parser
=
argparse
.
ArgumentParser
(
prog
=
'mx python-src-import'
,
description
=
"Update the inlined files from CPython. Refer to the docs on Confluence."
,
)
parser
.
add_argument
(
'--cpython'
,
action
=
'store'
,
help
=
'Path to CPython sources'
,
required
=
True
)
parser
.
add_argument
(
'--python-version'
,
action
=
'store'
,
help
=
'Python version to be updated to (used for commit message)'
,
required
=
True
)
args
=
parser
.
parse_args
(
args
)
tracked_files
=
set
(
SUITE
.
vc
.
git_command
(
args
.
cpython
, [
'ls-files'
,
'--full-name'
,
'-z'
],
abortOnError
=
True
).
split
(
'
\0
'
)
)
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"copyrights"
,
"overrides"
))
as
f
:
entries
=
[
line
.
strip
().
split
(
','
)
for
line
in
f
if
','
in
line
]
cpython_files
=
[
file
for
file
,
license
in
entries
if
license
==
"python.copyright"
and
not
file
.
endswith
(
'.java'
)]
import_dir
=
os
.
path
.
abspath
(
os
.
path
.
join
(
SUITE
.
dir
,
'python-import'
))
shutil
.
rmtree
(
import_dir
,
ignore_errors
=
True
)
# Fetch the python-import branch, would fail when not fast-forwardable
SUITE
.
vc
.
git_command
(
SUITE
.
dir
, [
'fetch'
,
'origin'
,
'python-import:python-import'
])
# Checkout the python-import branch into a subdirectory
SUITE
.
vc
.
git_command
(
SUITE
.
dir
, [
'clone'
,
'-b'
,
'python-import'
,
'.'
,
'python-import'
])
for
file
in
os
.
listdir
(
import_dir
):
if
not
file
.
startswith
(
'.'
):
shutil
.
rmtree
(
os
.
path
.
join
(
import_dir
,
file
),
ignore_errors
=
True
)
def
copy_inlined_files
(
mapping
,
source_directory
,
overrides
):
overrides
=
list
(
overrides
)
for
path
,
rule
in
mapping
.
items
():
rule
.
copy
(
source_directory
,
import_dir
,
path
,
overrides
,
tracked_files
)
if
overrides
:
lines
=
'
\n
'
.
join
(
overrides
)
sys
.
exit
(
f"ERROR: The following files were not matched by any rule:
\n
{
lines
}
"
)
copy_inlined_files
(
CPYTHON_SOURCES_MAPPING
,
args
.
cpython
,
cpython_files
)
# Commit and fetch changes back into the main repository
# Some CPython test fixtures match GraalPy's ignore rules (for example
# Lib/test/archivetestdata/zipdir.zip). Also, do not let a developer's
# global Git ignore configuration affect which imported files are staged.
SUITE
.
vc
.
git_command
(
import_dir
, [
"add"
,
"--force"
,
"."
])
SUITE
.
vc
.
commit
(
import_dir
,
f"Update Python inlined files:
{
args
.
python_version
}
"
)
SUITE
.
vc
.
git_command
(
SUITE
.
dir
, [
'fetch'
,
'python-import'
,
'+python-import:python-import'
])
print
(
dedent
(
"""
\
The python-import branch has been updated to the specified release.
It is checked out in the python-import directory, where you can make changes and amend the commit. If you do, you
need to pull the changes back to this repository using the following (from the main repository directory):
git fetch python-import +python-import:python-import
When you're happy with the state, push the changes using:
git push origin python-import:python-import
"""
))
Back
|
FazBrowse Home
|
New Git URL