Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
1049ba78
Commit
1049ba78
authored
Jan 22, 2019
by
Michael Droettboom
Committed by
GitHub
Jan 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #286 from madhur-tandon/master
Check packages against Pyodide ABI version
parents
01274166
cf7072d3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
6 deletions
+81
-6
Makefile
Makefile
+4
-2
Makefile.envs
Makefile.envs
+2
-0
packages/Makefile
packages/Makefile
+1
-1
pyodide_build/buildall.py
pyodide_build/buildall.py
+3
-0
pyodide_build/buildpkg.py
pyodide_build/buildpkg.py
+4
-0
src/pyodide.js
src/pyodide.js
+24
-1
test/test_package_loading.py
test/test_package_loading.py
+35
-2
tools/file_packager.py
tools/file_packager.py
+8
-0
No files found.
Makefile
View file @
1049ba78
...
@@ -72,7 +72,7 @@ build/pyodide.asm.js: src/main.bc src/jsimport.bc src/jsproxy.bc src/js2python.b
...
@@ -72,7 +72,7 @@ build/pyodide.asm.js: src/main.bc src/jsimport.bc src/jsproxy.bc src/js2python.b
build/pyodide.asm.data
:
root/.built
build/pyodide.asm.data
:
root/.built
(
\
(
\
cd
build
;
\
cd
build
;
\
python
$(FILEPACKAGER)
pyodide.asm.data
--lz4
--preload
../root/lib@lib
--js-output
=
pyodide.asm.data.js
--use-preload-plugins
\
python
$(FILEPACKAGER)
pyodide.asm.data
--
abi
=
$(PYODIDE_PACKAGE_ABI)
--
lz4
--preload
../root/lib@lib
--js-output
=
pyodide.asm.data.js
--use-preload-plugins
\
)
)
uglifyjs build/pyodide.asm.data.js
-o
build/pyodide.asm.data.js
uglifyjs build/pyodide.asm.data.js
-o
build/pyodide.asm.data.js
...
@@ -80,11 +80,13 @@ build/pyodide.asm.data: root/.built
...
@@ -80,11 +80,13 @@ build/pyodide.asm.data: root/.built
build/pyodide_dev.js
:
src/pyodide.js
build/pyodide_dev.js
:
src/pyodide.js
cp
$<
$@
cp
$<
$@
sed
-i
-e
"s#{{DEPLOY}}##g"
$@
sed
-i
-e
"s#{{DEPLOY}}##g"
$@
sed
-i
-e
"s#{{ABI}}#
$(PYODIDE_PACKAGE_ABI)
#g"
$@
build/pyodide.js
:
src/pyodide.js
build/pyodide.js
:
src/pyodide.js
cp
$<
$@
cp
$<
$@
sed
-i
-e
's#{{DEPLOY}}#https://iodide.io/pyodide-demo/#g'
$@
sed
-i
-e
's#{{DEPLOY}}#https://iodide.io/pyodide-demo/#g'
$@
sed
-i
-e
"s#{{ABI}}#
$(PYODIDE_PACKAGE_ABI)
#g"
$@
build/python.html
:
src/python.html
build/python.html
:
src/python.html
...
@@ -145,7 +147,7 @@ build/test.data: $(CPYTHONLIB)
...
@@ -145,7 +147,7 @@ build/test.data: $(CPYTHONLIB)
)
)
(
\
(
\
cd
build
;
\
cd
build
;
\
python
$(FILEPACKAGER)
test.data
--lz4
--preload
../
$(CPYTHONLIB)
/test@/lib/python3.7/test
--js-output
=
test.js
--export-name
=
pyodide._module
--exclude
__pycache__
\
python
$(FILEPACKAGER)
test.data
--
abi
=
$(PYODIDE_PACKAGE_ABI)
--
lz4
--preload
../
$(CPYTHONLIB)
/test@/lib/python3.7/test
--js-output
=
test.js
--export-name
=
pyodide._module
--exclude
__pycache__
\
)
)
uglifyjs build/test.js
-o
build/test.js
uglifyjs build/test.js
-o
build/test.js
...
...
Makefile.envs
View file @
1049ba78
...
@@ -15,6 +15,8 @@ export HOSTPYTHON=$(HOSTPYTHONROOT)/bin/python3
...
@@ -15,6 +15,8 @@ export HOSTPYTHON=$(HOSTPYTHONROOT)/bin/python3
export
TARGETPYTHONROOT
=
$(PYODIDE_ROOT)
/cpython/installs/python-
$(PYVERSION)
export
TARGETPYTHONROOT
=
$(PYODIDE_ROOT)
/cpython/installs/python-
$(PYVERSION)
export
PYTHONINCLUDE
=
$(PYODIDE_ROOT)
/cpython/installs/python-
$(PYVERSION)
/include/python
$(PYMINOR)
export
PYTHONINCLUDE
=
$(PYODIDE_ROOT)
/cpython/installs/python-
$(PYVERSION)
/include/python
$(PYMINOR)
export
PYODIDE_PACKAGE_ABI
=
1
export
SIDE_LDFLAGS
=
\
export
SIDE_LDFLAGS
=
\
-O3
\
-O3
\
-s
"BINARYEN_METHOD='native-wasm'"
\
-s
"BINARYEN_METHOD='native-wasm'"
\
...
...
packages/Makefile
View file @
1049ba78
...
@@ -3,7 +3,7 @@ include ../Makefile.envs
...
@@ -3,7 +3,7 @@ include ../Makefile.envs
all
:
deps
all
:
deps
../bin/pyodide buildall
.
../build
\
../bin/pyodide buildall
.
../build
\
--ldflags
=
"
$(SIDE_LDFLAGS)
"
--host
=
$(HOSTPYTHONROOT)
--target
=
$(TARGETPYTHONROOT)
--
package_abi
=
$(PYODIDE_PACKAGE_ABI)
--
ldflags
=
"
$(SIDE_LDFLAGS)
"
--host
=
$(HOSTPYTHONROOT)
--target
=
$(TARGETPYTHONROOT)
deps
:
deps
:
# Install build dependencies
# Install build dependencies
$(HOSTPYTHON)
-m
pip
install
Cython Tempita
$(HOSTPYTHON)
-m
pip
install
Cython Tempita
...
...
pyodide_build/buildall.py
View file @
1049ba78
...
@@ -69,6 +69,9 @@ def make_parser(parser):
...
@@ -69,6 +69,9 @@ def make_parser(parser):
parser
.
add_argument
(
parser
.
add_argument
(
'output'
,
type
=
str
,
nargs
=
1
,
'output'
,
type
=
str
,
nargs
=
1
,
help
=
'Output directory in which to put all built packages'
)
help
=
'Output directory in which to put all built packages'
)
parser
.
add_argument
(
'--package_abi'
,
type
=
int
,
required
=
True
,
help
=
'The ABI number for the packages to be built'
)
parser
.
add_argument
(
parser
.
add_argument
(
'--cflags'
,
type
=
str
,
nargs
=
'?'
,
default
=
common
.
DEFAULTCFLAGS
,
'--cflags'
,
type
=
str
,
nargs
=
'?'
,
default
=
common
.
DEFAULTCFLAGS
,
help
=
'Extra compiling flags'
)
help
=
'Extra compiling flags'
)
...
...
pyodide_build/buildpkg.py
View file @
1049ba78
...
@@ -127,6 +127,7 @@ def package_files(buildpath, srcpath, pkg, args):
...
@@ -127,6 +127,7 @@ def package_files(buildpath, srcpath, pkg, args):
'python'
,
'python'
,
common
.
ROOTDIR
/
'file_packager.py'
,
common
.
ROOTDIR
/
'file_packager.py'
,
name
+
'.data'
,
name
+
'.data'
,
'--abi={0}'
.
format
(
args
.
package_abi
),
'--lz4'
,
'--lz4'
,
'--preload'
,
'--preload'
,
'{}@/'
.
format
(
install_prefix
),
'{}@/'
.
format
(
install_prefix
),
...
@@ -169,6 +170,9 @@ def make_parser(parser):
...
@@ -169,6 +170,9 @@ def make_parser(parser):
parser
.
add_argument
(
parser
.
add_argument
(
'package'
,
type
=
str
,
nargs
=
1
,
'package'
,
type
=
str
,
nargs
=
1
,
help
=
"Path to meta.yaml package description"
)
help
=
"Path to meta.yaml package description"
)
parser
.
add_argument
(
'--package_abi'
,
type
=
int
,
required
=
True
,
help
=
'The ABI number for the package to be built'
)
parser
.
add_argument
(
parser
.
add_argument
(
'--cflags'
,
type
=
str
,
nargs
=
'?'
,
default
=
common
.
DEFAULTCFLAGS
,
'--cflags'
,
type
=
str
,
nargs
=
'?'
,
default
=
common
.
DEFAULTCFLAGS
,
help
=
'Extra compiling flags'
)
help
=
'Extra compiling flags'
)
...
...
src/pyodide.js
View file @
1049ba78
...
@@ -159,6 +159,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -159,6 +159,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
window
.
pyodide
.
loadedPackages
[
package
]
=
toLoad
[
package
];
window
.
pyodide
.
loadedPackages
[
package
]
=
toLoad
[
package
];
}
}
delete
window
.
pyodide
.
_module
.
monitorRunDependencies
;
delete
window
.
pyodide
.
_module
.
monitorRunDependencies
;
window
.
removeEventListener
(
'
error
'
,
windowErrorHandler
);
if
(
!
isFirefox
)
{
if
(
!
isFirefox
)
{
preloadWasm
().
then
(()
=>
{
resolve
(
`Loaded
${
packageList
}
`
)});
preloadWasm
().
then
(()
=>
{
resolve
(
`Loaded
${
packageList
}
`
)});
}
else
{
}
else
{
...
@@ -167,6 +168,17 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -167,6 +168,17 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
}
};
};
// Add a handler for any exceptions that are thrown in the process of
// loading a package
var
windowErrorHandler
=
(
err
)
=>
{
delete
window
.
pyodide
.
_module
.
monitorRunDependencies
;
window
.
removeEventListener
(
'
error
'
,
windowErrorHandler
);
// Set up a new Promise chain, since this one failed
loadPackagePromise
=
new
Promise
((
resolve
)
=>
resolve
());
reject
(
err
.
message
);
};
window
.
addEventListener
(
'
error
'
,
windowErrorHandler
);
for
(
let
package
in
toLoad
)
{
for
(
let
package
in
toLoad
)
{
let
script
=
document
.
createElement
(
'
script
'
);
let
script
=
document
.
createElement
(
'
script
'
);
let
package_uri
=
toLoad
[
package
];
let
package_uri
=
toLoad
[
package
];
...
@@ -179,7 +191,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -179,7 +191,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
// If the package_uri fails to load, call monitorRunDependencies twice
// If the package_uri fails to load, call monitorRunDependencies twice
// (so packageCounter will still hit 0 and finish loading), and remove
// (so packageCounter will still hit 0 and finish loading), and remove
// the package from toLoad so we don't mark it as loaded.
// the package from toLoad so we don't mark it as loaded.
console
.
log
(
`Couldn't load package from URL
${
script
.
src
}
`
)
console
.
error
(
`Couldn't load package from URL
${
script
.
src
}
`
)
let
index
=
toLoad
.
indexOf
(
package
);
let
index
=
toLoad
.
indexOf
(
package
);
if
(
index
!==
-
1
)
{
if
(
index
!==
-
1
)
{
toLoad
.
splice
(
index
,
1
);
toLoad
.
splice
(
index
,
1
);
...
@@ -247,6 +259,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -247,6 +259,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
'
repr
'
,
'
repr
'
,
'
runPython
'
,
'
runPython
'
,
'
runPythonAsync
'
,
'
runPythonAsync
'
,
'
checkABI
'
,
'
version
'
,
'
version
'
,
];
];
...
@@ -277,6 +290,16 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -277,6 +290,16 @@ var languagePluginLoader = new Promise((resolve, reject) => {
return
{};
return
{};
};
};
Module
.
checkABI
=
function
(
ABI_number
)
{
if
(
ABI_number
!==
parseInt
(
'
{{ABI}}
'
))
{
var
ABI_mismatch_exception
=
`ABI numbers differ. Expected {{ABI}}, got
${
ABI_number
}
`
;
console
.
error
(
ABI_mismatch_exception
);
throw
ABI_mismatch_exception
;
}
return
true
;
};
Module
.
locateFile
=
(
path
)
=>
baseURL
+
path
;
Module
.
locateFile
=
(
path
)
=>
baseURL
+
path
;
var
postRunPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
var
postRunPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
Module
.
postRun
=
()
=>
{
Module
.
postRun
=
()
=>
{
...
...
test/test_package_loading.py
View file @
1049ba78
import
pytest
import
pytest
from
pathlib
import
Path
import
shutil
import
shutil
import
re
from
pathlib
import
Path
@
pytest
.
mark
.
parametrize
(
'active_server'
,
[
'main'
,
'secondary'
])
@
pytest
.
mark
.
parametrize
(
'active_server'
,
[
'main'
,
'secondary'
])
...
@@ -108,6 +108,39 @@ def test_load_packages_sequential(selenium_standalone, packages):
...
@@ -108,6 +108,39 @@ def test_load_packages_sequential(selenium_standalone, packages):
assert
selenium
.
logs
.
count
(
f'Loading
{
packages
[
1
]
}
'
)
==
1
assert
selenium
.
logs
.
count
(
f'Loading
{
packages
[
1
]
}
'
)
==
1
def
test_different_ABI
(
selenium_standalone
):
url
=
selenium_standalone
.
server_hostname
port
=
selenium_standalone
.
server_port
build_dir
=
Path
(
__file__
).
parent
.
parent
/
'build'
original_file
=
open
(
'build/numpy.js'
,
'r+'
)
original_contents
=
original_file
.
read
()
original_file
.
close
()
modified_contents
=
re
.
sub
(
r'checkABI\
(
\d+\
)
', '
checkABI
(
-
1
)
',
original_contents)
modified_file = open('
build
/
numpy
-
broken
.
js
', '
w
+
')
modified_file.write(modified_contents)
modified_file.close()
try:
selenium_standalone.load_package(
f'
http
:
//
{
url
}:{
port
}
/
numpy
-
broken
.
js
'
)
assert '
ABI
numbers
differ
.
' in selenium_standalone.logs
finally:
(build_dir / '
numpy
-
broken
.
js
').unlink()
selenium_standalone.load_package('
kiwisolver
')
selenium_standalone.run('
import
kiwisolver
')
assert (
selenium_standalone.run('
repr
(
kiwisolver
)
') ==
"<module '
kiwisolver
' from "
"'
/
lib
/
python3
.
7
/
site
-
packages
/
kiwisolver
.
so
'>"
)
def test_load_handle_failure(selenium_standalone):
def test_load_handle_failure(selenium_standalone):
selenium = selenium_standalone
selenium = selenium_standalone
selenium.load_package('
pytz
')
selenium.load_package('
pytz
')
...
...
tools/file_packager.py
View file @
1049ba78
...
@@ -144,6 +144,10 @@ for arg in sys.argv[2:]:
...
@@ -144,6 +144,10 @@ for arg in sys.argv[2:]:
leading
=
'preload'
leading
=
'preload'
elif
arg
==
'--embed'
:
elif
arg
==
'--embed'
:
leading
=
'embed'
leading
=
'embed'
elif
arg
.
startswith
(
'--abi'
):
if
'='
in
arg
:
package_abi
=
arg
.
split
(
'='
,
1
)[
1
]
leading
=
''
elif
arg
==
'--exclude'
:
elif
arg
==
'--exclude'
:
leading
=
'exclude'
leading
=
'exclude'
elif
arg
==
'--no-force'
:
elif
arg
==
'--no-force'
:
...
@@ -227,6 +231,10 @@ if not from_emcc:
...
@@ -227,6 +231,10 @@ if not from_emcc:
var Module = typeof %(EXPORT_NAME)s !== 'undefined' ? %(EXPORT_NAME)s : {};
var Module = typeof %(EXPORT_NAME)s !== 'undefined' ? %(EXPORT_NAME)s : {};
'''
%
{
"EXPORT_NAME"
:
export_name
}
'''
%
{
"EXPORT_NAME"
:
export_name
}
ret
+=
'''
Module.checkABI({0});
'''
.
format
(
package_abi
)
ret
+=
'''
ret
+=
'''
if (!Module.expectedDataFileDownloads) {
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Module.expectedDataFileDownloads = 0;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment