Skip to content

Commit e4fb800

Browse files
authored
Clean up unused imports, run black (#9)
* Clean up unused imports, run black * More cleanup * Fix workflow * Fix missing pack_mounts
1 parent 2248235 commit e4fb800

File tree

12 files changed

+35
-77
lines changed

12 files changed

+35
-77
lines changed

.github/workflows/main.yaml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ defaults:
1212

1313

1414
jobs:
15-
1615
test_with_conda:
17-
1816
runs-on: ubuntu-latest
19-
20-
strategy:
21-
fail-fast: false
22-
2317
steps:
2418
- uses: actions/checkout@v2
2519

@@ -41,20 +35,15 @@ jobs:
4135
run: |
4236
micromamba activate dev-env
4337
python -m pip install . --no-deps
44-
45-
- name: Run Tests
38+
39+
- name: Run Tests
4640
run: |
4741
micromamba activate dev-env
4842
pytest -s
4943
5044
5145
test_with_pip:
52-
5346
runs-on: ubuntu-latest
54-
55-
strategy:
56-
fail-fast: false
57-
5847
steps:
5948
- uses: actions/checkout@v2
6049

@@ -71,13 +60,10 @@ jobs:
7160
- name: Install pyjs-code-runner
7261
run: |
7362
micromamba activate dev-env
74-
python -m pip install .
63+
python -m pip install .
7564
playwright install
76-
77-
- name: Run Tests
65+
66+
- name: Run Tests
7867
run: |
7968
micromamba activate dev-env
80-
8169
pytest -s
82-
83-

pyjs_code_runner/backend/backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def ensure_playwright_imports():
6161

6262
def get_backend_cls(backend_type):
6363
if backend_type == BackendType.node:
64-
raise RuntimeError("the node backend is currently disabled as its not (yet) working with empack>=3.0.0")
65-
64+
raise RuntimeError(
65+
"the node backend is currently disabled as its not (yet) working with empack>=3.0.0"
66+
)
6667

6768
elif backend_type == BackendType.browser_main:
6869
ensure_playwright_imports()

pyjs_code_runner/backend/browser_main/browser_main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(
2828
self.slow_mo = slow_mo
2929

3030
def run(self):
31-
3231
browser_main_html = "browser_main.html"
3332
main = HTML_DIR / browser_main_html
3433
shutil.copyfile(main, self.host_work_dir / browser_main_html)

pyjs_code_runner/backend/browser_worker/browser_worker.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def __init__(
2525
self.slow_mo = slow_mo
2626

2727
def run(self):
28-
2928
# copy html
3029
browser_worker_html = "browser_worker.html"
3130
main = HTML_DIR / browser_worker_html
@@ -40,7 +39,6 @@ def run(self):
4039
server,
4140
url,
4241
):
43-
4442
page_url = f"{url}/{browser_worker_html}"
4543
ret = asyncio.run(self.playwright_run_in_worker_thread(page_url=page_url))
4644
if ret != 0:
@@ -97,10 +95,8 @@ async def handle_worker(worker):
9795

9896
async def handle_console(msg):
9997
txt = str(msg)
100-
if (
101-
txt.startswith(
102-
"warning: Browser does not support creating object URLs"
103-
)
98+
if txt.startswith(
99+
"warning: Browser does not support creating object URLs"
104100
):
105101
pass
106102
else:

pyjs_code_runner/cli/run.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import os
21
from pathlib import Path
32
from typing import List, Optional
4-
import json
53
import typer
64

75

@@ -53,7 +51,7 @@ def parse_mounts(mounts):
5351
script_option = require_option(
5452
*make_names("script"), help="path of script inside the virtual fileystem to run"
5553
)
56-
relocate_prefix_option = typer.Option(
54+
relocate_prefix_option = typer.Option(
5755
"/",
5856
*make_names("relocate-prefix"),
5957
help="location of the conda environment in the virtual file",
@@ -238,15 +236,14 @@ def run_script(
238236
use_cache,
239237
backend_kwargs=None,
240238
):
241-
242239
if backend_kwargs is None:
243240
backend_kwargs = dict()
244241
mounts = parse_mounts(mounts)
245242
if use_cache:
246243
cache_dir = get_cache_dir(cache_dir=cache_dir)
247244
else:
248245
cache_dir = None
249-
pkg_file_filter = get_file_filter(pkg_file_filter, cache_dir=cache_dir)
246+
pkg_file_filter = get_file_filter(pkg_file_filter)
250247

251248
run(
252249
conda_env=conda_env,

pyjs_code_runner/constants.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
from pathlib import Path
22
import os
33

4-
EXPORT_NAME_SUFFIX = "EmscriptenForgeModule"
54
EMSCRIPTEN_HOME = "/home/web_user"
6-
EMPACK_FILE_FILTER_URL = (
7-
"https://raw.githubusercontent.com/emscripten-forge/recipes/main/empack_config.yaml"
8-
)
9-
10-
115
_THIS_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
126

137
JS_DIR = _THIS_DIR / "js"

pyjs_code_runner/get_cache_dir.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from appdirs import user_data_dir
21
import appdirs
2+
33
from pathlib import Path
44

5-
def get_appdir():
65

6+
def get_appdir():
77
path = Path(appdirs.user_data_dir("pyjs_code_runner", "ThorstenBeier"))
88
path.mkdir(parents=True, exist_ok=True)
99
return path
1010

1111

12-
1312
def get_cache_dir(cache_dir=None):
1413
if cache_dir is None:
1514
return get_appdir()
1615
else:
17-
return Path(cache_dir)
16+
return Path(cache_dir)

pyjs_code_runner/get_file_filter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import urllib.request
2-
from pathlib import Path
31
from empack.file_patterns import pkg_file_filter_from_yaml
42

5-
from .constants import EMPACK_FILE_FILTER_URL
63

7-
8-
def get_file_filter(pkg_file_filter, cache_dir):
4+
def get_file_filter(pkg_file_filter):
95
if pkg_file_filter is None or len(pkg_file_filter) == 0:
106
return None
117
else:

pyjs_code_runner/js_global_object.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

pyjs_code_runner/run.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from .backend.backend import BackendType, get_backend_type_family, get_backend_cls
2-
from .constants import EXPORT_NAME_SUFFIX
3-
from .js_global_object import js_global_object
42
from .work_dir_context import work_dir_context
53
from .get_cache_dir import get_cache_dir
64

@@ -14,17 +12,21 @@
1412
import os
1513
import shutil
1614
import json
17-
import sys
18-
19-
def pack_mounts(mounts, host_work_dir, backend_type):
2015

2116

17+
def pack_mounts(mounts, host_work_dir, backend_type):
2218
mount_js_files = []
2319
for mount_index, (host_path, em_path) in enumerate(mounts):
2420
mount_filename = f"mount_{mount_index}.tar.gz"
2521
mount_js_files.append(mount_filename)
2622
if host_path.is_dir():
27-
pack_directory(host_dir=host_path,mount_dir=em_path,outname=mount_filename,outdir=host_work_dir, compresslevel=1)
23+
pack_directory(
24+
host_dir=host_path,
25+
mount_dir=em_path,
26+
outname=mount_filename,
27+
outdir=host_work_dir,
28+
compresslevel=1,
29+
)
2830

2931
elif host_path.is_file():
3032
raise RuntimeError("packing files is not yet supported")
@@ -36,7 +38,6 @@ def pack_mounts(mounts, host_work_dir, backend_type):
3638
json.dump(mount_js_files, f, indent=4)
3739

3840

39-
4041
def conda_env_to_cache_name(conda_env, backend_type):
4142
env_name = str(conda_env).replace(os.path.sep, "_")
4243
folder_name = (
@@ -94,7 +95,7 @@ def run(
9495
relocate_prefix = str(relocate_prefix)
9596
if host_work_dir is not None:
9697
host_work_dir = Path(host_work_dir)
97-
98+
9899
if pkg_file_filter is None:
99100
pkg_file_filter = pkg_file_filter_from_yaml(EMPACK_DEFAULT_CONFIG_PATH)
100101

@@ -106,7 +107,6 @@ def run(
106107

107108
# create a temporary host work directory
108109
with host_work_dir_context(host_work_dir) as host_work_dir:
109-
110110
# copy pyjs-runtime to host-work-dir
111111
copy_pyjs(
112112
conda_env=conda_env,
@@ -116,16 +116,18 @@ def run(
116116
)
117117

118118
# pack the environment itself
119-
pack_env(env_prefix=conda_env,
120-
relocate_prefix=relocate_prefix,
121-
file_filters=pkg_file_filter,
122-
use_cache=use_cache,
123-
cache_dir=cache_dir,
124-
outdir=host_work_dir,
125-
compresslevel=9)
119+
pack_env(
120+
env_prefix=conda_env,
121+
relocate_prefix=relocate_prefix,
122+
file_filters=pkg_file_filter,
123+
use_cache=use_cache,
124+
cache_dir=cache_dir,
125+
outdir=host_work_dir,
126+
compresslevel=9,
127+
)
126128

127129
# pack all the mounts
128-
mount_js_files = pack_mounts(
130+
pack_mounts(
129131
mounts=mounts,
130132
backend_type=backend_type,
131133
host_work_dir=host_work_dir,
@@ -142,4 +144,3 @@ def run(
142144

143145
# run
144146
backend.run()
145-

0 commit comments

Comments
 (0)