Skip to content

Commit c1cc787

Browse files
committed
Run black
1 parent 1767024 commit c1cc787

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

wasm/lib/Lib/asyncweb.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ async def _main_wrapper(coro):
4949
try:
5050
await coro
5151
except:
52-
try:
53-
import traceback, sys
54-
traceback.print_exc(file=sys.stdout)
55-
except BaseException as e:
56-
tb = e.__traceback__
57-
while tb:
58-
print(tb.tb_lineno, tb.tb_frame.f_code.co_name, tb.tb_frame.f_code.co_filename)
59-
tb = tb.tb_next
60-
print(type(e), e)
52+
import traceback, sys
53+
54+
traceback.print_exc(file=sys.stdout)
6155

6256

6357
def _resolve(prom):

wasm/lib/Lib/whlimport.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,105 +5,124 @@
55
import _frozen_importlib as _bootstrap
66

77
_IS_SETUP = False
8+
9+
810
def setup(*, log=print):
911
global _IS_SETUP, LOG_FUNC
1012

1113
if not _IS_SETUP:
1214
import sys
15+
1316
sys.meta_path.insert(0, WheelFinder)
1417
_IS_SETUP = True
1518

1619
if not log:
20+
1721
def LOG_FUNC(log):
1822
pass
23+
1924
else:
2025
LOG_FUNC = log
2126

27+
2228
async def load_package(*args):
2329
await asyncweb.wait_all(_load_package(pkg) for pkg in args)
2430

31+
2532
_loaded_packages = {}
2633

2734
LOG_FUNC = print
2835

36+
2937
async def _load_package(pkg):
3038
# TODO: support pkg==X.Y semver specifiers as well as arbitrary URLs
31-
info = await browser.fetch(f'https://pypi.org/pypi/{pkg}/json', response_format="json")
32-
name = info['info']['name']
33-
ver = info['info']['version']
34-
ver_downloads = info['releases'][ver]
39+
info = await browser.fetch(
40+
f"https://pypi.org/pypi/{pkg}/json", response_format="json"
41+
)
42+
name = info["info"]["name"]
43+
ver = info["info"]["version"]
44+
ver_downloads = info["releases"][ver]
3545
try:
36-
dl = next(dl for dl in ver_downloads if dl['packagetype'] == 'bdist_wheel')
46+
dl = next(dl for dl in ver_downloads if dl["packagetype"] == "bdist_wheel")
3747
except StopIteration:
3848
raise ValueError(f"no wheel available for package {Name!r} {ver}")
3949
if name in _loaded_packages:
4050
return
41-
fname = dl['filename']
51+
fname = dl["filename"]
4252
LOG_FUNC(f"Downloading {fname} ({format_size(dl['size'])})...")
43-
zip_data = io.BytesIO(await browser.fetch(dl['url'], response_format="array_buffer"))
53+
zip_data = io.BytesIO(
54+
await browser.fetch(dl["url"], response_format="array_buffer")
55+
)
4456
size = len(zip_data.getbuffer())
4557
LOG_FUNC(f"{fname} done!")
4658
_loaded_packages[name] = zipfile.ZipFile(zip_data)
4759

60+
4861
def format_size(bytes):
4962
# type: (float) -> str
5063
if bytes > 1000 * 1000:
51-
return '{:.1f} MB'.format(bytes / 1000.0 / 1000)
64+
return "{:.1f} MB".format(bytes / 1000.0 / 1000)
5265
elif bytes > 10 * 1000:
53-
return '{} kB'.format(int(bytes / 1000))
66+
return "{} kB".format(int(bytes / 1000))
5467
elif bytes > 1000:
55-
return '{:.1f} kB'.format(bytes / 1000.0)
68+
return "{:.1f} kB".format(bytes / 1000.0)
5669
else:
57-
return '{} bytes'.format(int(bytes))
70+
return "{} bytes".format(int(bytes))
71+
5872

5973
class WheelFinder:
6074
_packages = _loaded_packages
61-
75+
6276
@classmethod
6377
def find_spec(cls, fullname, path=None, target=None):
64-
path = fullname.replace('.', '/')
78+
path = fullname.replace(".", "/")
6579
for zname, z in cls._packages.items():
6680
mi, fullpath = _get_module_info(z, path)
6781
if mi is not None:
68-
return _bootstrap.spec_from_loader(fullname, cls, origin=f'wheel:{zname}/{fullpath}', is_package=mi)
82+
return _bootstrap.spec_from_loader(
83+
fullname, cls, origin=f"wheel:{zname}/{fullpath}", is_package=mi
84+
)
6985
return None
70-
86+
7187
@classmethod
7288
def create_module(cls, spec):
7389
return None
74-
90+
7591
@classmethod
7692
def get_source(cls, fullname):
7793
spec = cls.find_spec(fullname)
7894
if spec:
7995
return cls._get_source(spec)
8096
else:
81-
raise ImportError('cannot find source for module', name=fullname)
97+
raise ImportError("cannot find source for module", name=fullname)
8298

8399
@classmethod
84100
def _get_source(cls, spec):
85101
origin = spec.origin
86102
if not origin or not origin.startswith("wheel:"):
87-
raise ImportError(f'{module.__spec__.name!r} is not a zip module')
103+
raise ImportError(f"{module.__spec__.name!r} is not a zip module")
88104

89-
zipname, slash, path = origin[len('wheel:'):].partition('/')
105+
zipname, slash, path = origin[len("wheel:") :].partition("/")
90106
return cls._packages[zipname].read(path).decode()
91107

92108
@classmethod
93109
def exec_module(cls, module):
94110
spec = module.__spec__
95111
source = cls._get_source(spec)
96-
code = _bootstrap._call_with_frames_removed(compile, source, spec.origin, 'exec', dont_inherit=True)
112+
code = _bootstrap._call_with_frames_removed(
113+
compile, source, spec.origin, "exec", dont_inherit=True
114+
)
97115
_bootstrap._call_with_frames_removed(exec, code, module.__dict__)
98116

99117

100118
_zip_searchorder = (
101119
# (path_sep + '__init__.pyc', True, True),
102-
('/__init__.py', False, True),
120+
("/__init__.py", False, True),
103121
# ('.pyc', True, False),
104-
('.py', False, False),
122+
(".py", False, False),
105123
)
106124

125+
107126
def _get_module_info(zf, path):
108127
for suffix, isbytecode, ispackage in _zip_searchorder:
109128
fullpath = path + suffix

0 commit comments

Comments
 (0)