Skip to content

Commit cf6773d

Browse files
authored
Merge pull request #5 from aidanhs/aphs-docker
Add instructions for docker
2 parents 93a2c8b + 5c4529a commit cf6773d

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EMEXPORTS=\
3030
-s EXPORTED_FUNCTIONS="['_Py_Initialize', '_PyRun_SimpleString']" -s "EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap']"
3131

3232
empython.js: python/libpython3.5.a
33-
python2 mapfiles.py python/Lib datafilezip > js/postJs.js
33+
./mapfiles.py python/Lib datafilezip > js/postJs.js
3434
cat js/postJs.js.in >> js/postJs.js
3535
emcc $(EMFLAGS) $(EMEXPORTS) -o $@ $< python/Modules/zlib/libz.a
3636

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
= empython
2+
3+
== Get it
4+
5+
First, clone and initialise submodules:
6+
7+
```
8+
$ git clone [email protected]:aidanhs/empython.git
9+
$ cd empython
10+
$ git submodule update --init
11+
```
12+
13+
== Build it
14+
15+
If you have emscripten 2.0.7 installed (other versions may or may not work):
116

217
```
318
$ cd python
@@ -6,3 +21,13 @@ $ make -f ../Makefile em
621
$ cd ..
722
$ make empython.js
823
```
24+
25+
If you have docker or podman (below I'll use podman, I think you'll need to add `-u $(id -u):$(id -g)` for Docker):
26+
27+
```
28+
$ podman pull emscripten/emsdk:2.0.7
29+
$ podman run -it --rm -v $(pwd):/src emscripten/emsdk:2.0.7 bash -c "cd python && make -f ../Makefile prep && make -f ../Makefile em && cd .. && make empython.js"
30+
$ ls -l empython.{js,wasm}
31+
.rw-r--r-- 2.9M aidanhs 25 Oct 14:52 empython.js
32+
.rwxr-xr-x 1.9M aidanhs 25 Oct 14:52 empython.wasm
33+
```

mapfiles.py

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
from __future__ import print_function
33

44
import os
55
import sys
66
import py_compile
77
from zipfile import ZipFile, ZIP_DEFLATED
8-
from StringIO import StringIO
8+
from io import BytesIO
99
from subprocess import check_call
1010
import base64
1111

@@ -17,7 +17,7 @@ def mk_contents(data):
1717
'for(i=0;i<%s;i++)a[i]=t.charCodeAt(i);'
1818
'return a'
1919
'})()'
20-
) % (base64.b64encode(data), len(data), len(data))
20+
) % (base64.b64encode(data).decode('ascii'), len(data), len(data))
2121

2222
def files_to_datafilecalls(fpaths):
2323
basedir = '/usr/local/lib/python3.5'
@@ -44,7 +44,7 @@ def files_to_datafilecalls(fpaths):
4444
return commands
4545

4646
def files_to_datafilezipcall(fpaths):
47-
zf = StringIO()
47+
zf = BytesIO()
4848
zipfile = ZipFile(zf, 'w', ZIP_DEFLATED)
4949
for fpath, targetdir in fpaths:
5050
zipfile.write(fpath, os.path.join(targetdir, os.path.basename(fpath)))

0 commit comments

Comments
 (0)