python-minifier 2.11.2__py2-none-any.whl
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.
- python_minifier/__init__.py +269 -0
- python_minifier/__init__.pyi +37 -0
- python_minifier/__main__.py +332 -0
- python_minifier/ast_compare.py +104 -0
- python_minifier/ast_compat.py +40 -0
- python_minifier/ast_printer.py +130 -0
- python_minifier/expression_printer.py +753 -0
- python_minifier/f_string.py +446 -0
- python_minifier/ministring.py +179 -0
- python_minifier/module_printer.py +862 -0
- python_minifier/py.typed +0 -0
- python_minifier/rename/__init__.py +6 -0
- python_minifier/rename/bind_names.py +192 -0
- python_minifier/rename/binding.py +495 -0
- python_minifier/rename/mapper.py +175 -0
- python_minifier/rename/name_generator.py +51 -0
- python_minifier/rename/rename_literals.py +249 -0
- python_minifier/rename/renamer.py +230 -0
- python_minifier/rename/resolve_names.py +106 -0
- python_minifier/rename/util.py +203 -0
- python_minifier/token_printer.py +299 -0
- python_minifier/transforms/__init__.py +0 -0
- python_minifier/transforms/combine_imports.py +76 -0
- python_minifier/transforms/constant_folding.py +114 -0
- python_minifier/transforms/remove_annotations.py +130 -0
- python_minifier/transforms/remove_annotations_options.py +35 -0
- python_minifier/transforms/remove_annotations_options.pyi +17 -0
- python_minifier/transforms/remove_asserts.py +26 -0
- python_minifier/transforms/remove_debug.py +53 -0
- python_minifier/transforms/remove_exception_brackets.py +124 -0
- python_minifier/transforms/remove_explicit_return_none.py +38 -0
- python_minifier/transforms/remove_literal_statements.py +61 -0
- python_minifier/transforms/remove_object_base.py +24 -0
- python_minifier/transforms/remove_pass.py +26 -0
- python_minifier/transforms/remove_posargs.py +13 -0
- python_minifier/transforms/suite_transformer.py +196 -0
- python_minifier/util.py +48 -0
- python_minifier-2.11.2.dist-info/LICENSE +21 -0
- python_minifier-2.11.2.dist-info/METADATA +177 -0
- python_minifier-2.11.2.dist-info/RECORD +44 -0
- python_minifier-2.11.2.dist-info/WHEEL +5 -0
- python_minifier-2.11.2.dist-info/entry_points.txt +3 -0
- python_minifier-2.11.2.dist-info/top_level.txt +1 -0
- python_minifier-2.11.2.dist-info/zip-safe +1 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import python_minifier.ast_compat as ast
|
|
2
|
+
|
|
3
|
+
from python_minifier.rename.mapper import add_parent
|
|
4
|
+
from python_minifier.util import is_ast_node
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NodeVisitor(object):
|
|
8
|
+
def visit(self, node):
|
|
9
|
+
"""Visit a node."""
|
|
10
|
+
method = 'visit_' + node.__class__.__name__
|
|
11
|
+
visitor = getattr(self, method, self.generic_visit)
|
|
12
|
+
return visitor(node)
|
|
13
|
+
|
|
14
|
+
def generic_visit(self, node):
|
|
15
|
+
"""Called if no explicit visitor function exists for a node."""
|
|
16
|
+
for field, value in ast.iter_fields(node):
|
|
17
|
+
if isinstance(value, list):
|
|
18
|
+
for item in value:
|
|
19
|
+
if isinstance(item, ast.AST):
|
|
20
|
+
self.visit(item)
|
|
21
|
+
elif isinstance(value, ast.AST):
|
|
22
|
+
self.visit(value)
|
|
23
|
+
|
|
24
|
+
def visit_Constant(self, node):
|
|
25
|
+
if node.value in [None, True, False]:
|
|
26
|
+
method = 'visit_NameConstant'
|
|
27
|
+
elif isinstance(node.value, (int, float, complex)):
|
|
28
|
+
method = 'visit_Num'
|
|
29
|
+
elif isinstance(node.value, str):
|
|
30
|
+
method = 'visit_Str'
|
|
31
|
+
elif isinstance(node.value, bytes):
|
|
32
|
+
method = 'visit_Bytes'
|
|
33
|
+
elif node.value == Ellipsis:
|
|
34
|
+
method = 'visit_Ellipsis'
|
|
35
|
+
else:
|
|
36
|
+
raise RuntimeError('Unknown Constant value %r' % type(node.value))
|
|
37
|
+
|
|
38
|
+
visitor = getattr(self, method, self.generic_visit)
|
|
39
|
+
return visitor(node)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class SuiteTransformer(NodeVisitor):
|
|
43
|
+
"""
|
|
44
|
+
Transform suites of instructions
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __call__(self, node):
|
|
48
|
+
return self.visit(node)
|
|
49
|
+
|
|
50
|
+
def visit_ClassDef(self, node):
|
|
51
|
+
node.bases = [self.visit(b) for b in node.bases]
|
|
52
|
+
|
|
53
|
+
if hasattr(node, 'type_params') and node.type_params is not None:
|
|
54
|
+
node.type_params = [self.visit(t) for t in node.type_params]
|
|
55
|
+
|
|
56
|
+
node.body = self.suite(node.body, parent=node)
|
|
57
|
+
node.decorator_list = [self.visit(d) for d in node.decorator_list]
|
|
58
|
+
|
|
59
|
+
if hasattr(node, 'starargs') and node.starargs is not None:
|
|
60
|
+
node.starargs = self.visit(node.starargs)
|
|
61
|
+
|
|
62
|
+
if hasattr(node, 'kwargs') and node.kwargs is not None:
|
|
63
|
+
node.kwargs = self.visit(node.kwargs)
|
|
64
|
+
|
|
65
|
+
if hasattr(node, 'keywords'):
|
|
66
|
+
node.keywords = [self.visit(kw) for kw in node.keywords]
|
|
67
|
+
|
|
68
|
+
return node
|
|
69
|
+
|
|
70
|
+
def visit_FunctionDef(self, node):
|
|
71
|
+
node.args = self.visit(node.args)
|
|
72
|
+
node.body = self.suite(node.body, parent=node)
|
|
73
|
+
node.decorator_list = [self.visit(d) for d in node.decorator_list]
|
|
74
|
+
|
|
75
|
+
if hasattr(node, 'returns') and node.returns is not None:
|
|
76
|
+
node.returns = self.visit(node.returns)
|
|
77
|
+
|
|
78
|
+
return node
|
|
79
|
+
|
|
80
|
+
def visit_AsyncFunctionDef(self, node):
|
|
81
|
+
return self.visit_FunctionDef(node)
|
|
82
|
+
|
|
83
|
+
def visit_For(self, node):
|
|
84
|
+
node.target = self.visit(node.target)
|
|
85
|
+
node.iter = self.visit(node.iter)
|
|
86
|
+
|
|
87
|
+
node.body = self.suite(node.body, parent=node)
|
|
88
|
+
|
|
89
|
+
if node.orelse:
|
|
90
|
+
node.orelse = self.suite(node.orelse, parent=node)
|
|
91
|
+
|
|
92
|
+
return node
|
|
93
|
+
|
|
94
|
+
def visit_AsyncFor(self, node):
|
|
95
|
+
return self.visit_For(node)
|
|
96
|
+
|
|
97
|
+
def visit_If(self, node):
|
|
98
|
+
node.test = self.visit(node.test)
|
|
99
|
+
|
|
100
|
+
node.body = self.suite(node.body, parent=node)
|
|
101
|
+
|
|
102
|
+
if node.orelse:
|
|
103
|
+
node.orelse = self.suite(node.orelse, parent=node)
|
|
104
|
+
|
|
105
|
+
return node
|
|
106
|
+
|
|
107
|
+
def visit_Try(self, node):
|
|
108
|
+
node.body = self.suite(node.body, parent=node)
|
|
109
|
+
|
|
110
|
+
node.handlers = [self.visit(h) for h in node.handlers]
|
|
111
|
+
|
|
112
|
+
if node.orelse:
|
|
113
|
+
node.orelse = self.suite(node.orelse, parent=node)
|
|
114
|
+
|
|
115
|
+
if node.finalbody:
|
|
116
|
+
node.finalbody = self.suite(node.finalbody, parent=node)
|
|
117
|
+
|
|
118
|
+
return node
|
|
119
|
+
|
|
120
|
+
def visit_While(self, node):
|
|
121
|
+
node.test = self.visit(node.test)
|
|
122
|
+
|
|
123
|
+
node.body = self.suite(node.body, parent=node)
|
|
124
|
+
|
|
125
|
+
if node.orelse:
|
|
126
|
+
node.orelse = self.suite(node.orelse, parent=node)
|
|
127
|
+
|
|
128
|
+
return node
|
|
129
|
+
|
|
130
|
+
def visit_With(self, node):
|
|
131
|
+
|
|
132
|
+
if hasattr(node, 'items'):
|
|
133
|
+
node.items = [self.visit(i) for i in node.items]
|
|
134
|
+
else:
|
|
135
|
+
if node.context_expr:
|
|
136
|
+
node.context_expr = self.visit(node.context_expr)
|
|
137
|
+
if node.optional_vars:
|
|
138
|
+
node.optional_vars = self.visit(node.optional_vars)
|
|
139
|
+
|
|
140
|
+
node.body = self.suite(node.body, parent=node)
|
|
141
|
+
return node
|
|
142
|
+
|
|
143
|
+
def visit_AsyncWith(self, node):
|
|
144
|
+
return self.visit_With(node)
|
|
145
|
+
|
|
146
|
+
def visit_Module(self, node):
|
|
147
|
+
node.body = self.suite(node.body, parent=node)
|
|
148
|
+
return node
|
|
149
|
+
|
|
150
|
+
def suite(self, node_list, parent):
|
|
151
|
+
return [self.visit(node) for node in node_list]
|
|
152
|
+
|
|
153
|
+
def generic_visit(self, node):
|
|
154
|
+
for field, old_value in ast.iter_fields(node):
|
|
155
|
+
if isinstance(old_value, list):
|
|
156
|
+
new_values = []
|
|
157
|
+
for value in old_value:
|
|
158
|
+
if isinstance(value, ast.AST):
|
|
159
|
+
value = self.visit(value)
|
|
160
|
+
if value is None:
|
|
161
|
+
continue
|
|
162
|
+
elif not isinstance(value, ast.AST):
|
|
163
|
+
new_values.extend(value)
|
|
164
|
+
continue
|
|
165
|
+
new_values.append(value)
|
|
166
|
+
old_value[:] = new_values
|
|
167
|
+
elif isinstance(old_value, ast.AST):
|
|
168
|
+
new_node = self.visit(old_value)
|
|
169
|
+
if new_node is None:
|
|
170
|
+
delattr(node, field)
|
|
171
|
+
else:
|
|
172
|
+
setattr(node, field, new_node)
|
|
173
|
+
return node
|
|
174
|
+
|
|
175
|
+
def add_child(self, child, parent, namespace=None):
|
|
176
|
+
def nearest_function_namespace(node):
|
|
177
|
+
"""
|
|
178
|
+
Return the namespace node for the nearest function scope.
|
|
179
|
+
|
|
180
|
+
This could be itself.
|
|
181
|
+
|
|
182
|
+
:param node: The node to get the function namespace of
|
|
183
|
+
:type node: ast.Node
|
|
184
|
+
:rtype: ast.Node
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
if is_ast_node(node, (ast.FunctionDef, ast.Module, 'AsyncFunctionDef')):
|
|
189
|
+
return node
|
|
190
|
+
return nearest_function_namespace(node.parent)
|
|
191
|
+
|
|
192
|
+
if namespace is None:
|
|
193
|
+
namespace = nearest_function_namespace(parent)
|
|
194
|
+
|
|
195
|
+
add_parent(child, parent=parent, namespace=namespace)
|
|
196
|
+
return child
|
python_minifier/util.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import python_minifier.ast_compat as ast
|
|
2
|
+
|
|
3
|
+
def is_ast_node(node, types):
|
|
4
|
+
"""
|
|
5
|
+
Is a node one of the specified node types
|
|
6
|
+
|
|
7
|
+
A node type may be an actual ast class, or a string naming one.
|
|
8
|
+
types is a single node type or an iterable of many.
|
|
9
|
+
|
|
10
|
+
If a node_type specified a specific Constant type (Str, Bytes, Num etc),
|
|
11
|
+
returns true for Constant nodes of the correct type.
|
|
12
|
+
|
|
13
|
+
:type node: ast.AST
|
|
14
|
+
:param types:
|
|
15
|
+
:rtype: bool
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
if not isinstance(types, tuple):
|
|
20
|
+
types = (types,)
|
|
21
|
+
|
|
22
|
+
actual_types = []
|
|
23
|
+
for node_type in types:
|
|
24
|
+
if isinstance(node_type, str):
|
|
25
|
+
node_type = getattr(ast, node_type, None)
|
|
26
|
+
if node_type is not None:
|
|
27
|
+
actual_types.append(node_type)
|
|
28
|
+
else:
|
|
29
|
+
actual_types.append(node_type)
|
|
30
|
+
|
|
31
|
+
if isinstance(node, tuple(actual_types)):
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
if hasattr(ast, 'Constant') and isinstance(node, ast.Constant):
|
|
35
|
+
if type(node.value) in [type(None), type(True), type(False)]:
|
|
36
|
+
return ast.NameConstant in actual_types
|
|
37
|
+
elif isinstance(node.value, (int, float, complex)):
|
|
38
|
+
return ast.Num in actual_types
|
|
39
|
+
elif isinstance(node.value, str):
|
|
40
|
+
return ast.Str in actual_types
|
|
41
|
+
elif isinstance(node.value, bytes):
|
|
42
|
+
return ast.Bytes in actual_types
|
|
43
|
+
elif node.value == Ellipsis:
|
|
44
|
+
return ast.Ellipsis in actual_types
|
|
45
|
+
else:
|
|
46
|
+
raise RuntimeError('Unknown Constant value %r' % type(node.value))
|
|
47
|
+
|
|
48
|
+
return False
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Daniel Flook
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: python-minifier
|
|
3
|
+
Version: 2.11.2
|
|
4
|
+
Summary: Transform Python source code into it's most compact representation
|
|
5
|
+
Home-page: https://github.com/dflook/python-minifier
|
|
6
|
+
Author: Daniel Flook
|
|
7
|
+
Author-email: daniel@flook.org
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://dflook.github.io/python-minifier/
|
|
10
|
+
Project-URL: Issues, https://github.com/dflook/python-minifier/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/dflook/python-minifier/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: minify minifier
|
|
13
|
+
Platform: UNKNOWN
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 2
|
|
30
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
31
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
32
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: Topic :: Software Development
|
|
35
|
+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <3.14
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# Python Minifier
|
|
39
|
+
|
|
40
|
+
Transforms Python source code into its most compact representation.
|
|
41
|
+
|
|
42
|
+
[Try it out!](https://python-minifier.com)
|
|
43
|
+
|
|
44
|
+
python-minifier currently supports Python 2.7 and Python 3.3 to 3.13. Previous releases supported Python 2.6.
|
|
45
|
+
|
|
46
|
+
* [PyPI](https://pypi.org/project/python-minifier/)
|
|
47
|
+
* [Documentation](https://dflook.github.io/python-minifier/)
|
|
48
|
+
* [Issues](https://github.com/dflook/python-minifier/issues)
|
|
49
|
+
|
|
50
|
+
As an example, the following python source:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
def handler(event, context):
|
|
54
|
+
l.info(event)
|
|
55
|
+
try:
|
|
56
|
+
i_token = hashlib.new('md5', (event['RequestId'] + event['StackId']).encode()).hexdigest()
|
|
57
|
+
props = event['ResourceProperties']
|
|
58
|
+
|
|
59
|
+
if event['RequestType'] == 'Create':
|
|
60
|
+
event['PhysicalResourceId'] = 'None'
|
|
61
|
+
event['PhysicalResourceId'] = create_cert(props, i_token)
|
|
62
|
+
add_tags(event['PhysicalResourceId'], props)
|
|
63
|
+
validate(event['PhysicalResourceId'], props)
|
|
64
|
+
|
|
65
|
+
if wait_for_issuance(event['PhysicalResourceId'], context):
|
|
66
|
+
event['Status'] = 'SUCCESS'
|
|
67
|
+
return send(event)
|
|
68
|
+
else:
|
|
69
|
+
return reinvoke(event, context)
|
|
70
|
+
|
|
71
|
+
elif event['RequestType'] == 'Delete':
|
|
72
|
+
if event['PhysicalResourceId'] != 'None':
|
|
73
|
+
acm.delete_certificate(CertificateArn=event['PhysicalResourceId'])
|
|
74
|
+
event['Status'] = 'SUCCESS'
|
|
75
|
+
return send(event)
|
|
76
|
+
|
|
77
|
+
elif event['RequestType'] == 'Update':
|
|
78
|
+
|
|
79
|
+
if replace_cert(event):
|
|
80
|
+
event['PhysicalResourceId'] = create_cert(props, i_token)
|
|
81
|
+
add_tags(event['PhysicalResourceId'], props)
|
|
82
|
+
validate(event['PhysicalResourceId'], props)
|
|
83
|
+
|
|
84
|
+
if not wait_for_issuance(event['PhysicalResourceId'], context):
|
|
85
|
+
return reinvoke(event, context)
|
|
86
|
+
else:
|
|
87
|
+
if 'Tags' in event['OldResourceProperties']:
|
|
88
|
+
acm.remove_tags_from_certificate(CertificateArn=event['PhysicalResourceId'],
|
|
89
|
+
Tags=event['OldResourceProperties']['Tags'])
|
|
90
|
+
|
|
91
|
+
add_tags(event['PhysicalResourceId'], props)
|
|
92
|
+
|
|
93
|
+
event['Status'] = 'SUCCESS'
|
|
94
|
+
return send(event)
|
|
95
|
+
else:
|
|
96
|
+
raise RuntimeError('Unknown RequestType')
|
|
97
|
+
|
|
98
|
+
except Exception as ex:
|
|
99
|
+
l.exception('')
|
|
100
|
+
event['Status'] = 'FAILED'
|
|
101
|
+
event['Reason'] = str(ex)
|
|
102
|
+
return send(event)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Becomes:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
def handler(event,context):
|
|
109
|
+
L='OldResourceProperties';K='Tags';J='None';H='SUCCESS';G='RequestType';E='Status';D=context;B='PhysicalResourceId';A=event;l.info(A)
|
|
110
|
+
try:
|
|
111
|
+
F=hashlib.new('md5',(A['RequestId']+A['StackId']).encode()).hexdigest();C=A['ResourceProperties']
|
|
112
|
+
if A[G]=='Create':
|
|
113
|
+
A[B]=J;A[B]=create_cert(C,F);add_tags(A[B],C);validate(A[B],C)
|
|
114
|
+
if wait_for_issuance(A[B],D):A[E]=H;return send(A)
|
|
115
|
+
else:return reinvoke(A,D)
|
|
116
|
+
elif A[G]=='Delete':
|
|
117
|
+
if A[B]!=J:acm.delete_certificate(CertificateArn=A[B])
|
|
118
|
+
A[E]=H;return send(A)
|
|
119
|
+
elif A[G]=='Update':
|
|
120
|
+
if replace_cert(A):
|
|
121
|
+
A[B]=create_cert(C,F);add_tags(A[B],C);validate(A[B],C)
|
|
122
|
+
if not wait_for_issuance(A[B],D):return reinvoke(A,D)
|
|
123
|
+
else:
|
|
124
|
+
if K in A[L]:acm.remove_tags_from_certificate(CertificateArn=A[B],Tags=A[L][K])
|
|
125
|
+
add_tags(A[B],C)
|
|
126
|
+
A[E]=H;return send(A)
|
|
127
|
+
else:raise RuntimeError('Unknown RequestType')
|
|
128
|
+
except Exception as I:l.exception('');A[E]='FAILED';A['Reason']=str(I);return send(A)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Why?
|
|
132
|
+
|
|
133
|
+
AWS Cloudformation templates may have AWS lambda function source code embedded in them, but only if the function is less
|
|
134
|
+
than 4KiB. I wrote this package so I could write python normally and still embed the module in a template.
|
|
135
|
+
|
|
136
|
+
## Installation
|
|
137
|
+
|
|
138
|
+
To install python-minifier use pip:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
$ pip install python-minifier
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Note that python-minifier depends on the python interpreter for parsing source code,
|
|
145
|
+
and outputs source code compatible with the version of the interpreter it is run with.
|
|
146
|
+
|
|
147
|
+
This means that if you minify code written for Python 3.11 using python-minifier running with Python 3.12,
|
|
148
|
+
the minified code may only run with Python 3.12.
|
|
149
|
+
|
|
150
|
+
python-minifier runs with and can minify code written for Python 2.7 and Python 3.3 to 3.13.
|
|
151
|
+
|
|
152
|
+
## Usage
|
|
153
|
+
|
|
154
|
+
To minify a source file, and write the minified module to stdout:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
$ pyminify hello.py
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
There is also an API. The same example would look like:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import python_minifier
|
|
164
|
+
|
|
165
|
+
with open('hello.py') as f:
|
|
166
|
+
print(python_minifier.minify(f.read()))
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Documentation is available at [dflook.github.io/python-minifier/](https://dflook.github.io/python-minifier/)
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
Available under the MIT License. Full text is in the [LICENSE](LICENSE) file.
|
|
174
|
+
|
|
175
|
+
Copyright (c) 2024 Daniel Flook
|
|
176
|
+
|
|
177
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
python_minifier/__init__.py,sha256=mr0_t3hEk5R7K2fcidew9nys0PTBrEGKaPaizDEgWqk,9456
|
|
2
|
+
python_minifier/__init__.pyi,sha256=_B0ywdLZ_iES6Ubq3ajuHbBS6Lr9J_InxJWbPo38iuQ,1214
|
|
3
|
+
python_minifier/__main__.py,sha256=q2BU9CC5G328DFdfHmxg8auAwZTEc6pbM869p6583I4,11746
|
|
4
|
+
python_minifier/ast_compare.py,sha256=ZxPTh7JwiuMo81e7jpOAnHsRAq7BXj3jCAeBu4K5kyI,3164
|
|
5
|
+
python_minifier/ast_compat.py,sha256=ZOcHXNiIh9NFjFbLMndiewuT664ZtB_w0_AtlUV710Q,1620
|
|
6
|
+
python_minifier/ast_printer.py,sha256=Nsh-8FM6-tsuLMfQBr9s32idQGnk8WZomJkJT_zLuAE,3222
|
|
7
|
+
python_minifier/expression_printer.py,sha256=7r0Z0WDgYAaLwHg0STMNp70zSt4aVa45MJUGmTxxkqY,22423
|
|
8
|
+
python_minifier/f_string.py,sha256=30cSPIzqQ7_oUX4UPWJWuXjWfPWWni9RWI85Qt_HisY,14036
|
|
9
|
+
python_minifier/ministring.py,sha256=1J_nVWakRpW98yT706xe57mP0Rf45N1ivjAk7-AnOTA,4378
|
|
10
|
+
python_minifier/module_printer.py,sha256=IXkvwC-EtPxNmzArGACqJhYF0sVX-rpHOxwSsoqFbYU,25342
|
|
11
|
+
python_minifier/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
python_minifier/token_printer.py,sha256=PKstW8JBpmk_C7S3t-SCx3nO-HStE1Ac3RxYl4XX_2g,9337
|
|
13
|
+
python_minifier/util.py,sha256=hmMW4z8rTyO90b5cASxOVZyNGx_ohFWI5Pr4vAeodpo,1535
|
|
14
|
+
python_minifier/rename/__init__.py,sha256=i-Su9VHxOwWGPMmURH1GUaFdtDZNYkKlbYdTUevgRi0,375
|
|
15
|
+
python_minifier/rename/bind_names.py,sha256=TaR8VIjmKVRJvnMBjxbc52uTFVgS6OE9vm67i-mavJM,6941
|
|
16
|
+
python_minifier/rename/binding.py,sha256=yOP3RFXzP7E0mVqdARNuWuKGmeqQyh42L8WhSXI51EE,15347
|
|
17
|
+
python_minifier/rename/mapper.py,sha256=FU-rGFvd6N8vlTixWsEeNrQbL4ku9bldFJUL_O01EkU,6598
|
|
18
|
+
python_minifier/rename/name_generator.py,sha256=70Klx2DteYRpBT8dr6jYDB31ARfinS42e08kKlWAzLg,1269
|
|
19
|
+
python_minifier/rename/rename_literals.py,sha256=n_XHME6mhT9pR_RTiRjWo3YWvVuQoPNBERyCOgNrpBQ,7156
|
|
20
|
+
python_minifier/rename/renamer.py,sha256=RitT7xFr8G1V3wQtxTvxgr1EXbQM6puUeK39CSUYtMo,6706
|
|
21
|
+
python_minifier/rename/resolve_names.py,sha256=J3Yv32uc2KPfsTa-p9hUNNCEbQDDS-b0na6EUqVeGAo,4356
|
|
22
|
+
python_minifier/rename/util.py,sha256=UchrXPibRr338POF-64zWRfl5OoxwUrE4uOnQstni2s,5451
|
|
23
|
+
python_minifier/transforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
python_minifier/transforms/combine_imports.py,sha256=rXbX8ygOMgDti1B_zwU5trEIRoDrGjUpQcC8VvQMioI,2298
|
|
25
|
+
python_minifier/transforms/constant_folding.py,sha256=LWH2z210i9ZTFY8rgjEayifB7DPYkb6XSdHEQATurF4,4435
|
|
26
|
+
python_minifier/transforms/remove_annotations.py,sha256=uBjka4wt22hPJQ66xpCj5B5HaFL3gZ6gr6OsGgq9yo4,4704
|
|
27
|
+
python_minifier/transforms/remove_annotations_options.py,sha256=K-E9-TQlCyGRO-YKDfri0kyLevYxQweZhyViwiRAM7Y,1867
|
|
28
|
+
python_minifier/transforms/remove_annotations_options.pyi,sha256=BUz465OPI88YKMpDLyLfPwiJ50sL0nBJtUf6Vot23Sc,575
|
|
29
|
+
python_minifier/transforms/remove_asserts.py,sha256=jatGfsPeSzPuEHhTg9c6XaJRInM_t74zRmSEB1FoYYE,784
|
|
30
|
+
python_minifier/transforms/remove_debug.py,sha256=2LoWJVZchhXx2O5rf1nou-_IlWkqYOu3_V5t2Wllly0,1856
|
|
31
|
+
python_minifier/transforms/remove_exception_brackets.py,sha256=_-fQnjiiZCCkljC-GoG4XH9YzvRwQNfFy1KbA6_UG04,4110
|
|
32
|
+
python_minifier/transforms/remove_explicit_return_none.py,sha256=1k4dzPneDPg9UJBKrj-b9YKDkyXlFVd9TzyuAjjzjSg,1287
|
|
33
|
+
python_minifier/transforms/remove_literal_statements.py,sha256=dlYONJ-m5oj1zZITHsLY7O6QZ52rl1k2hHWbkqdxJNM,1619
|
|
34
|
+
python_minifier/transforms/remove_object_base.py,sha256=MvI1XwwB9zcwdClhyTeoD6Won4VmzNdZZ0kcB4yBgt8,702
|
|
35
|
+
python_minifier/transforms/remove_pass.py,sha256=A2c4psmYxQ6cYnk6u2KISZW6XhpDEaY-1zFx9Gy6RqI,781
|
|
36
|
+
python_minifier/transforms/remove_posargs.py,sha256=ecLdKGr0kKx6uf7OXiB_SgF57xWRiDq6ixn5OBSVi7Y,330
|
|
37
|
+
python_minifier/transforms/suite_transformer.py,sha256=zzQKf8QIVCHJ0IGF8i0yBi7kbyazaDQxrnu6eB4v6bg,6246
|
|
38
|
+
python_minifier-2.11.2.dist-info/LICENSE,sha256=FzsyDHb8pAZupSGFjIOuHcHMlFf6N-aIxq9gOYGbNyE,1069
|
|
39
|
+
python_minifier-2.11.2.dist-info/METADATA,sha256=OmFILwGLprKDfar9hQ6pN66fBekDGxIU7fUluDCXLZs,6453
|
|
40
|
+
python_minifier-2.11.2.dist-info/WHEEL,sha256=1VPi6hfNQaRRNuEdK_3dv9o8COtLGnHWJghhj4CQ28k,92
|
|
41
|
+
python_minifier-2.11.2.dist-info/entry_points.txt,sha256=aS7ZUWQeeys8lAbrmmEa2__Bg-anH1tUMyi9cKdTbO4,60
|
|
42
|
+
python_minifier-2.11.2.dist-info/top_level.txt,sha256=4SRDfWKi_KMq7LDrjlzUFoDCs6INYPtxc1Pun4z8LsU,16
|
|
43
|
+
python_minifier-2.11.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
44
|
+
python_minifier-2.11.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
python_minifier
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|