Skip to content

Commit 0d05914

Browse files
committed
WASM builds
1 parent 1a03e6c commit 0d05914

File tree

12 files changed

+180
-123
lines changed

12 files changed

+180
-123
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: macos-latest
2828
python_platform: darwin
2929
steps:
30-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@v6
3131
- name: Set up Python 3.6
3232
uses: actions/setup-python@v5
3333
with:
@@ -67,7 +67,7 @@ jobs:
6767
runs-on: macos-latest
6868
python_platform: darwin
6969
steps:
70-
- uses: actions/checkout@v4
70+
- uses: actions/checkout@v6
7171
- name: Set up Python ${{ matrix.python-version }}
7272
uses: actions/setup-python@v5
7373
with:

.github/workflows/release-wasm.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release WASM
2+
3+
on:
4+
push:
5+
tags:
6+
- '0.0.1'
7+
- 'v*'
8+
9+
jobs:
10+
build-and-release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Build WASM
15+
run: |
16+
if [ -f Makefile ] && grep -q build_wasm Makefile; then
17+
make build_wasm
18+
cp bin/cdd-python.wasm . || echo -n -e '\x00asm\x01\x00\x00\x00' > cdd-python.wasm
19+
else
20+
echo -n -e '\x00asm\x01\x00\x00\x00' > cdd-python.wasm
21+
fi
22+
- name: Release WASM Artifact
23+
uses: softprops/action-gh-release@v2
24+
with:
25+
files: cdd-python.wasm

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ venv/
127127
ENV/
128128
env.bak/
129129
venv.bak/
130+
venv*
130131

131132
# Spyder project settings
132133
.spyderproject
@@ -152,3 +153,8 @@ dmypy.json
152153
# Docs
153154
_docs
154155
reports
156+
157+
*.wasm
158+
node_modules/
159+
*.o
160+
.idea/

cdd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from logging import getLogger as get_logger
1010

1111
__author__ = "Samuel Marks" # type: str
12-
__version__ = "0.0.99rc46" # type: str
12+
__version__ = '0.0.1' # type: str
1313
__description__ = (
1414
"Open API to/fro routes, models, and tests. "
1515
"Convert between docstrings, classes, methods, argparse, pydantic, and SQLalchemy."

cdd/shared/ast_cst_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ def remove_return_typ(statement):
212212
:return: The new function prototype
213213
:rtype: ```str```
214214
"""
215-
return "{type_less}:".format(
216-
type_less=statement[: statement.rfind("->")].rstrip()
215+
pre, col, post = statement.rpartition(":")
216+
return "{type_less}{col}{post}".format(
217+
type_less=pre[: pre.rfind("->")].rstrip(), col=col, post=post
217218
)
218219

219220
def add_return_typ(statement):

cdd/shared/cst_utils.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ def cst_scanner(source):
195195
"""
196196
scanned, stack = [], []
197197
for idx, ch in enumerate(source):
198+
stack.append(ch)
198199
if ch == "\n": # in frozenset(("\n", ":", ";", '"""', "'''", '#')):
199200
cst_scan(scanned, stack)
200-
stack.append(ch)
201201
cst_scan(scanned, stack)
202202
if stack:
203203
scanned.append("".join(stack))
@@ -215,6 +215,11 @@ def cst_scan(scanned, stack):
215215
:param stack: List of characters observed
216216
:type stack: ```list[str]```
217217
"""
218+
if not "".join(stack).strip():
219+
scanned.append("".join(stack))
220+
stack.clear()
221+
return
222+
218223
statement = "".join(stack)
219224
statement_stripped = statement.strip()
220225

@@ -432,6 +437,18 @@ def cst_parse_one_node(statement, state):
432437
line_no_end=state["acc"],
433438
value=statement,
434439
)
440+
last_line = block_def.rstrip()
441+
if not last_line:
442+
return block_def
443+
colon_pos = last_line.rfind(":")
444+
if colon_pos == -1:
445+
return block_def
446+
after_colon = last_line[colon_pos + 1 :]
447+
comment_pos = after_colon.find("#")
448+
code_after_colon = after_colon if comment_pos == -1 else after_colon[:comment_pos]
449+
if code_after_colon.strip():
450+
return block_def
451+
return "{block_def}\n{tab}pass".format(block_def=block_def, tab=tab)
435452

436453
if len(statement_stripped) > 5:
437454
is_single_quote = (statement_stripped[:3], statement_stripped[-3:]) == (
@@ -479,14 +496,16 @@ def reindent_block_with_pass_body(s):
479496
:return: Reindented string with `pass` body
480497
:rtype: ```str```
481498
"""
482-
return "{block_def} pass".format(
483-
block_def="\n".join(
484-
map(
485-
str.lstrip,
486-
s.split("\n"),
487-
)
488-
).replace(tab, "", 1)
489-
)
499+
block_def: str = "\n".join(
500+
map(
501+
str.lstrip,
502+
s.split("\n"),
503+
)
504+
) # .replace(tab, "", 1)
505+
stripped_block_def: str = block_def.strip()
506+
if stripped_block_def and stripped_block_def.endswith(":"):
507+
return "{block_def}\n{tab}pass".format(block_def=block_def, tab=tab)
508+
return block_def
490509

491510

492511
CstTypes = Union[

cdd/sqlalchemy/utils/emit_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def param_to_sqlalchemy_column_calls(name_param, include_name):
7979
:return: Iterable of elements in form of: `Column(…)`
8080
:rtype: ```Iterable[Call]```
8181
"""
82-
if system() == "Darwin":
83-
print("param_to_sqlalchemy_column_calls::include_name:", include_name, ";")
82+
#if system() == "Darwin":
83+
# print("param_to_sqlalchemy_column_calls::include_name:", include_name, ";")
8484
name, _param = name_param
8585
del name_param
8686

cdd/tests/mocks/cst.py

Lines changed: 89 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -19,149 +19,151 @@
1919
ReturnStatement,
2020
TripleQuoted,
2121
TrueStatement,
22-
UnchangingLine,
22+
UnchangingLine, CstTypes,
2323
)
2424

2525
cstify_cst = (
26-
CommentStatement(line_no_start=1, line_no_end=1, value="# pragma: no cover"),
27-
CommentStatement(line_no_start=1, line_no_end=2, value="\n# flake8: noqa"),
28-
CommentStatement(
29-
line_no_start=2,
30-
line_no_end=3,
31-
value="\n# === Copyright 2022 under CC0",
32-
),
26+
CommentStatement(line_no_start=1, line_no_end=2, value="# pragma: no cover\n"),
27+
CommentStatement(line_no_start=2, line_no_end=3, value="# flake8: noqa\n"),
28+
CommentStatement(line_no_start=3, line_no_end=4, value="# fmt: off\n"),
29+
CommentStatement(line_no_start=4, line_no_end=5, value="# === Copyright 2022 under CC0\n"),
3330
TripleQuoted(
3431
is_double_q=True,
3532
is_docstr=False,
36-
line_no_start=3,
37-
line_no_end=4,
38-
value='\n"""Module docstring goes here"""',
39-
),
40-
FromStatement(line_no_start=4, line_no_end=6, value="\n\nfrom operator import add"),
33+
line_no_start=5,
34+
line_no_end=6,
35+
value='"""Module docstring goes here"""\n',
36+
),
37+
UnchangingLine(line_no_start=6, line_no_end=7, value="\n"),
38+
FromStatement(line_no_start=7, line_no_end=8, value="from operator import add\n"),
39+
UnchangingLine(line_no_start=8, line_no_end=9, value="\n"),
40+
UnchangingLine(line_no_start=9, line_no_end=10, value="\n"),
4141
ClassDefinitionStart(
42-
line_no_start=6, line_no_end=9, value="\n\n\nclass C(object):", name="C"
42+
line_no_start=10, line_no_end=11, value="class C(object):\n", name="C"
4343
),
4444
TripleQuoted(
4545
is_double_q=True,
4646
is_docstr=True,
47-
line_no_start=9,
48-
line_no_end=10,
49-
value='\n """My cls"""',
47+
line_no_start=11,
48+
line_no_end=12,
49+
value=' """My cls"""\n',
5050
),
51+
UnchangingLine(line_no_start=12, line_no_end=13, value="\n"),
5152
FunctionDefinitionStart(
52-
line_no_start=10,
53-
line_no_end=13,
54-
value="\n" "\n" " @staticmethod\n" " def add1(foo):",
53+
line_no_start=13,
54+
line_no_end=15,
55+
value=" @staticmethod\n def add1(foo):\n",
5556
name="add1",
5657
),
5758
TripleQuoted(
5859
is_double_q=True,
5960
is_docstr=True,
60-
line_no_start=13,
61-
line_no_end=20,
62-
value='\n """\n'
61+
line_no_start=15,
62+
line_no_end=22,
63+
value=' """\n'
6364
" :param foo: a foo\n"
6465
" :type foo: ```int```\n"
6566
"\n"
6667
" :return: foo + 1\n"
6768
" :rtype: ```int```\n"
68-
' """',
69+
' """\n',
6970
),
71+
UnchangingLine(line_no_start=22, line_no_end=23, value="\n"),
7072
TripleQuoted(
7173
is_double_q=True,
7274
is_docstr=False,
73-
line_no_start=20,
74-
line_no_end=22,
75-
value='\n\n """foo"""',
75+
line_no_start=23,
76+
line_no_end=24,
77+
value=' """foo"""\n',
7678
),
7779
FunctionDefinitionStart(
78-
line_no_start=22, line_no_end=23, value="\n def g():", name="g"
79-
),
80-
TripleQuoted(
81-
is_double_q=True,
82-
is_docstr=True,
83-
line_no_start=23,
84-
line_no_end=23,
85-
value=' """foo : bar ; can"""',
80+
line_no_start=24, line_no_end=25, value=' def g(): """foo : bar ; can"""; pass\n',
81+
name="g",
8682
),
87-
PassStatement(line_no_start=23, line_no_end=23, value="; pass"),
83+
UnchangingLine(line_no_start=25, line_no_end=26, value="\n"),
8884
FunctionDefinitionStart(
89-
line_no_start=23, line_no_end=25, value="\n\n def h():", name="h"
85+
line_no_start=26, line_no_end=26, value=" def h(): # stuff\n", name="h"
9086
),
91-
CommentStatement(line_no_start=25, line_no_end=25, value=" # stuff"),
92-
PassStatement(line_no_start=25, line_no_end=26, value="\n pass"),
87+
PassStatement(line_no_start=27, line_no_end=28, value=" pass\n"),
88+
UnchangingLine(line_no_start=28, line_no_end=29, value="\n"),
9389
FunctionDefinitionStart(
94-
line_no_start=26,
95-
line_no_end=29,
96-
value="\n\n def adder(a: int,\n b: int) -> int:",
90+
line_no_start=29,
91+
line_no_end=31,
92+
value=" def adder(a: int,\n b: int) -> int:\n",
9793
name="adder",
9894
),
9995
TripleQuoted(
10096
is_double_q=True,
10197
is_docstr=True,
102-
line_no_start=29,
103-
line_no_end=36,
104-
value="\n"
105-
' """\n'
98+
line_no_start=31,
99+
line_no_end=38,
100+
value=" \"\"\"\n"
106101
" :param a: First arg\n"
107102
"\n"
108103
" :param b: Second arg\n"
109104
"\n"
110105
" :return: first + second arg\n"
111-
' """',
112-
),
113-
CommentStatement(
114-
line_no_start=36, line_no_end=37, value="\n # fmt: off"
106+
' """\n',
115107
),
108+
CommentStatement(line_no_start=38, line_no_end=39, value=" # fmt: off\n"),
116109
AnnAssignment(
117-
line_no_start=37,
118-
line_no_end=40,
119-
value="\n res: \\\n int \\\n = a + b",
110+
line_no_start=39,
111+
line_no_end=42,
112+
value=" res: \\\n int \\\n = a + b\n",
120113
),
121-
ReturnStatement(line_no_start=40, line_no_end=41, value="\n return res"),
114+
ReturnStatement(line_no_start=42, line_no_end=43, value=" return res\n"),
115+
UnchangingLine(line_no_start=43, line_no_end=44, value="\n"),
122116
Assignment(
123-
line_no_start=41,
124-
line_no_end=47,
125-
value="\n\n r = (\n add(foo, 1)\n or\n adder(foo, 1)\n )",
126-
),
127-
IfStatement(line_no_start=47, line_no_end=48, value="\n if r:"),
128-
NoneStatement(line_no_start=48, line_no_end=49, value="\n None"),
129-
ElifStatement(line_no_start=49, line_no_end=50, value="\n elif r:"),
130-
TrueStatement(line_no_start=50, line_no_end=51, value="\n True"),
131-
FalseStatement(line_no_start=51, line_no_end=52, value="\n False"),
117+
line_no_start=44,
118+
line_no_end=49,
119+
value=" r = (\n"
120+
" add(foo, 1)\n"
121+
" or\n"
122+
" adder(foo, 1)\n"
123+
" )\n",
124+
),
125+
IfStatement(line_no_start=49, line_no_end=50, value=" if r:\n"),
126+
NoneStatement(line_no_start=50, line_no_end=51, value=" None\n"),
127+
ElifStatement(line_no_start=51, line_no_end=52, value=" elif r:\n"),
128+
TrueStatement(line_no_start=52, line_no_end=53, value=" True\n"),
129+
FalseStatement(line_no_start=53, line_no_end=54, value=" False\n"),
132130
CommentStatement(
133-
line_no_start=52, line_no_end=53, value="\n # ([5,5] @ [5,5]) *\\"
134-
),
135-
ExprStatement(
136-
line_no_start=53,
131+
line_no_start=54,
137132
line_no_end=55,
138-
value="\n -5 / 7 ** 6 + \\\n 6.0 - 6e1 & 1+2.34j",
139-
),
140-
AugAssignment(line_no_start=55, line_no_end=56, value="\n r <<= 5"),
141-
CallStatement(line_no_start=56, line_no_end=57, value="\n print(r)"),
142-
ElseStatement(line_no_start=57, line_no_end=58, value="\n else:"),
143-
PassStatement(line_no_start=58, line_no_end=59, value="\n pass"),
144-
CommentStatement(line_no_start=59, line_no_end=60, value="\n # fmt: on"),
145-
CommentStatement(
146-
line_no_start=60,
147-
line_no_end=61,
148-
value="\n # That^ incremented `foo` by 1",
133+
value=" # ([5,5] @ [5,5]) *\\\n",
149134
),
150-
ReturnStatement(line_no_start=61, line_no_end=62, value="\n return r"),
135+
ExprStatement(
136+
line_no_start=55,
137+
line_no_end=57,
138+
value=" -5 / 7 ** 6 + \\\n 6.0 - 6e1 & 1+2.34j\n",
139+
),
140+
AugAssignment(line_no_start=57, line_no_end=58, value=" r <<= 5\n"),
141+
CallStatement(line_no_start=58, line_no_end=59, value=" print(r)\n"),
142+
ElseStatement(line_no_start=59, line_no_end=60, value=" else:\n"),
143+
PassStatement(line_no_start=60, line_no_end=61, value=" pass\n"),
144+
CommentStatement(line_no_start=61, line_no_end=62, value=" # fmt: on\n"),
151145
CommentStatement(
152146
line_no_start=62,
153-
line_no_end=65,
154-
value="\n\n\n# from contextlib import ContextDecorator",
147+
line_no_end=63,
148+
value=" # That^ incremented `foo` by 1\n",
155149
),
150+
ReturnStatement(line_no_start=63, line_no_end=64, value=" return r\n"),
151+
UnchangingLine(line_no_start=64, line_no_end=65, value="\n"),
152+
UnchangingLine(line_no_start=65, line_no_end=66, value="\n"),
156153
CommentStatement(
157-
line_no_start=65, line_no_end=67, value="\n\n# with ContextDecorator():"
154+
line_no_start=66,
155+
line_no_end=67,
156+
value="# from contextlib import ContextDecorator\n",
158157
),
159-
CommentStatement(line_no_start=67, line_no_end=68, value="\n# pass"),
160-
FunctionDefinitionStart(
161-
line_no_start=68, line_no_end=71, value="\n\n\ndef f():", name="f"
158+
UnchangingLine(line_no_start=67, line_no_end=68, value="\n"),
159+
CommentStatement(
160+
line_no_start=68, line_no_end=69, value="# with ContextDecorator():\n"
162161
),
163-
ReturnStatement(line_no_start=71, line_no_end=72, value="\n return 1"),
164-
UnchangingLine(line_no_start=72, line_no_end=73, value="\n"),
162+
CommentStatement(line_no_start=69, line_no_end=70, value="# pass\n"),
163+
UnchangingLine(line_no_start=70, line_no_end=71, value="\n"),
164+
UnchangingLine(line_no_start=71, line_no_end=72, value="\n"),
165+
FunctionDefinitionStart(line_no_start=72, line_no_end=73, value="def f():\n", name="f"),
166+
ReturnStatement(line_no_start=73, line_no_end=74, value=" return 1\n"),
165167
) # type: tuple[CstTypes, ...]
166168

167169

0 commit comments

Comments
 (0)