aispeech-ds-cli 0.1.0__py3-none-win_amd64.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.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: aispeech-ds-cli
3
+ Version: 0.1.0
4
+ Summary: Dataset external client CLI
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Operating System :: Microsoft :: Windows
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: packaging>=23
@@ -0,0 +1,8 @@
1
+ ds_cli_bin/__init__.py,sha256=KfrBbyZ4r2fRExiaGVbZttfXwDgHZplxZJyhQZKK_Vs,9286
2
+ ds_cli_bin/release_config.py,sha256=Fb9IvCCG5bNENbTi4MkRKSmzeNm5NjeQknYLcYpdsg4,99
3
+ ds_cli_bin/bin/ds-cli.exe,sha256=D0EAWbmtA5swEwBlELjOACwMTlohXLwYVaKPMoPOb-0,10779040
4
+ aispeech_ds_cli-0.1.0.dist-info/METADATA,sha256=67NlDXMW7uEe1KcFVflxP-wTNu__D9WtwceaGBQCkbE,344
5
+ aispeech_ds_cli-0.1.0.dist-info/WHEEL,sha256=hVx9elvUDfBjRmbl8JwIcXXikst35RZTZK9nspfI_28,98
6
+ aispeech_ds_cli-0.1.0.dist-info/entry_points.txt,sha256=OOhUKuncoBdhvN1AfVO6SPkmse792Vg7NsIKZPnGThY,43
7
+ aispeech_ds_cli-0.1.0.dist-info/top_level.txt,sha256=-7n-fnvxB_XT3_c82PDe2nLak3vBb9rULEnp2m_4yPQ,11
8
+ aispeech_ds_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ds-cli = ds_cli_bin:main
@@ -0,0 +1 @@
1
+ ds_cli_bin
ds_cli_bin/__init__.py ADDED
@@ -0,0 +1,312 @@
1
+ import json
2
+ import os
3
+ import shlex
4
+ import subprocess
5
+ import sys
6
+ import time
7
+ from importlib.metadata import version
8
+ from importlib.resources import files
9
+ from pathlib import Path
10
+ from urllib.request import urlopen
11
+
12
+
13
+ PACKAGE_NAME = "aispeech-ds-cli"
14
+ DEFAULT_CHECK_INTERVAL_SECONDS = 0
15
+ try:
16
+ from .release_config import DEFAULT_PIP_INDEX_ARGS, DEFAULT_PYPI_JSON_URL
17
+ except Exception:
18
+ DEFAULT_PYPI_JSON_URL = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
19
+ DEFAULT_PIP_INDEX_ARGS = []
20
+
21
+
22
+ def _cache_path():
23
+ cache_name = os.getenv("DS_CLI_UPDATE_CACHE", "update-check.json")
24
+ return Path.home() / ".ds-cli" / cache_name
25
+
26
+
27
+ def _pypi_json_url():
28
+ return os.getenv("DS_CLI_UPDATE_JSON_URL", DEFAULT_PYPI_JSON_URL)
29
+
30
+
31
+ def _pip_index_args():
32
+ override = os.getenv("DS_CLI_PIP_INDEX_ARGS")
33
+ if override:
34
+ return override.split()
35
+ return list(DEFAULT_PIP_INDEX_ARGS)
36
+
37
+
38
+ def _check_interval_seconds():
39
+ try:
40
+ return max(0, int(os.getenv("DS_CLI_UPDATE_CACHE_SECONDS", DEFAULT_CHECK_INTERVAL_SECONDS)))
41
+ except ValueError:
42
+ return DEFAULT_CHECK_INTERVAL_SECONDS
43
+
44
+
45
+ def _load_cached_latest():
46
+ path = _cache_path()
47
+ if not path.exists():
48
+ return None
49
+
50
+ try:
51
+ data = json.loads(path.read_text(encoding="utf-8"))
52
+ checked_at = data.get("checked_at", 0)
53
+ if time.time() - checked_at > _check_interval_seconds():
54
+ return None
55
+ return data.get("latest")
56
+ except Exception:
57
+ return None
58
+
59
+
60
+ def _save_cached_latest(latest):
61
+ path = _cache_path()
62
+ path.parent.mkdir(parents=True, exist_ok=True)
63
+ path.write_text(
64
+ json.dumps({"checked_at": time.time(), "latest": latest}),
65
+ encoding="utf-8",
66
+ )
67
+
68
+
69
+ def _fetch_latest_version(version_cls):
70
+ with urlopen(_pypi_json_url(), timeout=2) as response:
71
+ data = json.loads(response.read().decode("utf-8"))
72
+
73
+ versions = []
74
+ for raw_version, files_info in data.get("releases", {}).items():
75
+ parsed = version_cls(raw_version)
76
+ if parsed.is_prerelease:
77
+ continue
78
+ if files_info and all(item.get("yanked", False) for item in files_info):
79
+ continue
80
+ versions.append(parsed)
81
+
82
+ if not versions:
83
+ return None
84
+
85
+ return str(max(versions))
86
+
87
+
88
+ def _upgrade_command():
89
+ base = [_python_executable(), "-m", "pip", "install", "-U"]
90
+ base.extend(_pip_index_args())
91
+ base.append(PACKAGE_NAME)
92
+ return base
93
+
94
+
95
+ def _python_executable():
96
+ executable = Path(sys.executable)
97
+ if os.name == "nt" and executable.name.lower() == "ds-cli.exe":
98
+ candidate = Path(sys.prefix) / "Scripts" / "python.exe"
99
+ if candidate.exists():
100
+ return str(candidate)
101
+ return sys.executable
102
+
103
+
104
+ def _format_command(args):
105
+ if os.name == "nt":
106
+ return subprocess.list2cmdline(args)
107
+ return " ".join(shlex.quote(arg) for arg in args)
108
+
109
+
110
+ def _run_upgrade_after_exit(command):
111
+ updater_path = Path.home() / ".ds-cli" / f"self-update-{os.getpid()}.py"
112
+ updater_path.parent.mkdir(parents=True, exist_ok=True)
113
+ updater_path.write_text(
114
+ """
115
+ import ctypes
116
+ import json
117
+ import os
118
+ import subprocess
119
+ import sys
120
+ import time
121
+
122
+
123
+ def wait_for_parent(pid, timeout_seconds=60):
124
+ if os.name == "nt":
125
+ handle = ctypes.windll.kernel32.OpenProcess(0x00100000, False, pid)
126
+ if handle:
127
+ try:
128
+ ctypes.windll.kernel32.WaitForSingleObject(handle, int(timeout_seconds * 1000))
129
+ finally:
130
+ ctypes.windll.kernel32.CloseHandle(handle)
131
+ return
132
+
133
+ deadline = time.time() + timeout_seconds
134
+ while time.time() < deadline:
135
+ try:
136
+ os.kill(pid, 0)
137
+ except OSError:
138
+ return
139
+ time.sleep(0.2)
140
+
141
+
142
+ def format_command(command):
143
+ if os.name == "nt":
144
+ return subprocess.list2cmdline(command)
145
+ return " ".join(command)
146
+
147
+
148
+ def restore_prompt():
149
+ if os.name != "nt" or os.getenv("DS_CLI_RESTORE_PROMPT", "1") == "0":
150
+ return
151
+
152
+ try:
153
+ from ctypes import wintypes
154
+
155
+ STD_INPUT_HANDLE = -10
156
+ KEY_EVENT = 0x0001
157
+ VK_RETURN = 0x0D
158
+
159
+ class KEY_EVENT_RECORD(ctypes.Structure):
160
+ _fields_ = [
161
+ ("bKeyDown", wintypes.BOOL),
162
+ ("wRepeatCount", wintypes.WORD),
163
+ ("wVirtualKeyCode", wintypes.WORD),
164
+ ("wVirtualScanCode", wintypes.WORD),
165
+ ("uChar", wintypes.WCHAR),
166
+ ("dwControlKeyState", wintypes.DWORD),
167
+ ]
168
+
169
+ class INPUT_RECORD(ctypes.Structure):
170
+ _fields_ = [
171
+ ("EventType", wintypes.WORD),
172
+ ("KeyEvent", KEY_EVENT_RECORD),
173
+ ]
174
+
175
+ records = (INPUT_RECORD * 2)()
176
+ records[0].EventType = KEY_EVENT
177
+ records[0].KeyEvent = KEY_EVENT_RECORD(True, 1, VK_RETURN, 0, "\\r", 0)
178
+ records[1].EventType = KEY_EVENT
179
+ records[1].KeyEvent = KEY_EVENT_RECORD(False, 1, VK_RETURN, 0, "\\r", 0)
180
+
181
+ written = wintypes.DWORD()
182
+ handle = ctypes.windll.kernel32.GetStdHandle(STD_INPUT_HANDLE)
183
+ ctypes.windll.kernel32.WriteConsoleInputW(handle, records, 2, ctypes.byref(written))
184
+ except Exception:
185
+ pass
186
+
187
+
188
+ def main():
189
+ parent_pid = int(sys.argv[1])
190
+ command = json.loads(sys.argv[2])
191
+ wait_for_parent(parent_pid)
192
+ time.sleep(0.5)
193
+ print("[ds-cli] Running update command:")
194
+ print(" " + format_command(command))
195
+ rc = subprocess.call(command)
196
+ if rc == 0:
197
+ print("[ds-cli] Update completed. Please run your command again.")
198
+ else:
199
+ print("[ds-cli] Update failed. Please run the update command manually.", file=sys.stderr)
200
+ sys.stdout.flush()
201
+ sys.stderr.flush()
202
+ restore_prompt()
203
+ try:
204
+ os.remove(__file__)
205
+ except OSError:
206
+ pass
207
+ return rc
208
+
209
+
210
+ if __name__ == "__main__":
211
+ raise SystemExit(main())
212
+ """.lstrip(),
213
+ encoding="utf-8",
214
+ )
215
+
216
+ subprocess.Popen(
217
+ [_python_executable(), str(updater_path), str(os.getpid()), json.dumps(command)],
218
+ close_fds=False,
219
+ )
220
+ print("[ds-cli] 已启动自动升级进程,当前命令将退出。")
221
+ print("[ds-cli] Auto-update has started. The current command will exit.")
222
+ return 2
223
+
224
+
225
+ def _can_update_in_current_process():
226
+ return os.name != "nt"
227
+
228
+
229
+ def _run_upgrade():
230
+ command = _upgrade_command()
231
+ print("[ds-cli] 正在升级,请稍候...")
232
+ print("[ds-cli] Updating, please wait...")
233
+ if not _can_update_in_current_process():
234
+ return _run_upgrade_after_exit(command)
235
+
236
+ result = subprocess.run(command)
237
+ if result.returncode == 0:
238
+ print("[ds-cli] 升级完成,请重新执行命令。")
239
+ print("[ds-cli] Update completed. Please run your command again.")
240
+ else:
241
+ print(
242
+ f"[ds-cli] 升级失败,请手动执行:\n"
243
+ f" {_format_command(command)}\n"
244
+ f"[ds-cli] Update failed. Please run manually:\n"
245
+ f" {_format_command(command)}",
246
+ file=sys.stderr,
247
+ )
248
+ return result.returncode or 2
249
+
250
+
251
+ def _confirm_upgrade():
252
+ if not sys.stdin.isatty():
253
+ return False
254
+ try:
255
+ answer = input("[ds-cli] 是否现在自动升级?输入 y 继续,其他输入退出 / Update now? Enter y to continue: ")
256
+ except (EOFError, KeyboardInterrupt):
257
+ return False
258
+ return answer.strip().lower() == "y"
259
+
260
+
261
+ def _ensure_latest_version():
262
+ try:
263
+ from packaging.version import Version
264
+
265
+ current = Version(version(PACKAGE_NAME))
266
+
267
+ latest = _load_cached_latest()
268
+ if latest is None:
269
+ latest = _fetch_latest_version(Version)
270
+ if latest:
271
+ _save_cached_latest(latest)
272
+
273
+ if latest and Version(latest) > current:
274
+ command = _upgrade_command()
275
+ print(
276
+ f"[ds-cli] 当前工具版本过低,请升级。\n"
277
+ f"[ds-cli] 当前版本:{current},最新版本:{latest}。\n"
278
+ f"[ds-cli] The current tool version is too old. Please upgrade. "
279
+ f"Current version: {current}; latest version: {latest}.\n"
280
+ f"[ds-cli] 升级命令 / Upgrade command:\n"
281
+ f" {_format_command(command)}",
282
+ file=sys.stderr,
283
+ flush=True,
284
+ )
285
+ if os.getenv("DS_CLI_AUTO_UPDATE") == "1" or _confirm_upgrade():
286
+ return _run_upgrade()
287
+ return 2
288
+ except Exception as exc:
289
+ command = _upgrade_command()
290
+ print(
291
+ f"[ds-cli] 无法校验最新版本,命令不能继续执行。\n"
292
+ f"[ds-cli] Failed to verify latest version, so the command cannot continue.\n"
293
+ f"[ds-cli] 原因 / Reason: {exc}\n"
294
+ f"[ds-cli] 可先尝试升级 / Try updating first:\n"
295
+ f" {_format_command(command)}",
296
+ file=sys.stderr,
297
+ flush=True,
298
+ )
299
+ return 3
300
+
301
+ return 0
302
+
303
+
304
+ def main():
305
+ update_status = _ensure_latest_version()
306
+ if update_status != 0:
307
+ return update_status
308
+
309
+ exe_name = "ds-cli.exe" if sys.platform.startswith("win") else "ds-cli"
310
+ exe = files(__package__).joinpath("bin", exe_name)
311
+ result = subprocess.run([str(exe), *sys.argv[1:]])
312
+ return result.returncode
Binary file
@@ -0,0 +1,2 @@
1
+ DEFAULT_PYPI_JSON_URL = "https://pypi.org/pypi/aispeech-ds-cli/json"
2
+ DEFAULT_PIP_INDEX_ARGS = []