-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.py
More file actions
35 lines (31 loc) · 1.43 KB
/
Copy pathcli.py
File metadata and controls
35 lines (31 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import glob
from pathlib import Path
from pymini.pymini import minify
from argparse import ArgumentParser
def main():
parser = ArgumentParser()
parser.add_argument('path', help='Path to the file or directory to minify')
parser.add_argument('--keep-module-names', action='store_true', help='Keep module names as they are. Useful for compressing libraries')
parser.add_argument('--keep-global-variables', action='store_true', help='Keep global variables as they are. Useful for compressing libraries')
parser.add_argument('--single-file', action='store_true', help='Concatenate all outputs into a single file')
parser.add_argument('-o', '--output', help='Path to the output directory', default='./')
args = parser.parse_args()
sources, modules = [], []
for path in glob.iglob(args.path):
if not path.endswith('.py') or '.ugli.' in path:
continue
with open(path) as f:
sources.append(f.read())
modules.append(Path(path).stem)
cleaned, modules = minify(
sources, modules, keep_module_names=args.keep_module_names,
keep_global_variables=args.keep_global_variables,
output_single_file=args.single_file
)
output = Path(args.output)
output.mkdir(parents=True, exist_ok=True)
for source, module in zip(cleaned, modules):
with open(output / f'{module}.py', 'w') as f:
f.write(source)
if __name__ == '__main__':
main()