Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit 28a2697

Browse files
committed
Fix lints for wasm libraries
1 parent 00ebbcc commit 28a2697

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
# black's line length
3+
max-line-length = 88

wasm/lib/Lib/_microdistlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# taken from https://bitbucket.org/pypa/distlib/src/master/distlib/util.py
2+
# flake8: noqa
3+
# fmt: off
24

35
from types import SimpleNamespace as Container
46
import re

wasm/lib/Lib/asyncweb.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from _js import Promise
2-
from collections.abc import Coroutine, Awaitable
3-
from abc import ABC, abstractmethod
2+
from collections.abc import Coroutine
43

54
try:
65
import browser
@@ -61,9 +60,11 @@ def main(async_func):
6160
async def _main_wrapper(coro):
6261
try:
6362
await coro
64-
except:
65-
import traceback, sys
63+
except: # noqa: E722
64+
import traceback
65+
import sys
6666

67+
# TODO: sys.stderr on wasm
6768
traceback.print_exc(file=sys.stdout)
6869

6970

@@ -198,7 +199,7 @@ def promise_done(success, res):
198199
_settimeout = browser.window.get_prop("setTimeout")
199200

200201
def timeout(ms):
201-
prom = asyncweb.CallbackPromise()
202+
prom = CallbackPromise()
202203

203204
@browser.jsclosure_once
204205
def cb(this):

wasm/lib/Lib/browser.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
1-
from _browser import *
1+
from _browser import (
2+
fetch,
3+
request_animation_frame,
4+
cancel_animation_frame,
5+
Document,
6+
Element,
7+
load_module,
8+
)
29

310
from _js import JSValue, Promise
411
from _window import window
512

13+
__all__ = [
14+
"jsstr",
15+
"jsclosure",
16+
"jsclosure_once",
17+
"jsfloat",
18+
"NULL",
19+
"UNDEFINED",
20+
"alert",
21+
"confirm",
22+
"prompt",
23+
"fetch",
24+
"request_animation_frame",
25+
"cancel_animation_frame",
26+
"Document",
27+
"Element",
28+
"load_module",
29+
"JSValue",
30+
"Promise",
31+
]
32+
633

734
jsstr = window.new_from_str
835
jsclosure = window.new_closure
936
jsclosure_once = window.new_closure_once
1037
_jsfloat = window.new_from_float
1138

39+
UNDEFINED = window.undefined()
40+
NULL = window.null()
41+
1242

1343
def jsfloat(n):
1444
return _jsfloat(float(n))
@@ -41,4 +71,6 @@ def prompt(msg, default_val=None):
4171
if default_val is not None and type(default_val) != str:
4272
raise TypeError("default_val must be a string")
4373

44-
return _prompt.call(*(jsstr(arg) for arg in [msg, default_val] if arg)).as_str()
74+
return _prompt.call(
75+
jsstr(msg), jsstr(default_val) if default_val else UNDEFINED
76+
).as_str()

wasm/lib/Lib/whlimport.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import asyncweb
44
import io
55
import re
6-
from urllib.parse import urlparse, unquote
6+
import posixpath
7+
from urllib.parse import urlparse
78
import _frozen_importlib as _bootstrap
89
import _microdistlib
910

@@ -74,7 +75,7 @@ async def _load_info_pypi(pkg):
7475
try:
7576
dl = next(dl for dl in ver_downloads if dl["packagetype"] == "bdist_wheel")
7677
except StopIteration:
77-
raise ValueError(f"no wheel available for package {Name!r} {ver}")
78+
raise ValueError(f"no wheel available for package {name!r} {ver}")
7879
return (
7980
name,
8081
dl["filename"],
@@ -124,11 +125,11 @@ def get_source(cls, fullname):
124125

125126
@classmethod
126127
def _get_source(cls, spec):
127-
origin = spec.origin
128-
if not origin or not origin.startswith("zip:"):
129-
raise ImportError(f"{module.__spec__.name!r} is not a zip module")
128+
origin = spec.origin and remove_prefix(spec.origin, "zip:")
129+
if not origin:
130+
raise ImportError(f"{spec.name!r} is not a zip module")
130131

131-
zipname, slash, path = origin[len("zip:") :].partition("/")
132+
zipname, slash, path = origin.partition("/")
132133
return cls._packages[zipname].read(path).decode()
133134

134135
@classmethod
@@ -141,6 +142,13 @@ def exec_module(cls, module):
141142
_bootstrap._call_with_frames_removed(exec, code, module.__dict__)
142143

143144

145+
def remove_prefix(s, prefix):
146+
if s.startswith(prefix):
147+
return s[len(prefix) :] # noqa: E203
148+
else:
149+
return None
150+
151+
144152
_zip_searchorder = (
145153
("/__init__.pyc", True, True),
146154
("/__init__.py", False, True),

0 commit comments

Comments
 (0)