Skip to content

Commit d94ccfa

Browse files
committed
inital version of code runner
1 parent 5acb2e3 commit d94ccfa

36 files changed

+1395
-5
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length=88
3+
extend-ignore=E203,D104,D100,I004,E501
4+
exclude=tests/data/*

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
105+
__pypackages__/
106+
107+
# Celery stuff
108+
celerybeat-schedule
109+
celerybeat.pid
110+
111+
# SageMath parsed files
112+
*.sage.py
113+
114+
# Environments
115+
.env
116+
.venv
117+
env/
118+
venv/
119+
ENV/
120+
env.bak/
121+
venv.bak/
122+
123+
# Spyder project settings
124+
.spyderproject
125+
.spyproject
126+
127+
# Rope project settings
128+
.ropeproject
129+
130+
# mkdocs documentation
131+
/site
132+
133+
# mypy
134+
.mypy_cache/
135+
.dmypy.json
136+
dmypy.json
137+
138+
# Pyre type checker
139+
.pyre/
140+
141+
# pytype static type analyzer
142+
.pytype/
143+
144+
# Cython debug symbols
145+
cython_debug/
146+
147+
# PyCharm
148+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
149+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
150+
# and can be added to the global gitignore or merged into this file. For a more nuclear
151+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
152+
#.idea/

.pre-commit-config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 19.10b0
4+
hooks:
5+
- id: black
6+
args: [--safe, --quiet]
7+
- repo: https://github.com/asottile/blacken-docs
8+
rev: v1.7.0
9+
hooks:
10+
- id: blacken-docs
11+
additional_dependencies: [black==19.10b0]
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v3.2.0
14+
hooks:
15+
- id: trailing-whitespace
16+
- id: end-of-file-fixer
17+
# - repo: https://github.com/pre-commit/mirrors-isort
18+
# rev: v5.2.2
19+
# hooks:
20+
# - id: isort
21+
# exclude: tests/data
22+
- repo: https://gitlab.com/pycqa/flake8
23+
rev: 3.8.3
24+
hooks:
25+
- id: flake8
26+
exclude: tests/data
27+
language_version: python3
28+
additional_dependencies:
29+
- flake8-typing-imports==1.9.0
30+
- flake8-builtins==1.5.3
31+
- flake8-bugbear==20.1.4
32+
# - flake8-isort==3.0.1

LICENSE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Copyright (c) 2022 Dr. Thorsten Beier
2+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3+
4+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5+
6+
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.

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# pyjs-code-runner
22

3-
Write cross platform build scripts with the power of Python!
4-
To be used in the `boa` project.
3+
A driver to run python code in a wasm environment, almost like running vanilla python code.
54

6-
Currently supports `CMake`, `Autotools`, `Meson` and `Make`.
75

86
## Examples
97

10-
More coming soon!
118

12-
### CMake
139

1410
```bash
1511
# run in node backend
@@ -36,5 +32,19 @@ pyjs_code_runner run script \
3632
--async-main \
3733
--headless
3834

35+
```
36+
37+
38+
```bash
39+
# run in browser-worker-thread backend
40+
# in a headless fashion
41+
pyjs_code_runner run script \
42+
browser-worker \
43+
--conda-env /home/web_user/env \
44+
--mount ~/src/pyjs/tests:/tests \
45+
--script main.py \
46+
--work-dir /tests \
47+
--async-main \
48+
--headless
3949

4050
```

pyjs_code_runner/__init__.py

Whitespace-only changes.

pyjs_code_runner/backend/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from enum import Enum
2+
3+
from .node.node import NodeBackend
4+
from .browser_main.browser_main import BrowserMainBackend
5+
from .browser_worker.browser_worker import BrowserWorkerBackend
6+
7+
8+
class BackendFamilyType(str, Enum):
9+
browser = "browsef"
10+
node = "node"
11+
12+
13+
class BackendType(str, Enum):
14+
browser_main = "browser-main"
15+
browser_worker = "browser-worker"
16+
node = "node"
17+
18+
19+
def get_backend_type_family(backend):
20+
if backend == BackendType.node:
21+
return BackendFamilyType.node
22+
else:
23+
return BackendFamilyType.browser
24+
25+
26+
def get_backend_cls(backend_type):
27+
if backend_type == BackendType.node:
28+
return NodeBackend
29+
elif backend_type == BackendType.browser_main:
30+
return BrowserMainBackend
31+
elif backend_type == BackendType.browser_worker:
32+
return BrowserWorkerBackend
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from ..constants import JS_DIR, HTML_DIR
2+
3+
4+
class BackendBase(object):
5+
def __init__(self, host_work_dir, work_dir, script, async_main):
6+
self.host_work_dir = host_work_dir
7+
self.script = script
8+
self.work_dir = work_dir
9+
self.async_main = async_main
10+
11+
def js_utils(self):
12+
with open(JS_DIR / "utils.js") as f:
13+
content = f.read()
14+
15+
return content

pyjs_code_runner/backend/browser_main/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)