mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 19:14:16 +08:00
- Add example scripts for all API categories (connection, market info, kline, minute, transaction, finance, block, fund flow) - Fix GetIndexBarsCmd: index bar records have 4 extra bytes (advance/ decline counts) that were not consumed, causing pos drift and corrupted dates/volumes for all records after the first - Fix price_limits.py example (SecurityQuote has no name attr) - Fix finance_info.py display (scientific notation -> formatted numbers) - Add PostToolUse ruff hook (scripts/ruff_hook.py) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""PostToolUse hook: 对 Edit/Write 修改的 .py 文件自动运行 ruff check + format。
|
|
|
|
stdin 接收 JSON: {"tool_name": "Edit"|"Write", "tool_input": {"file_path": "..."}}
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
try:
|
|
data = json.load(sys.stdin)
|
|
except (json.JSONDecodeError, EOFError):
|
|
return
|
|
|
|
file_path = data.get("tool_input", {}).get("file_path", "")
|
|
if not file_path.endswith(".py"):
|
|
return
|
|
|
|
# ruff check --fix(自动修复 lint 问题)
|
|
r = subprocess.run(
|
|
["ruff", "check", "--fix", file_path],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=15,
|
|
)
|
|
if r.returncode != 0 and r.stdout.strip():
|
|
print(f"[ruff check] {file_path}:\n{r.stdout.strip()}")
|
|
|
|
# ruff format
|
|
r = subprocess.run(
|
|
["ruff", "format", file_path],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=15,
|
|
)
|
|
if r.returncode != 0 and r.stdout.strip():
|
|
print(f"[ruff format] {file_path}:\n{r.stdout.strip()}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|