codegen-2 2.15.8__tar.gz → 2.16.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codegen_2-2.16.1/PKG-INFO +31 -0
- codegen_2-2.16.1/README.md +18 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/ast.py +0 -2
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/expr.py +83 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/pyproject.toml +1 -1
- codegen_2-2.15.8/PKG-INFO +0 -15
- codegen_2-2.15.8/README.md +0 -2
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/__init__.py +0 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/__init__.py +0 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/program.py +0 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/statement.py +0 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/types.py +0 -0
- {codegen_2-2.15.8 → codegen_2-2.16.1}/codegen/models/var.py +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: codegen-2
|
|
3
|
+
Version: 2.16.1
|
|
4
|
+
Summary: Meta-programming
|
|
5
|
+
Author: Binh Vu
|
|
6
|
+
Author-email: Binh Vu <binh@toan2.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
|
|
9
|
+
Requires-Dist: autoflake>=2.2.1 ; extra == 'dev'
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# codegen
|
|
15
|
+
|
|
16
|
+
`codegen` is a small code generation library for building Python and partial TypeScript output from a lightweight AST.
|
|
17
|
+
|
|
18
|
+
- PyPI/package name: `codegen-2`
|
|
19
|
+
- Import path: `codegen`
|
|
20
|
+
- Main public module: `codegen.models`
|
|
21
|
+
- Python requirement: `>=3.11`
|
|
22
|
+
|
|
23
|
+
Use this import pattern:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from codegen.models import Program, DeferredVar, ImportHelper, expr, stmt
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The top-level `codegen/__init__.py` is empty, so `from codegen import Program` does not work.
|
|
30
|
+
|
|
31
|
+
Full reference: [docs/codegen-reference.md](docs/codegen-reference.md)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# codegen
|
|
2
|
+
|
|
3
|
+
`codegen` is a small code generation library for building Python and partial TypeScript output from a lightweight AST.
|
|
4
|
+
|
|
5
|
+
- PyPI/package name: `codegen-2`
|
|
6
|
+
- Import path: `codegen`
|
|
7
|
+
- Main public module: `codegen.models`
|
|
8
|
+
- Python requirement: `>=3.11`
|
|
9
|
+
|
|
10
|
+
Use this import pattern:
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from codegen.models import Program, DeferredVar, ImportHelper, expr, stmt
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The top-level `codegen/__init__.py` is empty, so `from codegen import Program` does not work.
|
|
17
|
+
|
|
18
|
+
Full reference: [docs/codegen-reference.md](docs/codegen-reference.md)
|
|
@@ -11,7 +11,6 @@ from codegen.models.statement import (
|
|
|
11
11
|
Comment,
|
|
12
12
|
DefClassLikeStatement,
|
|
13
13
|
DefClassStatement,
|
|
14
|
-
DefClassVarStatement,
|
|
15
14
|
DefFuncStatement,
|
|
16
15
|
ElseStatement,
|
|
17
16
|
ExceptionStatement,
|
|
@@ -19,7 +18,6 @@ from codegen.models.statement import (
|
|
|
19
18
|
IfStatement,
|
|
20
19
|
ImportStatement,
|
|
21
20
|
LineBreak,
|
|
22
|
-
NoStatement,
|
|
23
21
|
PythonStatement,
|
|
24
22
|
ReturnStatement,
|
|
25
23
|
SingleExprStatement,
|
|
@@ -66,6 +66,9 @@ class ExprConstant(Expr):
|
|
|
66
66
|
+ "}"
|
|
67
67
|
)
|
|
68
68
|
if isinstance(val, set):
|
|
69
|
+
if len(val) == 0:
|
|
70
|
+
return "set()"
|
|
71
|
+
|
|
69
72
|
return (
|
|
70
73
|
"{"
|
|
71
74
|
+ ", ".join(sorted((ExprConstant.constant_to_python(v) for v in val)))
|
|
@@ -432,6 +435,86 @@ class PredefinedFn:
|
|
|
432
435
|
return f"{self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()})"
|
|
433
436
|
return f"{self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()})"
|
|
434
437
|
|
|
438
|
+
@dataclass(init=False)
|
|
439
|
+
class map_list_as_set(Expr):
|
|
440
|
+
collection: Expr
|
|
441
|
+
func: Expr
|
|
442
|
+
filter: Optional[Expr] = None
|
|
443
|
+
|
|
444
|
+
def __init__(
|
|
445
|
+
self,
|
|
446
|
+
collection: Expr,
|
|
447
|
+
func: Callable[[ExprIdent], Expr],
|
|
448
|
+
filter: Optional[Callable[[ExprIdent], Expr]] = None,
|
|
449
|
+
):
|
|
450
|
+
self.collection = collection
|
|
451
|
+
self.func = func(ExprIdent("_x"))
|
|
452
|
+
self.filter = filter(ExprIdent("_x")) if filter is not None else None
|
|
453
|
+
|
|
454
|
+
def to_python(self):
|
|
455
|
+
if self.filter is not None:
|
|
456
|
+
return f"{{{self.func.to_python()} for _x in {self.collection.to_python()} if {self.filter.to_python()}}}"
|
|
457
|
+
return (
|
|
458
|
+
f"{{{self.func.to_python()} for _x in {self.collection.to_python()}}}"
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
def to_typescript(self):
|
|
462
|
+
if self.filter is not None:
|
|
463
|
+
return f"new Set({self.collection.to_typescript()}.filter((_x: any) => {self.filter.to_typescript()}).map((_x: any) => {self.func.to_typescript()}))"
|
|
464
|
+
return f"new Set({self.collection.to_typescript()}.map((_x: any) => {self.func.to_typescript()}))"
|
|
465
|
+
|
|
466
|
+
@dataclass(init=False)
|
|
467
|
+
class flatten_map_list(Expr):
|
|
468
|
+
collection: Expr
|
|
469
|
+
func: Expr
|
|
470
|
+
filter: Optional[Expr] = None
|
|
471
|
+
|
|
472
|
+
def __init__(
|
|
473
|
+
self,
|
|
474
|
+
collection: Expr,
|
|
475
|
+
func: Callable[[ExprIdent], Expr],
|
|
476
|
+
filter: Optional[Callable[[ExprIdent], Expr]] = None,
|
|
477
|
+
):
|
|
478
|
+
self.collection = collection
|
|
479
|
+
self.func = func(ExprIdent("_x"))
|
|
480
|
+
self.filter = filter(ExprIdent("_x")) if filter is not None else None
|
|
481
|
+
|
|
482
|
+
def to_python(self):
|
|
483
|
+
if self.filter is not None:
|
|
484
|
+
return f"[_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()} if {self.filter.to_python()}]"
|
|
485
|
+
return f"[_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()}]"
|
|
486
|
+
|
|
487
|
+
def to_typescript(self):
|
|
488
|
+
if self.filter is not None:
|
|
489
|
+
return f"{self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}).filter((_y: any) => {self.filter.to_typescript()})"
|
|
490
|
+
return f"{self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()})"
|
|
491
|
+
|
|
492
|
+
@dataclass(init=False)
|
|
493
|
+
class flatten_map_list_as_set(Expr):
|
|
494
|
+
collection: Expr
|
|
495
|
+
func: Expr
|
|
496
|
+
filter: Optional[Expr] = None
|
|
497
|
+
|
|
498
|
+
def __init__(
|
|
499
|
+
self,
|
|
500
|
+
collection: Expr,
|
|
501
|
+
func: Callable[[ExprIdent], Expr],
|
|
502
|
+
filter: Optional[Callable[[ExprIdent], Expr]] = None,
|
|
503
|
+
):
|
|
504
|
+
self.collection = collection
|
|
505
|
+
self.func = func(ExprIdent("_x"))
|
|
506
|
+
self.filter = filter(ExprIdent("_y")) if filter is not None else None
|
|
507
|
+
|
|
508
|
+
def to_python(self):
|
|
509
|
+
if self.filter is not None:
|
|
510
|
+
return f"{{_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()} if {self.filter.to_python()}}}"
|
|
511
|
+
return f"{{_y for _x in {self.collection.to_python()} for _y in {self.func.to_python()}}}"
|
|
512
|
+
|
|
513
|
+
def to_typescript(self):
|
|
514
|
+
if self.filter is not None:
|
|
515
|
+
return f"new Set({self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}).filter((_y: any) => {self.filter.to_typescript()}))"
|
|
516
|
+
return f"new Set({self.collection.to_typescript()}.flatMap((_x: any) => {self.func.to_typescript()}))"
|
|
517
|
+
|
|
435
518
|
@dataclass
|
|
436
519
|
class range(Expr):
|
|
437
520
|
start: Expr
|
codegen_2-2.15.8/PKG-INFO
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: codegen-2
|
|
3
|
-
Version: 2.15.8
|
|
4
|
-
Summary: Meta-programming
|
|
5
|
-
Author: Binh Vu
|
|
6
|
-
Author-email: Binh Vu <binh@toan2.com>
|
|
7
|
-
License: MIT
|
|
8
|
-
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
|
|
9
|
-
Requires-Dist: autoflake>=2.2.1 ; extra == 'dev'
|
|
10
|
-
Requires-Python: >=3.11
|
|
11
|
-
Provides-Extra: dev
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
|
|
14
|
-
# codegen
|
|
15
|
-
Meta-programming
|
codegen_2-2.15.8/README.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|