threadcheck 0.0.1__tar.gz
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.
- threadcheck-0.0.1/.github/workflows/diagnose_hook.py +125 -0
- threadcheck-0.0.1/.github/workflows/diagnose_pytest.py +206 -0
- threadcheck-0.0.1/.github/workflows/release.yml +135 -0
- threadcheck-0.0.1/.github/workflows/test.yml +37 -0
- threadcheck-0.0.1/.gitignore +30 -0
- threadcheck-0.0.1/LICENSE +21 -0
- threadcheck-0.0.1/PKG-INFO +248 -0
- threadcheck-0.0.1/PLAN.md +292 -0
- threadcheck-0.0.1/README.md +225 -0
- threadcheck-0.0.1/README_CN.md +230 -0
- threadcheck-0.0.1/demo/race_example.py +21 -0
- threadcheck-0.0.1/demo/run_demo.py +44 -0
- threadcheck-0.0.1/pyproject.toml +44 -0
- threadcheck-0.0.1/release_body.md +16 -0
- threadcheck-0.0.1/src/threadcheck/__init__.py +13 -0
- threadcheck-0.0.1/src/threadcheck/__main__.py +3 -0
- threadcheck-0.0.1/src/threadcheck/_version.py +1 -0
- threadcheck-0.0.1/src/threadcheck/cli.py +89 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/__init__.py +0 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/__main__.py +38 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/clock.py +31 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/hook.py +97 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/tracker.py +191 -0
- threadcheck-0.0.1/src/threadcheck/dynamic/transform.py +192 -0
- threadcheck-0.0.1/src/threadcheck/pytest_plugin.py +60 -0
- threadcheck-0.0.1/src/threadcheck/reporting/__init__.py +0 -0
- threadcheck-0.0.1/src/threadcheck/reporting/formatter.py +33 -0
- threadcheck-0.0.1/src/threadcheck/reporting/sarif.py +100 -0
- threadcheck-0.0.1/src/threadcheck/reporting/types.py +3 -0
- threadcheck-0.0.1/src/threadcheck/static/__init__.py +0 -0
- threadcheck-0.0.1/src/threadcheck/static/analyzer.py +104 -0
- threadcheck-0.0.1/src/threadcheck/static/lock_tracker.py +42 -0
- threadcheck-0.0.1/src/threadcheck/static/models.py +48 -0
- threadcheck-0.0.1/src/threadcheck/static/visitors.py +324 -0
- threadcheck-0.0.1/tests/conftest.py +0 -0
- threadcheck-0.0.1/tests/fixtures/class_attribute_safe.py +15 -0
- threadcheck-0.0.1/tests/fixtures/class_race.py +16 -0
- threadcheck-0.0.1/tests/fixtures/class_safe.py +18 -0
- threadcheck-0.0.1/tests/fixtures/dynamic_race.py +14 -0
- threadcheck-0.0.1/tests/fixtures/dynamic_safe.py +16 -0
- threadcheck-0.0.1/tests/fixtures/no_race_simple.py +13 -0
- threadcheck-0.0.1/tests/fixtures/nonlocal_race.py +25 -0
- threadcheck-0.0.1/tests/fixtures/safe_with_lock.py +16 -0
- threadcheck-0.0.1/tests/fixtures/shared_list.py +13 -0
- threadcheck-0.0.1/tests/fixtures/simple_global.py +14 -0
- threadcheck-0.0.1/tests/fixtures/thread_subclass_race.py +16 -0
- threadcheck-0.0.1/tests/test_dynamic_detector.py +116 -0
- threadcheck-0.0.1/tests/test_pytest_plugin.py +222 -0
- threadcheck-0.0.1/tests/test_sarif.py +96 -0
- threadcheck-0.0.1/tests/test_static_analyzer.py +110 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Diagnose import hook pipeline on this Python version.
|
|
2
|
+
|
|
3
|
+
Tests:
|
|
4
|
+
1. Direct import through hook (proven to work)
|
|
5
|
+
2. Import via spec_from_file_location (mimics pytest import_path)
|
|
6
|
+
"""
|
|
7
|
+
import sys
|
|
8
|
+
import textwrap
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
REPO = Path(__file__).resolve().parent.parent.parent # repo root
|
|
12
|
+
sys.path.insert(0, str(REPO))
|
|
13
|
+
sys.path.insert(0, str(REPO / "src"))
|
|
14
|
+
|
|
15
|
+
print(f"Python: {sys.version}")
|
|
16
|
+
|
|
17
|
+
# ── prepare helpers ──────────────────────────────────────────────
|
|
18
|
+
tmp_dir = REPO / "tmp_diagnose"
|
|
19
|
+
tmp_dir.mkdir(exist_ok=True)
|
|
20
|
+
|
|
21
|
+
(new_module := tmp_dir / "diagnose_mod.py").write_text(
|
|
22
|
+
textwrap.dedent("""\
|
|
23
|
+
import threading
|
|
24
|
+
counter = 0
|
|
25
|
+
def run_racy():
|
|
26
|
+
global counter
|
|
27
|
+
def inc():
|
|
28
|
+
global counter
|
|
29
|
+
for _ in range(50):
|
|
30
|
+
counter += 1
|
|
31
|
+
threads = [threading.Thread(target=inc) for _ in range(2)]
|
|
32
|
+
for t in threads:
|
|
33
|
+
t.start()
|
|
34
|
+
for t in threads:
|
|
35
|
+
t.join()
|
|
36
|
+
"""),
|
|
37
|
+
encoding="utf-8",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
(new_test := tmp_dir / "test_diag.py").write_text(
|
|
41
|
+
textwrap.dedent("""\
|
|
42
|
+
import sys; print(f"[diag] sys.path={sys.path[:3]}", flush=True)
|
|
43
|
+
print("[diag] importing diagnose_mod", flush=True)
|
|
44
|
+
sys.path.insert(0, __file__ and str(type(__file__)))
|
|
45
|
+
import diagnose_mod
|
|
46
|
+
_h = hasattr(diagnose_mod, "_threadcheck_tracker")
|
|
47
|
+
print(f"[diag] has_tracker={_h}", flush=True)
|
|
48
|
+
def test_diag():
|
|
49
|
+
diagnose_mod.run_racy()
|
|
50
|
+
"""),
|
|
51
|
+
encoding="utf-8",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
sys.path.insert(0, str(tmp_dir))
|
|
55
|
+
|
|
56
|
+
from threadcheck.dynamic.hook import install_hook, uninstall_hook
|
|
57
|
+
from threadcheck.dynamic.tracker import ThreadCheckTracker
|
|
58
|
+
import importlib.util
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# ── Test A: direct import (like diagnose_hook did before) ────────
|
|
62
|
+
print("\n=== Test A: direct import through hook ===")
|
|
63
|
+
hook = install_hook(include_paths=[REPO])
|
|
64
|
+
try:
|
|
65
|
+
ThreadCheckTracker.start()
|
|
66
|
+
sys.path.insert(0, str(tmp_dir))
|
|
67
|
+
import diagnose_mod
|
|
68
|
+
ok = hasattr(diagnose_mod, "_threadcheck_tracker")
|
|
69
|
+
print(f" has _threadcheck_tracker: {ok}")
|
|
70
|
+
if ok:
|
|
71
|
+
diagnose_mod.run_racy()
|
|
72
|
+
races = ThreadCheckTracker.detect_races()
|
|
73
|
+
print(f" races detected: {len(races)}")
|
|
74
|
+
else:
|
|
75
|
+
# fallback: check meta_path
|
|
76
|
+
print(f" sys.meta_path[0]: {type(sys.meta_path[0]).__name__}")
|
|
77
|
+
finally:
|
|
78
|
+
ThreadCheckTracker.reset()
|
|
79
|
+
uninstall_hook(hook)
|
|
80
|
+
sys.modules.pop("diagnose_mod", None)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
# ── Test B: import via spec_from_file_location (mimics pytest) ───
|
|
84
|
+
print("\n=== Test B: import via spec_from_file_location (pytest-style) ===")
|
|
85
|
+
hook = install_hook(include_paths=[REPO])
|
|
86
|
+
try:
|
|
87
|
+
ThreadCheckTracker.start()
|
|
88
|
+
|
|
89
|
+
# pytest adds test file's parent dir to sys.path
|
|
90
|
+
sys.path.insert(0, str(tmp_dir))
|
|
91
|
+
|
|
92
|
+
# pytest imports test file via spec_from_file_location
|
|
93
|
+
spec = importlib.util.spec_from_file_location(
|
|
94
|
+
"test_diag", str(new_test),
|
|
95
|
+
)
|
|
96
|
+
mod = importlib.util.module_from_spec(spec)
|
|
97
|
+
sys.modules["test_diag"] = mod
|
|
98
|
+
spec.loader.exec_module(mod)
|
|
99
|
+
|
|
100
|
+
# now check if diagnose_mod was instrumented
|
|
101
|
+
diag_mod = sys.modules.get("diagnose_mod")
|
|
102
|
+
if diag_mod is None:
|
|
103
|
+
print(" diagnose_mod NOT in sys.modules (hook may not have been called)")
|
|
104
|
+
else:
|
|
105
|
+
ok = hasattr(diag_mod, "_threadcheck_tracker")
|
|
106
|
+
print(f" diagnose_mod has _threadcheck_tracker: {ok}")
|
|
107
|
+
if ok:
|
|
108
|
+
# run the test
|
|
109
|
+
mod.test_diag()
|
|
110
|
+
races = ThreadCheckTracker.detect_races()
|
|
111
|
+
print(f" races detected: {len(races)}")
|
|
112
|
+
for var, r1, r2 in races:
|
|
113
|
+
print(f" {var}: T{r1.thread_id} {r1.operation} vs T{r2.thread_id} {r2.operation}")
|
|
114
|
+
else:
|
|
115
|
+
print(" hook did not instrument diagnose_mod!")
|
|
116
|
+
print(f" sys.meta_path[0]: {type(sys.meta_path[0]).__name__}")
|
|
117
|
+
finally:
|
|
118
|
+
ThreadCheckTracker.reset()
|
|
119
|
+
uninstall_hook(hook)
|
|
120
|
+
for m in list(sys.modules.keys()):
|
|
121
|
+
if m.startswith("diagnose_mod") or m.startswith("test_diag"):
|
|
122
|
+
sys.modules.pop(m, None)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
print("\n=== Done ===")
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Diagnose the full pytest plugin flow.
|
|
2
|
+
- Test A: direct import (same process)
|
|
3
|
+
- Test B: subprocess pytest (like the real test)
|
|
4
|
+
"""
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import textwrap
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
REPO = Path(__file__).resolve().parent.parent.parent # repo root
|
|
11
|
+
sys.path.insert(0, str(REPO))
|
|
12
|
+
sys.path.insert(0, str(REPO / "src"))
|
|
13
|
+
|
|
14
|
+
print(f"Python: {sys.version}")
|
|
15
|
+
print(f"REPO: {REPO}")
|
|
16
|
+
|
|
17
|
+
# ── 1. Create helper module (like test_plugin_detects_race does) ──
|
|
18
|
+
tmp_dir = REPO / "tmp_test_plugin"
|
|
19
|
+
tmp_dir.mkdir(exist_ok=True)
|
|
20
|
+
|
|
21
|
+
helper = tmp_dir / "race_helpers.py"
|
|
22
|
+
helper.write_text(
|
|
23
|
+
textwrap.dedent("""\
|
|
24
|
+
import threading
|
|
25
|
+
counter = 0
|
|
26
|
+
def run_racy_increment():
|
|
27
|
+
global counter
|
|
28
|
+
threads = []
|
|
29
|
+
def inc():
|
|
30
|
+
global counter
|
|
31
|
+
for _ in range(50):
|
|
32
|
+
counter += 1
|
|
33
|
+
for _ in range(3):
|
|
34
|
+
t = threading.Thread(target=inc)
|
|
35
|
+
t.start()
|
|
36
|
+
threads.append(t)
|
|
37
|
+
for t in threads:
|
|
38
|
+
t.join()
|
|
39
|
+
"""),
|
|
40
|
+
encoding="utf-8",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
test_file = tmp_dir / "test_race.py"
|
|
44
|
+
test_file.write_text(
|
|
45
|
+
textwrap.dedent("""\
|
|
46
|
+
import sys
|
|
47
|
+
from race_helpers import run_racy_increment
|
|
48
|
+
import race_helpers as rh
|
|
49
|
+
_has = "_threadcheck_tracker" in rh.__dict__
|
|
50
|
+
print(f"[DBG] has_tracker={_has}", flush=True)
|
|
51
|
+
if _has:
|
|
52
|
+
_t = type(rh.__dict__["_threadcheck_tracker"]).__name__
|
|
53
|
+
print(f"[DBG] tracker_type={_t}", flush=True)
|
|
54
|
+
def test_race():
|
|
55
|
+
run_racy_increment()
|
|
56
|
+
"""),
|
|
57
|
+
encoding="utf-8",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# ═══════════════════════════════════════════════════════════════════
|
|
61
|
+
# Test A: direct import (same process)
|
|
62
|
+
# ═══════════════════════════════════════════════════════════════════
|
|
63
|
+
print("\n" + "=" * 60)
|
|
64
|
+
print("Test A: direct import (same process)")
|
|
65
|
+
print("=" * 60)
|
|
66
|
+
|
|
67
|
+
sys.path.insert(0, str(tmp_dir))
|
|
68
|
+
|
|
69
|
+
from threadcheck.dynamic.hook import install_hook, uninstall_hook
|
|
70
|
+
from threadcheck.dynamic.tracker import ThreadCheckTracker
|
|
71
|
+
|
|
72
|
+
rootpath = REPO
|
|
73
|
+
hook = install_hook(include_paths=[rootpath])
|
|
74
|
+
print(f"include_paths: {[str(p) for p in hook._include_paths]}")
|
|
75
|
+
|
|
76
|
+
ThreadCheckTracker.start()
|
|
77
|
+
print(f"tracker active: {ThreadCheckTracker._active}")
|
|
78
|
+
|
|
79
|
+
import importlib
|
|
80
|
+
try:
|
|
81
|
+
test_mod = importlib.import_module("test_race")
|
|
82
|
+
print(f"imported: {test_mod}")
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print(f"import failed: {e}")
|
|
85
|
+
import traceback; traceback.print_exc()
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
import race_helpers as rh
|
|
89
|
+
has_tracker = hasattr(rh, "_threadcheck_tracker")
|
|
90
|
+
print(f"race_helpers has _threadcheck_tracker: {has_tracker}")
|
|
91
|
+
if not has_tracker:
|
|
92
|
+
print(" HOOK FAILED!")
|
|
93
|
+
spec = hook.find_spec("race_helpers", None, None)
|
|
94
|
+
print(f" find_spec: {spec}")
|
|
95
|
+
print(f" meta_path[0]: {type(sys.meta_path[0]).__name__}")
|
|
96
|
+
sys.exit(1)
|
|
97
|
+
|
|
98
|
+
# Show instrumented source of the inc function
|
|
99
|
+
import ast, textwrap as _tw
|
|
100
|
+
_rh_source = Path(__file__).resolve().parent.parent.parent / "tmp_test_plugin" / "race_helpers.py"
|
|
101
|
+
_rh_text = _rh_source.read_text(encoding="utf-8")
|
|
102
|
+
from threadcheck.dynamic.transform import transform_source
|
|
103
|
+
_print_transformed = transform_source(_rh_text, str(_rh_source))
|
|
104
|
+
print("--- transformed source (first 30 lines) ---")
|
|
105
|
+
for _i, _line in enumerate(_print_transformed.splitlines()[:30]):
|
|
106
|
+
print(f" {_i+1}: {_line}")
|
|
107
|
+
print("--- end ---")
|
|
108
|
+
|
|
109
|
+
ThreadCheckTracker.reset_logs()
|
|
110
|
+
test_mod.test_race()
|
|
111
|
+
races = ThreadCheckTracker.detect_races()
|
|
112
|
+
print(f"races detected: {len(races)}")
|
|
113
|
+
for var, r1, r2 in races:
|
|
114
|
+
print(f" {var}: T{r1.thread_id} {r1.operation} vs T{r2.thread_id} {r2.operation}")
|
|
115
|
+
|
|
116
|
+
if not races:
|
|
117
|
+
print(f"access_log: {dict((k, len(v)) for k, v in ThreadCheckTracker._access_log.items())}")
|
|
118
|
+
print(f"thread_clocks: {list(ThreadCheckTracker._thread_clocks.keys())}")
|
|
119
|
+
for var, recs in ThreadCheckTracker._access_log.items():
|
|
120
|
+
all_tids = set(r.thread_id for r in recs)
|
|
121
|
+
print(f" thread_ids in '{var}': {len(all_tids)} unique ids: {all_tids}")
|
|
122
|
+
# Plain threading test (no instrumentation)
|
|
123
|
+
import threading as _th
|
|
124
|
+
_plain_results = []
|
|
125
|
+
_plain_lock = _th.Lock()
|
|
126
|
+
_started_tids = []
|
|
127
|
+
_started_nids = []
|
|
128
|
+
def _plain_worker():
|
|
129
|
+
with _plain_lock:
|
|
130
|
+
_plain_results.append(_th.get_ident())
|
|
131
|
+
_plain_threads = [_th.Thread(target=_plain_worker) for _ in range(3)]
|
|
132
|
+
_started_tids = [t.ident for t in _plain_threads]
|
|
133
|
+
for _t in _plain_threads:
|
|
134
|
+
_t.start()
|
|
135
|
+
_started_nids.append(_t.native_id)
|
|
136
|
+
for _t in _plain_threads:
|
|
137
|
+
_t.join()
|
|
138
|
+
print(f" before_start_tids: {_started_tids}", flush=True)
|
|
139
|
+
print(f" after_start_nids: {_started_nids}", flush=True)
|
|
140
|
+
print(f" after_join_results: {_plain_results}", flush=True)
|
|
141
|
+
print(f" unique_worker_tids: {set(_plain_results)}", flush=True)
|
|
142
|
+
# Run without closures (top-level import approach)
|
|
143
|
+
_simple_results2 = []
|
|
144
|
+
def _simple_worker2():
|
|
145
|
+
_simple_results2.append(1)
|
|
146
|
+
_simple_threads2 = [_th.Thread(target=_simple_worker2) for _ in range(3)]
|
|
147
|
+
for _t in _simple_threads2: _t.start()
|
|
148
|
+
for _t in _simple_threads2: _t.join()
|
|
149
|
+
print(f" closure_worker_count: {len(_simple_results2)} values={_simple_results2}", flush=True)
|
|
150
|
+
# Absolute simplest: function that takes no closures
|
|
151
|
+
_worker3_results = []
|
|
152
|
+
import builtins
|
|
153
|
+
class _Worker3State:
|
|
154
|
+
results = _worker3_results
|
|
155
|
+
def _worker3():
|
|
156
|
+
_Worker3State.results.append(_th.get_ident())
|
|
157
|
+
_threads3 = [_th.Thread(target=_worker3) for _ in range(3)]
|
|
158
|
+
for _t in _threads3: _t.start()
|
|
159
|
+
for _t in _threads3: _t.join()
|
|
160
|
+
print(f" class_attr_results: {_worker3_results}", flush=True)
|
|
161
|
+
|
|
162
|
+
ThreadCheckTracker.reset()
|
|
163
|
+
uninstall_hook(hook)
|
|
164
|
+
|
|
165
|
+
# ═══════════════════════════════════════════════════════════════════
|
|
166
|
+
# Test B: subprocess pytest (like the real test)
|
|
167
|
+
# ═══════════════════════════════════════════════════════════════════
|
|
168
|
+
print("\n" + "=" * 60)
|
|
169
|
+
print("Test B: subprocess pytest (like test_plugin_detects_race)")
|
|
170
|
+
print("=" * 60)
|
|
171
|
+
|
|
172
|
+
# Clean up modules from Test A
|
|
173
|
+
for m in list(sys.modules.keys()):
|
|
174
|
+
if m in ("test_race", "race_helpers"):
|
|
175
|
+
sys.modules.pop(m, None)
|
|
176
|
+
|
|
177
|
+
result = subprocess.run(
|
|
178
|
+
[sys.executable, "-m", "pytest", str(test_file), "-v", "-s", "--threadcheck"],
|
|
179
|
+
capture_output=True, text=True, timeout=30,
|
|
180
|
+
cwd=REPO,
|
|
181
|
+
)
|
|
182
|
+
print(f"returncode: {result.returncode}")
|
|
183
|
+
print(f"--- stdout ---")
|
|
184
|
+
sys.stdout.flush()
|
|
185
|
+
sys.stdout.write(result.stdout)
|
|
186
|
+
sys.stdout.flush()
|
|
187
|
+
if result.stderr:
|
|
188
|
+
print(f"--- stderr ---")
|
|
189
|
+
sys.stdout.flush()
|
|
190
|
+
sys.stdout.write(result.stderr)
|
|
191
|
+
sys.stdout.flush()
|
|
192
|
+
|
|
193
|
+
if result.returncode != 0:
|
|
194
|
+
if "Data races detected" in result.stdout or "Data races detected" in result.stderr:
|
|
195
|
+
print("\nSUCCESS: subprocess detected race!")
|
|
196
|
+
else:
|
|
197
|
+
print(f"\nSubprocess failed but no 'Data races detected'")
|
|
198
|
+
if "Error" in result.stdout or "error" in result.stderr:
|
|
199
|
+
print(" (possibly a pytest error)")
|
|
200
|
+
sys.exit(1)
|
|
201
|
+
else:
|
|
202
|
+
print("\nSUBPROCESS DID NOT DETECT RACE (exit 0)")
|
|
203
|
+
sys.exit(1)
|
|
204
|
+
|
|
205
|
+
# ═══════════════════════════════════════════════════════════════════
|
|
206
|
+
print("\nAll tests passed!")
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
name: Test on Python ${{ matrix.python-version }}
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
- run: pip install -e ".[test]"
|
|
26
|
+
- run: python -m pytest tests/ -v
|
|
27
|
+
|
|
28
|
+
release:
|
|
29
|
+
name: Create Release & Publish to PyPI
|
|
30
|
+
needs: test
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0
|
|
37
|
+
|
|
38
|
+
- name: Generate changelog
|
|
39
|
+
run: |
|
|
40
|
+
echo "## What's Changed" > release_body.md
|
|
41
|
+
echo "" >> release_body.md
|
|
42
|
+
|
|
43
|
+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
|
|
44
|
+
|
|
45
|
+
if [ -z "$PREV_TAG" ]; then
|
|
46
|
+
RANGE="HEAD"
|
|
47
|
+
else
|
|
48
|
+
RANGE="${PREV_TAG}..HEAD"
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
while IFS= read -r ENTRY; do
|
|
52
|
+
[ -z "$ENTRY" ] && continue
|
|
53
|
+
MSG="${ENTRY%%|||*}"
|
|
54
|
+
HASH="${ENTRY##*|||}"
|
|
55
|
+
|
|
56
|
+
TYPE="other"
|
|
57
|
+
case "$MSG" in
|
|
58
|
+
"feat"*) TYPE="feat" ;;
|
|
59
|
+
"fix"*) TYPE="fix" ;;
|
|
60
|
+
"docs"*) TYPE="docs" ;;
|
|
61
|
+
"style"*) TYPE="style" ;;
|
|
62
|
+
"refactor"*) TYPE="refactor" ;;
|
|
63
|
+
"perf"*) TYPE="perf" ;;
|
|
64
|
+
"test"*) TYPE="test" ;;
|
|
65
|
+
"ci"*) TYPE="ci" ;;
|
|
66
|
+
"chore"*) TYPE="chore" ;;
|
|
67
|
+
"revert"*) TYPE="revert" ;;
|
|
68
|
+
esac
|
|
69
|
+
|
|
70
|
+
echo "- ${MSG} (\`${HASH}\`)" >> "/tmp/changelog_${TYPE}.txt"
|
|
71
|
+
done <<< "$(git log ${RANGE} --format='%s|||%h')"
|
|
72
|
+
|
|
73
|
+
declare -A LABEL
|
|
74
|
+
LABEL[feat]="Features"
|
|
75
|
+
LABEL[fix]="Bug Fixes"
|
|
76
|
+
LABEL[docs]="Documentation"
|
|
77
|
+
LABEL[style]="Style"
|
|
78
|
+
LABEL[refactor]="Refactor"
|
|
79
|
+
LABEL[perf]="Performance"
|
|
80
|
+
LABEL[test]="Tests"
|
|
81
|
+
LABEL[ci]="CI/CD"
|
|
82
|
+
LABEL[chore]="Chores"
|
|
83
|
+
LABEL[revert]="Reverts"
|
|
84
|
+
LABEL[other]="Other"
|
|
85
|
+
|
|
86
|
+
for T in feat fix docs refactor perf test ci style chore revert other; do
|
|
87
|
+
F="/tmp/changelog_${T}.txt"
|
|
88
|
+
if [ -f "$F" ]; then
|
|
89
|
+
printf "\n### %s\n\n" "${LABEL[$T]}" >> release_body.md
|
|
90
|
+
cat "$F" >> release_body.md
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
|
|
94
|
+
- name: Get repository size
|
|
95
|
+
id: repo_size
|
|
96
|
+
run: |
|
|
97
|
+
SIZE=$(curl -s \
|
|
98
|
+
-H "Authorization: Bearer ${{ github.token }}" \
|
|
99
|
+
-H "Accept: application/vnd.github+json" \
|
|
100
|
+
"https://api.github.com/repos/${{ github.repository }}" \
|
|
101
|
+
| jq '.size')
|
|
102
|
+
echo "size=$SIZE" >> "$GITHUB_OUTPUT"
|
|
103
|
+
|
|
104
|
+
- name: Build time
|
|
105
|
+
id: build_time
|
|
106
|
+
run: |
|
|
107
|
+
echo "time=$(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> "$GITHUB_OUTPUT"
|
|
108
|
+
|
|
109
|
+
- name: Append metadata
|
|
110
|
+
run: |
|
|
111
|
+
cat >> release_body.md << EOF
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
**Build Time:** ${{ steps.build_time.outputs.time }}
|
|
115
|
+
**Repository Size:** ${{ steps.repo_size.outputs.size }} KB
|
|
116
|
+
EOF
|
|
117
|
+
|
|
118
|
+
- name: Set up Python
|
|
119
|
+
uses: actions/setup-python@v5
|
|
120
|
+
with:
|
|
121
|
+
python-version: "3.12"
|
|
122
|
+
|
|
123
|
+
- name: Build package
|
|
124
|
+
run: |
|
|
125
|
+
pip install build
|
|
126
|
+
python -m build
|
|
127
|
+
|
|
128
|
+
- name: Create GitHub Release
|
|
129
|
+
uses: softprops/action-gh-release@v2
|
|
130
|
+
with:
|
|
131
|
+
body_path: release_body.md
|
|
132
|
+
files: dist/*
|
|
133
|
+
|
|
134
|
+
- name: Publish to PyPI
|
|
135
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test on Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install -e ".[test]"
|
|
29
|
+
|
|
30
|
+
- name: Diagnose import hook
|
|
31
|
+
run: python .github/workflows/diagnose_hook.py
|
|
32
|
+
|
|
33
|
+
- name: Diagnose pytest plugin
|
|
34
|
+
run: python .github/workflows/diagnose_pytest.py
|
|
35
|
+
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: python -m pytest tests/ -v --tb=short
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
|
|
8
|
+
# Virtual environments
|
|
9
|
+
.venv/
|
|
10
|
+
venv/
|
|
11
|
+
env/
|
|
12
|
+
|
|
13
|
+
# IDE
|
|
14
|
+
.vscode/
|
|
15
|
+
.idea/
|
|
16
|
+
|
|
17
|
+
# OS
|
|
18
|
+
Thumbs.db
|
|
19
|
+
.DS_Store
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
htmlcov/
|
|
25
|
+
tmp_test_plugin/
|
|
26
|
+
tmp_diagnose/
|
|
27
|
+
.github/tmp_diagnose/
|
|
28
|
+
|
|
29
|
+
# Lock files
|
|
30
|
+
uv.lock
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chidc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|