forked from Rust-related/RustPython
Fix lints for wasm libraries
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# taken from https://bitbucket.org/pypa/distlib/src/master/distlib/util.py
|
||||
# flake8: noqa
|
||||
# fmt: off
|
||||
|
||||
from types import SimpleNamespace as Container
|
||||
import re
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from _js import Promise
|
||||
from collections.abc import Coroutine, Awaitable
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Coroutine
|
||||
|
||||
try:
|
||||
import browser
|
||||
@@ -61,9 +60,11 @@ def main(async_func):
|
||||
async def _main_wrapper(coro):
|
||||
try:
|
||||
await coro
|
||||
except:
|
||||
import traceback, sys
|
||||
except: # noqa: E722
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
# TODO: sys.stderr on wasm
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
|
||||
|
||||
@@ -198,7 +199,7 @@ if browser:
|
||||
_settimeout = browser.window.get_prop("setTimeout")
|
||||
|
||||
def timeout(ms):
|
||||
prom = asyncweb.CallbackPromise()
|
||||
prom = CallbackPromise()
|
||||
|
||||
@browser.jsclosure_once
|
||||
def cb(this):
|
||||
|
||||
@@ -1,14 +1,44 @@
|
||||
from _browser import *
|
||||
from _browser import (
|
||||
fetch,
|
||||
request_animation_frame,
|
||||
cancel_animation_frame,
|
||||
Document,
|
||||
Element,
|
||||
load_module,
|
||||
)
|
||||
|
||||
from _js import JSValue, Promise
|
||||
from _window import window
|
||||
|
||||
__all__ = [
|
||||
"jsstr",
|
||||
"jsclosure",
|
||||
"jsclosure_once",
|
||||
"jsfloat",
|
||||
"NULL",
|
||||
"UNDEFINED",
|
||||
"alert",
|
||||
"confirm",
|
||||
"prompt",
|
||||
"fetch",
|
||||
"request_animation_frame",
|
||||
"cancel_animation_frame",
|
||||
"Document",
|
||||
"Element",
|
||||
"load_module",
|
||||
"JSValue",
|
||||
"Promise",
|
||||
]
|
||||
|
||||
|
||||
jsstr = window.new_from_str
|
||||
jsclosure = window.new_closure
|
||||
jsclosure_once = window.new_closure_once
|
||||
_jsfloat = window.new_from_float
|
||||
|
||||
UNDEFINED = window.undefined()
|
||||
NULL = window.null()
|
||||
|
||||
|
||||
def jsfloat(n):
|
||||
return _jsfloat(float(n))
|
||||
@@ -41,4 +71,6 @@ def prompt(msg, default_val=None):
|
||||
if default_val is not None and type(default_val) != str:
|
||||
raise TypeError("default_val must be a string")
|
||||
|
||||
return _prompt.call(*(jsstr(arg) for arg in [msg, default_val] if arg)).as_str()
|
||||
return _prompt.call(
|
||||
jsstr(msg), jsstr(default_val) if default_val else UNDEFINED
|
||||
).as_str()
|
||||
|
||||
@@ -3,7 +3,8 @@ import zipfile
|
||||
import asyncweb
|
||||
import io
|
||||
import re
|
||||
from urllib.parse import urlparse, unquote
|
||||
import posixpath
|
||||
from urllib.parse import urlparse
|
||||
import _frozen_importlib as _bootstrap
|
||||
import _microdistlib
|
||||
|
||||
@@ -74,7 +75,7 @@ async def _load_info_pypi(pkg):
|
||||
try:
|
||||
dl = next(dl for dl in ver_downloads if dl["packagetype"] == "bdist_wheel")
|
||||
except StopIteration:
|
||||
raise ValueError(f"no wheel available for package {Name!r} {ver}")
|
||||
raise ValueError(f"no wheel available for package {name!r} {ver}")
|
||||
return (
|
||||
name,
|
||||
dl["filename"],
|
||||
@@ -124,11 +125,11 @@ class ZipFinder:
|
||||
|
||||
@classmethod
|
||||
def _get_source(cls, spec):
|
||||
origin = spec.origin
|
||||
if not origin or not origin.startswith("zip:"):
|
||||
raise ImportError(f"{module.__spec__.name!r} is not a zip module")
|
||||
origin = spec.origin and remove_prefix(spec.origin, "zip:")
|
||||
if not origin:
|
||||
raise ImportError(f"{spec.name!r} is not a zip module")
|
||||
|
||||
zipname, slash, path = origin[len("zip:") :].partition("/")
|
||||
zipname, slash, path = origin.partition("/")
|
||||
return cls._packages[zipname].read(path).decode()
|
||||
|
||||
@classmethod
|
||||
@@ -141,6 +142,13 @@ class ZipFinder:
|
||||
_bootstrap._call_with_frames_removed(exec, code, module.__dict__)
|
||||
|
||||
|
||||
def remove_prefix(s, prefix):
|
||||
if s.startswith(prefix):
|
||||
return s[len(prefix) :] # noqa: E203
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
_zip_searchorder = (
|
||||
("/__init__.pyc", True, True),
|
||||
("/__init__.py", False, True),
|
||||
|
||||
Reference in New Issue
Block a user