-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_package.py
More file actions
247 lines (214 loc) · 7.95 KB
/
batch_package.py
File metadata and controls
247 lines (214 loc) · 7.95 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env python3
"""批量打包所有 CLI 工具为标准 Python 包结构"""
import os
import shutil
TOOLS = [
{
'name': 'sysmon',
'src_file': '/root/sysmon/sysmon.py',
'desc': 'Terminal system monitor — real-time CPU, memory, disk, network, and process TUI dashboard',
'entry': 'sysmon:main',
'pkg_name': 'sysmon',
'keywords': ['monitoring', 'system', 'tui', 'dashboard', 'cli'],
'classifiers': [
'Environment :: Console (Text Based)',
'Topic :: System :: Monitoring',
],
},
{
'name': 'nb',
'src_file': '/root/nb/nb.py',
'desc': 'Command-line notebook — lightweight note management right in your terminal',
'entry': 'nb:main',
'pkg_name': 'nb',
'keywords': ['notes', 'notebook', 'cli', 'terminal', 'productivity'],
'classifiers': [
'Environment :: Console',
'Topic :: Office/Business :: News/Diary',
],
},
{
'name': 'project-doctor',
'src_file': '/root/project-doctor/project-doctor.py',
'desc': 'Project health checker — scan your project directory for infrastructure completeness and get actionable suggestions',
'entry': 'project_doctor:main',
'pkg_name': 'project_doctor',
'keywords': ['project', 'health-check', 'code-quality', 'cli'],
'classifiers': [
'Environment :: Console',
'Topic :: Software Development :: Quality Assurance',
],
},
{
'name': 'ren',
'src_file': '/root/ren/ren.py',
'desc': 'Bulk file renamer — safe, previewable, undo-friendly batch file renaming from the terminal',
'entry': 'ren:main',
'pkg_name': 'ren',
'keywords': ['rename', 'files', 'batch', 'cli', 'utilities'],
'classifiers': [
'Environment :: Console',
'Topic :: System :: Filesystems',
],
},
{
'name': 'chart-cli',
'src_file': '/root/chart-cli/chart-cli.py',
'desc': 'Terminal chart generator — draw bar charts, line charts, pie charts, and histograms with Unicode',
'entry': 'chart_cli:main',
'pkg_name': 'chart_cli',
'keywords': ['charts', 'visualization', 'terminal', 'cli', 'unicode'],
'classifiers': [
'Environment :: Console',
'Topic :: Office/Business :: Graphics',
],
},
{
'name': 'web-summary',
'src_file': '/root/web-summary/web-summary.py',
'desc': 'Web page summarizer — extract title, text, keywords, and links from any URL. Zero external dependencies.',
'entry': 'web_summary:main',
'pkg_name': 'web_summary',
'keywords': ['web', 'summary', 'extraction', 'cli', 'scraper'],
'classifiers': [
'Environment :: Console',
'Topic :: Internet :: WWW/HTTP',
],
},
{
'name': 'smellfinder',
'src_file': '/root/smellfinder/smellfinder.py',
'desc': 'Python code smell detector — static analysis for code quality issues, zero external dependencies',
'entry': 'smellfinder:main',
'pkg_name': 'smellfinder',
'keywords': ['code-quality', 'linting', 'static-analysis', 'python', 'cli'],
'classifiers': [
'Environment :: Console',
'Topic :: Software Development :: Quality Assurance',
],
},
]
BASE_DIR = '/root/evolver-packages'
PACKAGE_BASE = BASE_DIR
LICENSE_TEXT = """MIT License
Copyright (c) 2026 EVOLVER
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
PYPROJECT_TEMPLATE = """[build-system]
requires = ["setuptools>=64.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "{name}"
version = "1.0.0"
description = "{desc}"
readme = "README.md"
license = {{text = "MIT"}}
requires-python = ">=3.8"
keywords = {keywords}
authors = [
{{name = "EVOLVER"}},
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
{extra_classifiers}
]
[project.urls]
Homepage = "https://github.com/evolver/{name}"
Repository = "https://github.com/evolver/{name}"
[project.scripts]
{entry_name} = "{entry_point}"
[tool.setuptools.packages.find]
where = ["src"]
"""
def make_safe_pkg(name):
"""Convert tool name to valid Python package name"""
return name.replace('-', '_')
def make_classifiers_string(classifiers):
items = ', '.join(f'"{c}"' for c in classifiers)
return items if items else ''
def process_tool(tool):
name = tool['name']
pkg = make_safe_pkg(tool['pkg_name'])
entry_name = name # CLI command name with hyphens
entry_point = f'{pkg}:main'
print(f"\n{'='*50}")
print(f"Packaging: {name} (-> {pkg})")
print(f"{'='*50}")
# Create dirs
pkg_dir = os.path.join(PACKAGE_BASE, name)
src_dir = os.path.join(pkg_dir, 'src', pkg)
os.makedirs(src_dir, exist_ok=True)
# 1. Write pyproject.toml
extra_cls = make_classifiers_string(tool.get('classifiers', []))
pyproject = PYPROJECT_TEMPLATE.format(
name=name,
desc=tool['desc'],
entry_name=entry_name,
entry_point=entry_point,
keywords=tool.get('keywords', ['cli']),
extra_classifiers=extra_cls,
)
with open(os.path.join(pkg_dir, 'pyproject.toml'), 'w') as f:
f.write(pyproject)
print(f" ✓ pyproject.toml")
# 2. Write LICENSE
with open(os.path.join(pkg_dir, 'LICENSE'), 'w') as f:
f.write(LICENSE_TEXT)
print(f" ✓ LICENSE")
# 3. Copy README from evolver-products
readme_src = os.path.join('/root/evolver-products/tools', name, 'README.md')
if os.path.exists(readme_src):
shutil.copy2(readme_src, os.path.join(pkg_dir, 'README.md'))
print(f" ✓ README.md")
else:
print(f" ⚠ README.md not found at {readme_src}")
# 4. Copy source code into __init__.py
src_file = tool['src_file']
if os.path.exists(src_file):
shutil.copy2(src_file, os.path.join(src_dir, '__init__.py'))
print(f" ✓ {pkg}/__init__.py")
else:
print(f" ✗ SOURCE NOT FOUND: {src_file}")
return False
# 5. Write __main__.py
main_content = f'"""CLI entry point for `python -m {pkg}`"""\nfrom {pkg} import main\nmain()\n'
with open(os.path.join(src_dir, '__main__.py'), 'w') as f:
f.write(main_content)
print(f" ✓ {pkg}/__main__.py")
return True
def main():
print("=" * 50)
print("BULK PACKAGING: 7 CLI Tools")
print("=" * 50)
results = []
for tool in TOOLS:
ok = process_tool(tool)
results.append((tool['name'], ok))
print(f"\n{'='*50}")
print("SUMMARY")
print(f"{'='*50}")
for name, ok in results:
status = "✓" if ok else "✗"
print(f" {status} {name}")
print(f"\nLocation: {PACKAGE_BASE}/")
if __name__ == '__main__':
main()