astToolkit 0.3.2__tar.gz → 0.3.4__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.
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/PKG-INFO +1 -1
- asttoolkit-0.3.4/astToolkit/__init__.py +74 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_astTypes.py +7 -1
- asttoolkit-0.3.4/astToolkit/_dumpFunctionDef.py +76 -0
- asttoolkit-0.3.4/astToolkit/_joinClassmethod.py +1260 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_theSSOT.py +1 -1
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolBe.py +0 -1
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolkitAST.py +6 -56
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_types.py +1 -2
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/transformationTools.py +25 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit.egg-info/PKG-INFO +1 -1
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit.egg-info/SOURCES.txt +4 -8
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit.egg-info/top_level.txt +0 -1
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/pyproject.toml +1 -1
- asttoolkit-0.3.4/tests/test_joinClassmethod.py +119 -0
- asttoolkit-0.3.2/astToolkit/__init__.py +0 -37
- asttoolkit-0.3.2/toolFactory/Z0Z_hardcoded.py +0 -135
- asttoolkit-0.3.2/toolFactory/__init__.py +0 -31
- asttoolkit-0.3.2/toolFactory/_snippets.py +0 -16
- asttoolkit-0.3.2/toolFactory/datacenter.py +0 -251
- asttoolkit-0.3.2/toolFactory/docstrings.py +0 -106
- asttoolkit-0.3.2/toolFactory/factory3.py +0 -603
- asttoolkit-0.3.2/toolFactory/factory_annex.py +0 -66
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/LICENSE +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/README.md +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolClassIsAndAttribute.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolDOT.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolGrab.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolIfThis.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolMake.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolThen.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolkitContainers.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/_toolkitNodeVisitor.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit/py.typed +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit.egg-info/dependency_links.txt +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/astToolkit.egg-info/requires.txt +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/setup.cfg +0 -0
- /asttoolkit-0.3.2/toolFactory/py.typed → /asttoolkit-0.3.4/tests/conftest.py +0 -0
- {asttoolkit-0.3.2 → asttoolkit-0.3.4}/tests/test_basic.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astToolkit
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: A powerfully composable, type-safe toolkit for Python abstract syntax tree (AST) manipulation, analysis, transformation, and code generation with a layered architecture designed for building sophisticated code processing assembly-lines.
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License: CC-BY-NC-4.0
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AST Toolkit for Python - A comprehensive utility library for AST manipulation and transformation
|
|
3
|
+
|
|
4
|
+
The astToolkit package provides a powerful set of tools for working with Python's Abstract Syntax Tree (AST),
|
|
5
|
+
enabling sophisticated code analysis, transformation, and generation. The toolkit is designed around a
|
|
6
|
+
composable architecture with specialized modules for different aspects of AST manipulation:
|
|
7
|
+
|
|
8
|
+
Core Components:
|
|
9
|
+
- NodeTourist/NodeChanger: AST traversal and transformation engines
|
|
10
|
+
- Make: Factory methods for creating AST nodes with clean semantics
|
|
11
|
+
- IfThis/Then: Predicate-based node matching and transformation
|
|
12
|
+
- IngredientsFunction/IngredientsModule: Containers for storing code components with dependencies
|
|
13
|
+
|
|
14
|
+
Tool Categories:
|
|
15
|
+
- Antecedents: Be, ClassIsAndAttribute, IfThis
|
|
16
|
+
- Actions: Make, Then
|
|
17
|
+
- Modify antecedents and actions: DOT, Grab
|
|
18
|
+
- AST Organization: LedgerOfImports - Manage import statements
|
|
19
|
+
- Code Generation: extractFunctionDef, parseLogicalPath2astModule - Extract and parse code
|
|
20
|
+
|
|
21
|
+
The toolkit enables developers to perform complex AST operations with semantically clear code,
|
|
22
|
+
maintaining type safety and providing a declarative approach to code transformation.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from astToolkit._astTypes import * # noqa: F403
|
|
26
|
+
|
|
27
|
+
from astToolkit._types import (
|
|
28
|
+
str_nameDOTname as str_nameDOTname,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
from astToolkit._dumpFunctionDef import dump as dump
|
|
32
|
+
|
|
33
|
+
from astToolkit._toolkitNodeVisitor import (
|
|
34
|
+
NodeChanger as NodeChanger,
|
|
35
|
+
NodeTourist as NodeTourist,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from astToolkit._toolBe import Be as Be
|
|
39
|
+
from astToolkit._toolClassIsAndAttribute import ClassIsAndAttribute as ClassIsAndAttribute
|
|
40
|
+
from astToolkit._toolDOT import DOT as DOT
|
|
41
|
+
from astToolkit._toolGrab import Grab as Grab
|
|
42
|
+
from astToolkit._toolMake import Make as Make
|
|
43
|
+
from astToolkit._joinClassmethod import (
|
|
44
|
+
Add as Add,
|
|
45
|
+
BitAnd as BitAnd,
|
|
46
|
+
BitOr as BitOr,
|
|
47
|
+
BitXor as BitXor,
|
|
48
|
+
Div as Div,
|
|
49
|
+
FloorDiv as FloorDiv,
|
|
50
|
+
LShift as LShift,
|
|
51
|
+
MatMult as MatMult,
|
|
52
|
+
Mod as Mod,
|
|
53
|
+
Mult as Mult,
|
|
54
|
+
Pow as Pow,
|
|
55
|
+
RShift as RShift,
|
|
56
|
+
Sub as Sub,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
from astToolkit._toolIfThis import IfThis as IfThis
|
|
60
|
+
from astToolkit._toolThen import Then as Then
|
|
61
|
+
|
|
62
|
+
from astToolkit._toolkitContainers import (
|
|
63
|
+
IngredientsFunction as IngredientsFunction,
|
|
64
|
+
IngredientsModule as IngredientsModule,
|
|
65
|
+
LedgerOfImports as LedgerOfImports,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
from astToolkit._toolkitAST import (
|
|
69
|
+
astModuleToIngredientsFunction as astModuleToIngredientsFunction,
|
|
70
|
+
extractClassDef as extractClassDef,
|
|
71
|
+
extractFunctionDef as extractFunctionDef,
|
|
72
|
+
parseLogicalPath2astModule as parseLogicalPath2astModule,
|
|
73
|
+
parsePathFilename2astModule as parsePathFilename2astModule,
|
|
74
|
+
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""This file is generated automatically, so changes to this file will be lost."""
|
|
2
|
-
from typing import Any, TypeAlias as typing_TypeAlias, TypeVar as typing_TypeVar
|
|
2
|
+
from typing import Any, TypeAlias as typing_TypeAlias, TypedDict, TypeVar as typing_TypeVar
|
|
3
3
|
import ast
|
|
4
4
|
import sys
|
|
5
5
|
intORstr: typing_TypeAlias = Any
|
|
@@ -8,6 +8,12 @@ intORtype_params: typing_TypeAlias = Any
|
|
|
8
8
|
木 = typing_TypeVar('木', bound=ast.AST, covariant=True)
|
|
9
9
|
个 = typing_TypeVar('个', covariant=True)
|
|
10
10
|
个return = typing_TypeVar('个return', covariant=True)
|
|
11
|
+
|
|
12
|
+
class ast_attributes(TypedDict, total=False):
|
|
13
|
+
lineno: int
|
|
14
|
+
col_offset: int
|
|
15
|
+
end_lineno: int | None
|
|
16
|
+
end_col_offset: int | None
|
|
11
17
|
hasDOTannotation_expr: typing_TypeAlias = ast.AnnAssign
|
|
12
18
|
hasDOTannotation_exprOrNone: typing_TypeAlias = ast.arg
|
|
13
19
|
hasDOTannotation: typing_TypeAlias = hasDOTannotation_expr | hasDOTannotation_exprOrNone
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from _ast import *
|
|
2
|
+
|
|
3
|
+
def dump(node, annotate_fields=True, include_attributes=False, *, indent=None, show_empty=False):
|
|
4
|
+
"""
|
|
5
|
+
Return a formatted dump of the tree in node. This is mainly useful for
|
|
6
|
+
debugging purposes. If annotate_fields is true (by default),
|
|
7
|
+
the returned string will show the names and the values for fields.
|
|
8
|
+
If annotate_fields is false, the result string will be more compact by
|
|
9
|
+
omitting unambiguous field names. Attributes such as line
|
|
10
|
+
numbers and column offsets are not dumped by default. If this is wanted,
|
|
11
|
+
include_attributes can be set to true. If indent is a non-negative
|
|
12
|
+
integer or string, then the tree will be pretty-printed with that indent
|
|
13
|
+
level. None (the default) selects the single line representation.
|
|
14
|
+
If show_empty is False, then empty lists and fields that are None
|
|
15
|
+
will be omitted from the output for better readability.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def _format(node, level=0):
|
|
19
|
+
if indent is not None:
|
|
20
|
+
level += 1
|
|
21
|
+
prefix = '\n' + indent * level
|
|
22
|
+
sep = ',\n' + indent * level
|
|
23
|
+
else:
|
|
24
|
+
prefix = ''
|
|
25
|
+
sep = ', '
|
|
26
|
+
if isinstance(node, AST):
|
|
27
|
+
cls = type(node)
|
|
28
|
+
args = []
|
|
29
|
+
args_buffer = []
|
|
30
|
+
allsimple = True
|
|
31
|
+
keywords = annotate_fields
|
|
32
|
+
for name in node._fields:
|
|
33
|
+
try:
|
|
34
|
+
value = getattr(node, name)
|
|
35
|
+
except AttributeError:
|
|
36
|
+
keywords = True
|
|
37
|
+
continue
|
|
38
|
+
if value is None and getattr(cls, name, ...) is None:
|
|
39
|
+
keywords = True
|
|
40
|
+
continue
|
|
41
|
+
if not show_empty and (value is None or value == []) and (not isinstance(node, (Constant, MatchSingleton))):
|
|
42
|
+
args_buffer.append(repr(value))
|
|
43
|
+
continue
|
|
44
|
+
elif not keywords:
|
|
45
|
+
args.extend(args_buffer)
|
|
46
|
+
args_buffer = []
|
|
47
|
+
value, simple = _format(value, level)
|
|
48
|
+
allsimple = allsimple and simple
|
|
49
|
+
if keywords:
|
|
50
|
+
args.append('%s=%s' % (name, value))
|
|
51
|
+
else:
|
|
52
|
+
args.append(value)
|
|
53
|
+
if include_attributes and node._attributes:
|
|
54
|
+
for name in node._attributes:
|
|
55
|
+
try:
|
|
56
|
+
value = getattr(node, name)
|
|
57
|
+
except AttributeError:
|
|
58
|
+
continue
|
|
59
|
+
if value is None and getattr(cls, name, ...) is None:
|
|
60
|
+
continue
|
|
61
|
+
value, simple = _format(value, level)
|
|
62
|
+
allsimple = allsimple and simple
|
|
63
|
+
args.append('%s=%s' % (name, value))
|
|
64
|
+
if allsimple and len(args) <= 3:
|
|
65
|
+
return ('%s(%s)' % ('ast.' + node.__class__.__name__, ', '.join(args)), not args)
|
|
66
|
+
return ('%s(%s%s)' % ('ast.' + node.__class__.__name__, prefix, sep.join(args)), False)
|
|
67
|
+
elif isinstance(node, list):
|
|
68
|
+
if not node:
|
|
69
|
+
return ('[]', True)
|
|
70
|
+
return ('[%s%s]' % (prefix, sep.join((_format(x, level)[0] for x in node))), False)
|
|
71
|
+
return (repr(node), True)
|
|
72
|
+
if not isinstance(node, AST):
|
|
73
|
+
raise TypeError('expected AST, got %r' % node.__class__.__name__)
|
|
74
|
+
if indent is not None and (not isinstance(indent, str)):
|
|
75
|
+
indent = ' ' * indent
|
|
76
|
+
return _format(node)[0]
|