-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.py
More file actions
122 lines (91 loc) · 3.58 KB
/
Copy pathscripts.py
File metadata and controls
122 lines (91 loc) · 3.58 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
"""
MCPサーバーのエントリーポイントとユーティリティコマンド
"""
import subprocess
# 品質チェック対象ディレクトリの定数
QUALITY_CHECK_DIRS = ["src"]
def lint():
"""
ruffでコードの静的解析を実行する
"""
cmd = ["ruff", "check"] + QUALITY_CHECK_DIRS
subprocess.run(cmd)
def format():
"""
ruffでコードフォーマットを実行する
"""
cmd = ["ruff", "format"] + QUALITY_CHECK_DIRS
subprocess.run(cmd)
def fix():
"""
ruffで自動修正とフォーマットを一括実行する
"""
print("🔧 コードの自動修正とフォーマットを実行中...")
# 自動修正(安全な修正 + 危険な修正も含む)
fix_cmd = ["ruff", "check", "--fix", "--unsafe-fixes"] + QUALITY_CHECK_DIRS
fix_result = subprocess.run(fix_cmd)
# フォーマット
format_cmd = ["ruff", "format"] + QUALITY_CHECK_DIRS
format_result = subprocess.run(format_cmd)
if fix_result.returncode == 0 and format_result.returncode == 0:
print("✅ 自動修正とフォーマットが完了しました")
else:
print("❌ 自動修正またはフォーマットでエラーが発生しました")
exit(fix_result.returncode or format_result.returncode)
def type_check():
"""
メイン型チェックを実行する (ty - 高速)
"""
cmd = ["ty", "check"] + QUALITY_CHECK_DIRS
subprocess.run(cmd)
def test():
"""
pytestでテストを実行する
"""
print("🧪 テストを実行中...")
cmd = ["pytest", "-v"]
result = subprocess.run(cmd)
if result.returncode == 0:
print("✅ すべてのテストが成功しました!")
else:
print("❌ テストが失敗しました")
exit(result.returncode)
def check():
"""
型チェック、Lint、テストを同時に実行する(修正はしない)
"""
print("🔍 型チェックを実行中...")
type_result = subprocess.run(["ty", "check"] + QUALITY_CHECK_DIRS, capture_output=True)
print("📝 Lintを実行中...")
lint_result = subprocess.run(["ruff", "check"] + QUALITY_CHECK_DIRS, capture_output=True)
print("🧪 テストを実行中...")
test_result = subprocess.run(["pytest", "-v", "--tb=short"], capture_output=True)
# 結果をまとめて表示
print("\n" + "=" * 50)
print("📊 実行結果サマリー")
print("=" * 50)
type_status = "✅ PASS" if type_result.returncode == 0 else "❌ FAIL"
lint_status = "✅ PASS" if lint_result.returncode == 0 else "❌ FAIL"
test_status = "✅ PASS" if test_result.returncode == 0 else "❌ FAIL"
print(f"型チェック: {type_status}")
print(f"Lint: {lint_status}")
print(f"テスト: {test_status}")
# エラーがある場合は詳細を表示
if type_result.returncode != 0:
print("\n🔍 型チェックエラー:")
print(type_result.stdout.decode())
print(type_result.stderr.decode())
if lint_result.returncode != 0:
print("\n📝 Lintエラー:")
print(lint_result.stdout.decode())
print(lint_result.stderr.decode())
if test_result.returncode != 0:
print("\n🧪 テストエラー:")
print(test_result.stdout.decode())
print(test_result.stderr.decode())
# いずれかが失敗した場合は非ゼロで終了
if any(result.returncode != 0 for result in [type_result, lint_result, test_result]):
exit(1)
else:
print("\n🎉 すべてのチェックが成功しました!")
exit(0)