expr-codegen 0.16.5__tar.gz → 0.16.6__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.
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/PKG-INFO +1 -1
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/__init__.py +1 -0
- expr_codegen-0.16.6/expr_codegen/_version.py +1 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/codes.py +42 -0
- expr_codegen-0.16.5/expr_codegen/_version.py +0 -1
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/.gitignore +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/LICENSE +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/README.md +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/dag.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/expr.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/latex/__init__.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/latex/printer.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/model.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/__init__.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/code.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/helper.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/printer.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/ta.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/pandas/template.py.j2 +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/polars/__init__.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/polars/code.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/polars/printer.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/polars/template.py.j2 +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/rust/__init__.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/rust/code.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/rust/printer.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/rust/template.rs.j2 +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/sql/__init__.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/sql/code.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/sql/printer.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/sql/template.sql.j2 +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/expr_codegen/tool.py +0 -0
- {expr_codegen-0.16.5 → expr_codegen-0.16.6}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.16.6"
|
|
@@ -10,6 +10,48 @@ from sympy import Add, Mul, Pow, Eq, Not, Xor
|
|
|
10
10
|
from expr_codegen.expr import register_symbols, list_to_exprs
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
class ParentSetter(ast.NodeVisitor):
|
|
14
|
+
"""
|
|
15
|
+
第一步:遍历 AST 树,为每个节点添加 '_parent' 属性。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def visit(self, node):
|
|
19
|
+
for child in ast.iter_child_nodes(node):
|
|
20
|
+
child._parent = node
|
|
21
|
+
return super().visit(node)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class KwargsTransformer(ast.NodeTransformer):
|
|
25
|
+
"""格式化参数"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, kwargs):
|
|
28
|
+
self.kwargs = kwargs
|
|
29
|
+
|
|
30
|
+
def visit_Name(self, node):
|
|
31
|
+
if node.id not in self.kwargs:
|
|
32
|
+
return node
|
|
33
|
+
if not isinstance(node.ctx, ast.Load):
|
|
34
|
+
return node
|
|
35
|
+
|
|
36
|
+
parent = getattr(node, '_parent', None)
|
|
37
|
+
if isinstance(parent, ast.Call) and parent.func is node:
|
|
38
|
+
return node
|
|
39
|
+
|
|
40
|
+
return ast.Constant(value=self.kwargs.get(node.id))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def code_format(code, **kwargs) -> str:
|
|
44
|
+
"""将代码块中的部分命名参数替换成常量,变相实现动态参数"""
|
|
45
|
+
tree = ast_comments.parse(inspect.getsource(code))
|
|
46
|
+
# 记录父节点
|
|
47
|
+
t1 = ParentSetter()
|
|
48
|
+
t1.visit(tree)
|
|
49
|
+
# 替换参数
|
|
50
|
+
t2 = KwargsTransformer(kwargs)
|
|
51
|
+
t2.visit(tree)
|
|
52
|
+
return ast_comments.unparse(tree)
|
|
53
|
+
|
|
54
|
+
|
|
13
55
|
class SyntaxTransformer(ast.NodeTransformer):
|
|
14
56
|
"""修改语法。注意:一定要修改语法后才能改名"""
|
|
15
57
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.16.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|