adam-community 1.0.2__py3-none-any.whl → 1.0.4__py3-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.
- adam_community/__init__.py +1 -0
- adam_community/__version__.py +1 -0
- adam_community/cli/cli.py +32 -1
- adam_community/cli/updater.py +201 -0
- {adam_community-1.0.2.dist-info → adam_community-1.0.4.dist-info}/METADATA +9 -1
- {adam_community-1.0.2.dist-info → adam_community-1.0.4.dist-info}/RECORD +9 -7
- {adam_community-1.0.2.dist-info → adam_community-1.0.4.dist-info}/WHEEL +0 -0
- {adam_community-1.0.2.dist-info → adam_community-1.0.4.dist-info}/entry_points.txt +0 -0
- {adam_community-1.0.2.dist-info → adam_community-1.0.4.dist-info}/top_level.txt +0 -0
adam_community/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.4"
|
adam_community/cli/cli.py
CHANGED
|
@@ -4,11 +4,15 @@ from pathlib import Path
|
|
|
4
4
|
from .parser import parse_directory
|
|
5
5
|
from .build import build_package
|
|
6
6
|
from .init import init
|
|
7
|
+
from .updater import check_and_notify_update, update_cli, set_update_disabled
|
|
8
|
+
from ..__version__ import __version__
|
|
7
9
|
|
|
8
10
|
@click.group()
|
|
11
|
+
@click.version_option(version=__version__, prog_name='adam-cli')
|
|
9
12
|
def cli():
|
|
10
13
|
"""Adam Community CLI 工具"""
|
|
11
|
-
|
|
14
|
+
# 检查更新(静默执行,不影响正常功能)
|
|
15
|
+
check_and_notify_update()
|
|
12
16
|
|
|
13
17
|
@cli.command()
|
|
14
18
|
@click.argument('directory', type=click.Path(exists=True, file_okay=False, dir_okay=True), default='.')
|
|
@@ -41,6 +45,33 @@ def build(directory):
|
|
|
41
45
|
click.echo(f"- {error}")
|
|
42
46
|
raise click.Abort()
|
|
43
47
|
|
|
48
|
+
@cli.command()
|
|
49
|
+
def update():
|
|
50
|
+
"""更新 CLI 到最新版本"""
|
|
51
|
+
if update_cli():
|
|
52
|
+
click.echo("\n🎉 更新完成!重新运行命令以使用新版本。")
|
|
53
|
+
else:
|
|
54
|
+
click.echo("\n❌ 更新失败,请手动更新或检查网络连接。")
|
|
55
|
+
click.echo("手动更新命令:pip install --upgrade adam-community")
|
|
56
|
+
|
|
57
|
+
@cli.command()
|
|
58
|
+
@click.option('--disable-update-check', is_flag=True, help='禁用自动更新检查')
|
|
59
|
+
@click.option('--enable-update-check', is_flag=True, help='启用自动更新检查')
|
|
60
|
+
def config(disable_update_check, enable_update_check):
|
|
61
|
+
"""配置 CLI 设置"""
|
|
62
|
+
if disable_update_check and enable_update_check:
|
|
63
|
+
click.echo("错误:不能同时启用和禁用更新检查")
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
if disable_update_check:
|
|
67
|
+
set_update_disabled(True)
|
|
68
|
+
click.echo("✅ 已禁用自动更新检查")
|
|
69
|
+
elif enable_update_check:
|
|
70
|
+
set_update_disabled(False)
|
|
71
|
+
click.echo("✅ 已启用自动更新检查")
|
|
72
|
+
else:
|
|
73
|
+
click.echo("请使用 --disable-update-check 或 --enable-update-check 选项")
|
|
74
|
+
|
|
44
75
|
# 添加 init 命令
|
|
45
76
|
cli.add_command(init)
|
|
46
77
|
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Optional, Tuple
|
|
7
|
+
import requests
|
|
8
|
+
from packaging import version
|
|
9
|
+
import click
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.panel import Panel
|
|
12
|
+
|
|
13
|
+
console = Console()
|
|
14
|
+
|
|
15
|
+
def get_cache_dir() -> Path:
|
|
16
|
+
"""获取缓存目录"""
|
|
17
|
+
cache_dir = Path.home() / ".adam_cli" / "cache"
|
|
18
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
19
|
+
return cache_dir
|
|
20
|
+
|
|
21
|
+
def get_current_version() -> str:
|
|
22
|
+
"""获取当前版本"""
|
|
23
|
+
try:
|
|
24
|
+
# 尝试从 setup.py 或 __version__ 获取版本
|
|
25
|
+
from adam_community import __version__
|
|
26
|
+
return __version__
|
|
27
|
+
except ImportError:
|
|
28
|
+
# 如果无法导入,尝试从 pip 获取
|
|
29
|
+
try:
|
|
30
|
+
result = subprocess.run(
|
|
31
|
+
[sys.executable, "-m", "pip", "show", "adam-community"],
|
|
32
|
+
capture_output=True, text=True, timeout=10
|
|
33
|
+
)
|
|
34
|
+
if result.returncode == 0:
|
|
35
|
+
for line in result.stdout.split('\n'):
|
|
36
|
+
if line.startswith('Version:'):
|
|
37
|
+
return line.split(':', 1)[1].strip()
|
|
38
|
+
except:
|
|
39
|
+
pass
|
|
40
|
+
return "unknown"
|
|
41
|
+
|
|
42
|
+
def get_latest_version_from_pypi() -> Optional[str]:
|
|
43
|
+
"""从 PyPI 获取最新版本"""
|
|
44
|
+
try:
|
|
45
|
+
response = requests.get(
|
|
46
|
+
"https://pypi.org/pypi/adam-community/json",
|
|
47
|
+
timeout=5
|
|
48
|
+
)
|
|
49
|
+
if response.status_code == 200:
|
|
50
|
+
data = response.json()
|
|
51
|
+
return data['info']['version']
|
|
52
|
+
except:
|
|
53
|
+
pass
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
def should_check_update() -> bool:
|
|
57
|
+
"""检查是否需要检查更新(基于缓存时间)"""
|
|
58
|
+
cache_file = get_cache_dir() / "last_update_check.json"
|
|
59
|
+
|
|
60
|
+
if not cache_file.exists():
|
|
61
|
+
return True
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
with open(cache_file, 'r') as f:
|
|
65
|
+
data = json.load(f)
|
|
66
|
+
|
|
67
|
+
last_check = datetime.fromisoformat(data['last_check'])
|
|
68
|
+
# 24小时检查一次
|
|
69
|
+
return datetime.now() - last_check > timedelta(hours=24)
|
|
70
|
+
except:
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
def save_check_time():
|
|
74
|
+
"""保存检查时间"""
|
|
75
|
+
cache_file = get_cache_dir() / "last_update_check.json"
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
with open(cache_file, 'w') as f:
|
|
79
|
+
json.dump({
|
|
80
|
+
'last_check': datetime.now().isoformat()
|
|
81
|
+
}, f)
|
|
82
|
+
except:
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
def is_update_disabled() -> bool:
|
|
86
|
+
"""检查是否禁用了自动更新检查"""
|
|
87
|
+
config_file = get_cache_dir() / "config.json"
|
|
88
|
+
|
|
89
|
+
if not config_file.exists():
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
with open(config_file, 'r') as f:
|
|
94
|
+
config = json.load(f)
|
|
95
|
+
return config.get('disable_update_check', False)
|
|
96
|
+
except:
|
|
97
|
+
return False
|
|
98
|
+
|
|
99
|
+
def set_update_disabled(disabled: bool):
|
|
100
|
+
"""设置是否禁用自动更新检查"""
|
|
101
|
+
config_file = get_cache_dir() / "config.json"
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
config = {}
|
|
105
|
+
if config_file.exists():
|
|
106
|
+
with open(config_file, 'r') as f:
|
|
107
|
+
config = json.load(f)
|
|
108
|
+
|
|
109
|
+
config['disable_update_check'] = disabled
|
|
110
|
+
|
|
111
|
+
with open(config_file, 'w') as f:
|
|
112
|
+
json.dump(config, f, indent=2)
|
|
113
|
+
except:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
def check_for_update() -> Tuple[bool, Optional[str], Optional[str]]:
|
|
117
|
+
"""检查更新,返回(有更新, 当前版本, 最新版本)"""
|
|
118
|
+
if is_update_disabled():
|
|
119
|
+
return False, None, None
|
|
120
|
+
|
|
121
|
+
if not should_check_update():
|
|
122
|
+
return False, None, None
|
|
123
|
+
|
|
124
|
+
current_ver = get_current_version()
|
|
125
|
+
latest_ver = get_latest_version_from_pypi()
|
|
126
|
+
|
|
127
|
+
save_check_time()
|
|
128
|
+
|
|
129
|
+
if current_ver == "unknown" or latest_ver is None:
|
|
130
|
+
return False, current_ver, latest_ver
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
has_update = version.parse(latest_ver) > version.parse(current_ver)
|
|
134
|
+
return has_update, current_ver, latest_ver
|
|
135
|
+
except:
|
|
136
|
+
return False, current_ver, latest_ver
|
|
137
|
+
|
|
138
|
+
def show_update_notification(current_ver: str, latest_ver: str):
|
|
139
|
+
"""显示更新通知"""
|
|
140
|
+
console.print()
|
|
141
|
+
console.print(Panel.fit(
|
|
142
|
+
f"[yellow]📦 发现新版本![/yellow]\n"
|
|
143
|
+
f"当前版本: [red]{current_ver}[/red]\n"
|
|
144
|
+
f"最新版本: [green]{latest_ver}[/green]\n\n"
|
|
145
|
+
f"[dim]运行以下命令更新:[/dim]\n"
|
|
146
|
+
f"[cyan]adam-cli update[/cyan]\n\n"
|
|
147
|
+
f"[dim]或运行以下命令禁用更新检查:[/dim]\n"
|
|
148
|
+
f"[cyan]adam-cli config --disable-update-check[/cyan]",
|
|
149
|
+
border_style="yellow",
|
|
150
|
+
title="[yellow]🚀 更新提醒[/yellow]"
|
|
151
|
+
))
|
|
152
|
+
console.print()
|
|
153
|
+
|
|
154
|
+
def update_cli():
|
|
155
|
+
"""更新 CLI 到最新版本"""
|
|
156
|
+
console.print("🔍 检查最新版本...")
|
|
157
|
+
|
|
158
|
+
latest_ver = get_latest_version_from_pypi()
|
|
159
|
+
if latest_ver is None:
|
|
160
|
+
console.print("[red]❌ 无法获取最新版本信息,请检查网络连接[/red]")
|
|
161
|
+
return False
|
|
162
|
+
|
|
163
|
+
current_ver = get_current_version()
|
|
164
|
+
|
|
165
|
+
if current_ver != "unknown":
|
|
166
|
+
try:
|
|
167
|
+
if version.parse(current_ver) >= version.parse(latest_ver):
|
|
168
|
+
console.print(f"[green]✅ 已是最新版本 {current_ver}[/green]")
|
|
169
|
+
return True
|
|
170
|
+
except:
|
|
171
|
+
pass
|
|
172
|
+
|
|
173
|
+
console.print(f"📦 开始更新到版本 {latest_ver}...")
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
# 使用 pip 更新
|
|
177
|
+
result = subprocess.run([
|
|
178
|
+
sys.executable, "-m", "pip", "install", "--upgrade", "adam-community"
|
|
179
|
+
], capture_output=True, text=True)
|
|
180
|
+
|
|
181
|
+
if result.returncode == 0:
|
|
182
|
+
console.print(f"[green]✅ 更新成功![/green]")
|
|
183
|
+
console.print(f"[green]当前版本: {latest_ver}[/green]")
|
|
184
|
+
return True
|
|
185
|
+
else:
|
|
186
|
+
console.print(f"[red]❌ 更新失败:[/red]")
|
|
187
|
+
console.print(f"[red]{result.stderr}[/red]")
|
|
188
|
+
return False
|
|
189
|
+
except Exception as e:
|
|
190
|
+
console.print(f"[red]❌ 更新过程中出错:{str(e)}[/red]")
|
|
191
|
+
return False
|
|
192
|
+
|
|
193
|
+
def check_and_notify_update():
|
|
194
|
+
"""检查并通知更新(在 CLI 启动时调用)"""
|
|
195
|
+
try:
|
|
196
|
+
has_update, current_ver, latest_ver = check_for_update()
|
|
197
|
+
if has_update and current_ver and latest_ver:
|
|
198
|
+
show_update_notification(current_ver, latest_ver)
|
|
199
|
+
except:
|
|
200
|
+
# 静默处理错误,不影响正常功能
|
|
201
|
+
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: adam_community
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: Adam Community Tools and Utilities
|
|
5
5
|
Home-page: https://github.com/yourusername/adam-community
|
|
6
6
|
Author: Adam Community
|
|
@@ -14,6 +14,8 @@ Requires-Dist: requests>=2.31.0
|
|
|
14
14
|
Requires-Dist: click>=8.0.0
|
|
15
15
|
Requires-Dist: docstring-parser>=0.15
|
|
16
16
|
Requires-Dist: rich>=13.0.0
|
|
17
|
+
Requires-Dist: packaging>=21.0
|
|
18
|
+
Requires-Dist: jsonschema>=4.0.0
|
|
17
19
|
Dynamic: author
|
|
18
20
|
Dynamic: author-email
|
|
19
21
|
Dynamic: classifier
|
|
@@ -58,6 +60,11 @@ adam-cli parse .
|
|
|
58
60
|
adam-cli build .
|
|
59
61
|
```
|
|
60
62
|
|
|
63
|
+
更新 CLI 到最新版本:
|
|
64
|
+
```bash
|
|
65
|
+
adam-cli update
|
|
66
|
+
```
|
|
67
|
+
|
|
61
68
|
### Python 模块导入
|
|
62
69
|
|
|
63
70
|
```python
|
|
@@ -77,6 +84,7 @@ success, errors, zip_name = build_package(Path("./"))
|
|
|
77
84
|
- **JSON Schema 验证**: 将 Python 类型转换为 JSON Schema 并验证
|
|
78
85
|
- **项目构建**: 检查配置文件、文档文件并创建 zip 包
|
|
79
86
|
- **类型检查**: 支持多种 Python 类型注解格式
|
|
87
|
+
- **自动更新**: 智能检查和更新到最新版本,支持用户配置
|
|
80
88
|
|
|
81
89
|
## 开发
|
|
82
90
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
adam_community/__init__.py,sha256=
|
|
1
|
+
adam_community/__init__.py,sha256=vAmF9VQR6D4peppH0hnrHDmZK5cFeFPh11GIsTKUXhE,429
|
|
2
|
+
adam_community/__version__.py,sha256=O-a1T6uLdX0DYXelAnzqY4NDGktopbWdpKZloec7oxY,21
|
|
2
3
|
adam_community/tool.py,sha256=CCzWosxtuZ0yk7mupmnlgMpO59jr1hl-a_brSGIqhDI,4867
|
|
3
4
|
adam_community/util.py,sha256=W4SD4x-Tg_JVAINoi2Q2j5FqbWrQxvg0TRYfE9Yh2WI,11031
|
|
4
5
|
adam_community/cli/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
6
|
adam_community/cli/build.py,sha256=qs7DGTanMrs0ZH-oqLIzbm2ArkKssDrzdS2pJnd877E,10699
|
|
6
|
-
adam_community/cli/cli.py,sha256=
|
|
7
|
+
adam_community/cli/cli.py,sha256=L_V09KMWuasgdce6zrB2yNOpCl8G7k7C_oKWvLEzS5k,2810
|
|
7
8
|
adam_community/cli/init.py,sha256=ukdIXm1V75xRDWRnQaiKRhkmGDGKp4GASQjTroRan8I,6552
|
|
8
9
|
adam_community/cli/parser.py,sha256=DeNNB6Gqs1J3Cha3BSu1DOosQNTij8pyZOmW5ls_xqY,16362
|
|
10
|
+
adam_community/cli/updater.py,sha256=zN521c-G20MKz63wm7h16quBxiEZp4vQ6AbyV-IqtXk,6304
|
|
9
11
|
adam_community/cli/templates/__init__.py,sha256=43rU9rFkpsVrWjxR-brDnT2eakgRtb4XpnunbE-ais4,34
|
|
10
|
-
adam_community-1.0.
|
|
11
|
-
adam_community-1.0.
|
|
12
|
-
adam_community-1.0.
|
|
13
|
-
adam_community-1.0.
|
|
14
|
-
adam_community-1.0.
|
|
12
|
+
adam_community-1.0.4.dist-info/METADATA,sha256=GJy-u7tsKkiPQgkeeB_jnpsUuUh-hPB8IZ6X_swJQ24,2142
|
|
13
|
+
adam_community-1.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
14
|
+
adam_community-1.0.4.dist-info/entry_points.txt,sha256=4I7yRkn7cHwPY8-fWQLeAvKjc24zUy8Z65VsZNs0Wos,56
|
|
15
|
+
adam_community-1.0.4.dist-info/top_level.txt,sha256=MS8jbePXKZChih9kGizNVX0I1MFZFGWBMCIW_r86qhU,15
|
|
16
|
+
adam_community-1.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|