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
56ee2e68
Commit
56ee2e68
authored
Sep 05, 2018
by
Michael Droettboom
Committed by
GitHub
Sep 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #136 from rth/load-packages-multiple
Load multiple packages in pyodide.loadPackage
parents
ac970e74
c14147b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
3 deletions
+35
-3
docs/using_pyodide_from_iodide.md
docs/using_pyodide_from_iodide.md
+5
-0
docs/using_pyodide_from_javascript.md
docs/using_pyodide_from_javascript.md
+5
-0
src/pyodide.js
src/pyodide.js
+10
-3
test/test_package_loading.py
test/test_package_loading.py
+15
-0
No files found.
docs/using_pyodide_from_iodide.md
View file @
56ee2e68
...
@@ -61,6 +61,11 @@ When you request a package from the official repository, all of that package's
...
@@ -61,6 +61,11 @@ When you request a package from the official repository, all of that package's
dependencies are also loaded. Dependency resolution is not yet implemented
dependencies are also loaded. Dependency resolution is not yet implemented
when loading packages from custom URLs.
when loading packages from custom URLs.
Multiple packages can also be loaded in a single call,
```
js
pyodide
.
loadPackage
([
'
cycler
'
,
'
pytz
'
])
```
`pyodide.loadPackage`
returns a
`Promise`
.
`pyodide.loadPackage`
returns a
`Promise`
.
```
javascript
```
javascript
...
...
docs/using_pyodide_from_javascript.md
View file @
56ee2e68
...
@@ -49,6 +49,11 @@ When you request a package from the official repository, all of that package's
...
@@ -49,6 +49,11 @@ When you request a package from the official repository, all of that package's
dependencies are also loaded. Dependency resolution is not yet implemented
dependencies are also loaded. Dependency resolution is not yet implemented
when loading packages from custom URLs.
when loading packages from custom URLs.
Multiple packages can also be loaded in a single call,
```
js
pyodide
.
loadPackage
([
'
cycler
'
,
'
pytz
'
])
```
`pyodide.loadPackage`
returns a
`Promise`
.
`pyodide.loadPackage`
returns a
`Promise`
.
```
javascript
```
javascript
...
...
src/pyodide.js
View file @
56ee2e68
...
@@ -36,7 +36,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -36,7 +36,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
let
loadPackage
=
(
names
)
=>
{
let
loadPackage
=
(
names
)
=>
{
// DFS to find all dependencies of the requested packages
// DFS to find all dependencies of the requested packages
let
packages
=
window
.
pyodide
.
packages
.
dependencies
;
let
packages
=
window
.
pyodide
.
packages
.
dependencies
;
let
queue
=
new
Array
(
names
);
let
queue
=
[].
concat
(
names
||
[]
);
let
toLoad
=
new
Array
();
let
toLoad
=
new
Array
();
while
(
queue
.
length
)
{
while
(
queue
.
length
)
{
let
package_uri
=
queue
.
pop
();
let
package_uri
=
queue
.
pop
();
...
@@ -49,8 +49,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -49,8 +49,6 @@ var languagePluginLoader = new Promise((resolve, reject) => {
package_uri
=
'
default channel
'
;
package_uri
=
'
default channel
'
;
}
}
console
.
log
(
`Loading
${
package
}
from
${
package_uri
}
`
);
if
(
package
in
loadedPackages
)
{
if
(
package
in
loadedPackages
)
{
if
(
package_uri
!=
loadedPackages
[
package
])
{
if
(
package_uri
!=
loadedPackages
[
package
])
{
throw
new
Error
(
throw
new
Error
(
...
@@ -58,7 +56,16 @@ var languagePluginLoader = new Promise((resolve, reject) => {
...
@@ -58,7 +56,16 @@ var languagePluginLoader = new Promise((resolve, reject) => {
`
${
package
}
from
${
package_uri
}
while it is already `
+
`
${
package
}
from
${
package_uri
}
while it is already `
+
`loaded from
${
loadedPackages
[
package
]}
!`
);
`loaded from
${
loadedPackages
[
package
]}
!`
);
}
}
}
else
if
(
package
in
toLoad
)
{
if
(
package_uri
!=
toLoad
[
package
])
{
throw
new
Error
(
`URI mismatch, attempting to load package `
+
`
${
package
}
from
${
package_uri
}
while it is already `
+
`being loaded from
${
toLoad
[
package
]}
!`
);
}
}
else
{
}
else
{
console
.
log
(
`Loading
${
package
}
from
${
package_uri
}
`
);
toLoad
[
package
]
=
package_uri
;
toLoad
[
package
]
=
package_uri
;
if
(
packages
.
hasOwnProperty
(
package
))
{
if
(
packages
.
hasOwnProperty
(
package
))
{
packages
[
package
].
forEach
((
subpackage
)
=>
{
packages
[
package
].
forEach
((
subpackage
)
=>
{
...
...
test/test_package_loading.py
View file @
56ee2e68
...
@@ -34,3 +34,18 @@ def test_invalid_package_name(selenium):
...
@@ -34,3 +34,18 @@ def test_invalid_package_name(selenium):
with
pytest
.
raises
(
WebDriverException
,
with
pytest
.
raises
(
WebDriverException
,
match
=
"Invalid package name or URI"
):
match
=
"Invalid package name or URI"
):
selenium
.
load_package
(
'tcp://some_url'
)
selenium
.
load_package
(
'tcp://some_url'
)
@
pytest
.
mark
.
parametrize
(
'packages'
,
[[
'pyparsing'
,
'pytz'
],
[
'pyparsing'
,
'matplotlib'
]],
ids
=
'-'
.
join
)
def
test_load_packages_multiple
(
selenium_standalone
,
packages
):
selenium
=
selenium_standalone
selenium
.
load_package
(
packages
)
selenium
.
run
(
f'import
{
packages
[
0
]
}
'
)
selenium
.
run
(
f'import
{
packages
[
1
]
}
'
)
# The long must show that each package is loaded exactly once,
# including when one package is a dependency of the other
# ('pyparsing' and 'matplotlib')
assert
selenium
.
logs
.
count
(
f'Loading
{
packages
[
0
]
}
'
)
==
1
assert
selenium
.
logs
.
count
(
f'Loading
{
packages
[
1
]
}
'
)
==
1
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