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
4142ac0b
Commit
4142ac0b
authored
Jan 10, 2019
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #291: Allow loading of arbitrary packages
parent
b66c160d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
src/pyodide.js
src/pyodide.js
+13
-2
test/test_package_loading.py
test/test_package_loading.py
+32
-0
No files found.
src/pyodide.js
View file @
4142ac0b
...
...
@@ -120,7 +120,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
});
}
else
{
console
.
error
(
`Unknown package '
${
package
}
'`
);
return
;
}
}
}
...
...
@@ -176,7 +175,19 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
else
{
script
.
src
=
`
${
package_uri
}
`
;
}
script
.
onerror
=
(
e
)
=>
{
reject
(
e
);
};
script
.
onerror
=
(
e
)
=>
{
// If the package_uri fails to load, call monitorRunDependencies twice
// (so packageCounter will still hit 0 and finish loading), and remove
// the package from toLoad so we don't mark it as loaded.
console
.
log
(
`Couldn't load package from URL
${
script
.
src
}
`
)
let
index
=
toLoad
.
indexOf
(
package
);
if
(
index
!==
-
1
)
{
toLoad
.
splice
(
index
,
1
);
}
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
window
.
pyodide
.
_module
.
monitorRunDependencies
();
}
};
document
.
body
.
appendChild
(
script
);
}
...
...
test/test_package_loading.py
View file @
4142ac0b
import
pytest
from
pathlib
import
Path
import
shutil
@
pytest
.
mark
.
parametrize
(
'active_server'
,
[
'main'
,
'secondary'
])
def
test_load_from_url
(
selenium_standalone
,
web_server_secondary
,
...
...
@@ -114,4 +117,33 @@ def test_load_handle_failure(selenium_standalone):
assert
'Loading pytz'
in
selenium
.
logs
assert
'Loading pytz2'
in
selenium
.
logs
assert
"Unknown package 'pytz2'"
in
selenium
.
logs
assert
"Couldn't load package from URL"
in
selenium
.
logs
assert
'Loading pyparsing'
in
selenium
.
logs
# <- this fails
def
test_load_package_unknown
(
selenium_standalone
):
url
=
selenium_standalone
.
server_hostname
port
=
selenium_standalone
.
server_port
build_dir
=
Path
(
__file__
).
parent
.
parent
/
'build'
shutil
.
copyfile
(
build_dir
/
'pyparsing.js'
,
build_dir
/
'pyparsing-custom.js'
)
shutil
.
copyfile
(
build_dir
/
'pyparsing.data'
,
build_dir
/
'pyparsing-custom.data'
)
try
:
selenium_standalone
.
load_package
(
f'http://
{
url
}
:
{
port
}
/pyparsing-custom.js'
)
finally
:
(
build_dir
/
'pyparsing-custom.js'
).
unlink
()
(
build_dir
/
'pyparsing-custom.data'
).
unlink
()
assert
selenium_standalone
.
run_js
(
"return window.pyodide.loadedPackages."
"hasOwnProperty('pyparsing-custom')"
)
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