Skip to content

Commit 403f385

Browse files
committed
Add documentation, plugins, and test suite
Initial commit introducing MkDocs documentation, plugin implementations, test suite, CLI, and engine modules. Includes developer and user guides, API reference, test reference, example plugins, and configuration files for CI and documentation deployment. Removes obsolete LLM output file and updates core modules and tests to support new features.
1 parent ed72b4b commit 403f385

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+6567
-2393
lines changed

.github/workflows/gh-pages.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy MkDocs to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: "3.10"
17+
- name: Install deps
18+
run: pip install mkdocs mkdocs-material
19+
- name: Build site
20+
run: mkdocs build --site-dir site
21+
- name: Deploy to GitHub Pages
22+
uses: peaceiris/actions-gh-pages@v3
23+
with:
24+
github_token: ${{ secrets.GITHUB_TOKEN }}
25+
publish_dir: site

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 PatternLab Team
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.

debug_bmr.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from patternlab.plugin_api import BytesView
2+
from patternlab.plugins.binary_matrix_rank import BinaryMatrixRankTest
3+
4+
def inspect_rows(m=8, num_matrices=1):
5+
bits_per_matrix = m * m
6+
total_bytes = (bits_per_matrix * num_matrices) // 8
7+
pattern = (b'\xAA\x55') * (total_bytes // 2)
8+
bv = BytesView(pattern)
9+
bits = bv.bit_view()
10+
# Build rows for first matrix
11+
mat_bits = bits[0:bits_per_matrix]
12+
rows = []
13+
for r in range(m):
14+
row_bits = mat_bits[r*m:(r+1)*m]
15+
val = 0
16+
for bit in row_bits:
17+
val = (val << 1) | (1 if bit else 0)
18+
rows.append((row_bits, val))
19+
return rows, bv, pattern
20+
21+
def main():
22+
m = 8
23+
rows, bv, pattern = inspect_rows(m=m, num_matrices=1)
24+
print("First matrix rows (bits, int, bin):")
25+
for i, (rb, val) in enumerate(rows):
26+
print(f"row {i}: bits={rb} int={val} bin={format(val, '08b')}")
27+
# Run full plugin to show ranks
28+
res = BinaryMatrixRankTest().run(BytesView(pattern * 8), {"matrix_dim": m, "min_matrices": 8})
29+
print("\nFull plugin result p_value:", res.p_value)
30+
print("ranks:", res.metrics.get("ranks"))
31+
32+
if __name__ == '__main__':
33+
main()

debug_engine.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from patternlab.engine import Engine
2+
from patternlab.plugin_api import TestPlugin, TestResult
3+
4+
class ObsTest(TestPlugin):
5+
def describe(self): return "Observ"
6+
def run(self, data, params):
7+
_ = data.to_bytes()
8+
return TestResult(test_name="obs_test", passed=True, p_value=None)
9+
10+
e = Engine()
11+
e.register_test("obs_test", ObsTest())
12+
out = e.analyze(b"\x00\x01\x02", {"tests":[{"name":"obs_test","params":{}}]})
13+
print("analyze returned:", repr(out))
14+
import inspect, patternlab.engine
15+
src = inspect.getsource(patternlab.engine)
16+
print("\n--- source slice 1000..1320 ---")
17+
for i, line in enumerate(src.splitlines(), start=1):
18+
if 1000 <= i <= 1320:
19+
print(f"{i:4d} | {line}")

docs/api-reference.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# API Reference
2+
3+
Bu sayfa PatternLab paketinin programatik API'sinin kısa bir özetini sağlar. Daha geniş referans için kaynak koduna bakın: [`patternlab/engine.py`](patternlab/engine.py:1), [`patternlab/plugin_api.py`](patternlab/plugin_api.py:1), [`patternlab/cli.py`](patternlab/cli.py:1).
4+
5+
Önemli sınıflar ve fonksiyonlar
6+
- Engine
7+
- Ana analiz akışını yöneten sınıf. Kullanım: `Engine().analyze(data_bytes, config)`.
8+
- Kaydetme: `engine.register_test(name, plugin_instance)` ve `engine.register_transform(...)`.
9+
- Kaynak: [`patternlab/engine.py`](patternlab/engine.py:1)
10+
- TestPlugin, TransformPlugin, VisualPlugin
11+
- Eklenti taban sınıfları. Yeni eklenti yazarken genişletin.
12+
- Ayrıntılar: [`patternlab/plugin_api.py`](patternlab/plugin_api.py:1)
13+
- BytesView
14+
- Veri görünümü yardımcı sınıfı (bit_view, slice, vb.).
15+
- Kullanım: test eklentileri run metodunda `data: BytesView`.
16+
- TestResult
17+
- Test sonucu taşıyıcısı. Alanlar: test_name, passed, p_value, metrics, z_score, p_values, effect_sizes, flags, fdr_rejected, fdr_q.
18+
- Serialize: `serialize_testresult(result)` (bakınız `patternlab/plugin_api.py`).
19+
20+
Hızlı Örnek — Python
21+
```python
22+
from patternlab.engine import Engine
23+
from patternlab.plugins.monobit import MonobitTest
24+
25+
engine = Engine()
26+
engine.register_test("monobit", MonobitTest())
27+
28+
with open("test.bin","rb") as f:
29+
data = f.read()
30+
31+
config = {"tests":[{"name":"monobit","params":{"alpha":0.01}}]}
32+
output = engine.analyze(data, config)
33+
print(output["scorecard"])
34+
```
35+
36+
CLI ile entegrasyon
37+
- CLI entrypoint: [`patternlab/cli.py`](patternlab/cli.py:1)
38+
- Örnek: `patternlab analyze input.bin -c docs/configs/example.yml -o report.json`
39+
40+
Dokümantasyon otomatik türetme
41+
- Eğer ayrıntılı API referansı istenirse, `mkdocstrings` + `pytkdocs` ile otomatik döküm oluşturulabilir. Bunun için `mkdocs.yml` içinde `mkdocstrings` eklentisi ve `requirements-docs.txt` eklenmesi gerekir.
42+
43+
Kaynak dosyaları
44+
- Engine: [`patternlab/engine.py`](patternlab/engine.py:1)
45+
- Plugin API: [`patternlab/plugin_api.py`](patternlab/plugin_api.py:1)
46+
- CLI: [`patternlab/cli.py`](patternlab/cli.py:1)

docs/getting-started.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Getting Started
2+
3+
Bu sayfa projeyi hızlıca kurup çalıştırmak için gerekli adımları içerir.
4+
5+
Önkoşullar
6+
- Python 3.10+ kurulu olmalı
7+
- Depolama kökü: proje dizini (bkz. [`README.md`](README.md:1))
8+
9+
Kurulum (geliştirme)
10+
```bash
11+
# sanal ortam
12+
python -m venv .venv
13+
.venv/Scripts/activate
14+
15+
# proje bağımlılıkları (geliştirme)
16+
pip install -e .[dev]
17+
pip install mkdocs mkdocs-material
18+
```
19+
20+
Hızlı CLI örneği
21+
```bash
22+
# örnek yapılandırma: [`docs/configs/example.yml`](docs/configs/example.yml:1)
23+
patternlab analyze test.bin -c docs/configs/example.yml -o report.json
24+
```
25+
26+
Programatik kullanım
27+
```python
28+
from patternlab.engine import Engine
29+
engine = Engine()
30+
with open("test.bin","rb") as f:
31+
data = f.read()
32+
33+
config = {
34+
"transforms": [{"name":"xor_const","params":{"xor_value":55}}],
35+
"tests": [{"name":"monobit","params":{"alpha":0.01}}]
36+
}
37+
out = engine.analyze(data, config)
38+
print(out["scorecard"])
39+
```
40+
41+
Yerel dokümantasyon geliştirme
42+
```bash
43+
# MkDocs geliştirme sunucusu (canlı yeniden yükleme)
44+
mkdocs serve
45+
# yayın (GitHub Pages)
46+
mkdocs gh-deploy
47+
```
48+
49+
Daha fazla örnek konfigürasyon için bkz. [`docs/configs/example.yml`](docs/configs/example.yml:1) ve [`docs/configs/example.json`](docs/configs/example.json:1).

docs/index.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# PatternLab Dokümantasyonu
2+
3+
Bu site PatternLab projesi için kapsamlı kullanım, geliştirici rehberi ve test referansı sağlar.
4+
5+
Hızlı erişim:
6+
- [`Getting Started`](docs/getting-started.md:1)
7+
- [`User Guide`](docs/user-guide.md:1)
8+
- [`Plugin Developer Guide`](docs/plugin-developer-guide.md:1)
9+
- [`API Reference`](docs/api-reference.md:1)
10+
- [`Test Reference`](docs/test-reference.md:1)
11+
- Konfig örnekleri: [`docs/configs/example.yml`](docs/configs/example.yml:1) ve [`docs/configs/example.json`](docs/configs/example.json:1)
12+
13+
Yerel olarak siteyi çalıştırma
14+
```bash
15+
# Gerekli paketleri kurun (tercihen virtualenv içinde)
16+
pip install mkdocs mkdocs-material
17+
18+
# Geliştirme sunucusu
19+
mkdocs serve
20+
```
21+
22+
GitHub Pages'e hızlı yayım
23+
```bash
24+
# ilk kez deploy için repo ayarlarını kontrol edin
25+
mkdocs gh-deploy
26+
```
27+
28+
Read the Docs ile yayınlama
29+
- Projeyi Read the Docs'da etkinleştirin.
30+
- Gerekirse `requirements-docs.txt` veya `docs/requirements.txt` dosyası ekleyin.
31+
- (Opsiyonel) RTD yapılandırması için `readthedocs.yml` eklenebilir.
32+
33+
Mevcut Markdown içerik kaynakları
34+
- Eklenti rehberi: [`docs/plugin-developer-guide.md`](docs/plugin-developer-guide.md:1)
35+
- Test referansı: [`docs/test-reference.md`](docs/test-reference.md:1)
36+
- Konfig örnekleri: [`docs/configs/README.md`](docs/configs/README.md:1)
37+
38+
Bu sayfa, MkDocs yapılandırması olan [`mkdocs.yml`](mkdocs.yml:1) dosyası ile eşleşir. Bir sonraki adım olarak "Getting Started" ve "User Guide" sayfalarını zenginleştireceğim.

docs/plugin-developer-guide.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,64 @@ Ek referans
9696
- Engine: [`patternlab/engine.py`](patternlab/engine.py:1)
9797
- CLI: [`patternlab/cli.py`](patternlab/cli.py:1)
9898

99-
Bu kılavuz, hızlı bir başlangıç sağlar. İleri seviye konu veya örnek isterseniz ayrı bir doküman eklenebilir.
99+
Bu kılavuz, hızlı bir başlangıç sağlar. İleri seviye konu veya örnek isterseniz ayrı bir doküman eklenebilir.
100+
101+
## Örnek: Tam Bir Test Eklentisi
102+
103+
Aşağıda proje içinde doğrudan kullanılabilecek minimal, test edilebilir bir TestPlugin örneği bulunmaktadır. Bu dosyayı [`patternlab/plugins/my_test.py`](patternlab/plugins/my_test.py:1) olarak ekleyebilirsiniz.
104+
105+
```python
106+
# python
107+
from patternlab.plugin_api import TestPlugin, BytesView, TestResult
108+
109+
class MyThresholdTest(TestPlugin):
110+
"""Basit eşik tabanlı monobit benzeri test örneği."""
111+
112+
requires = ["bits"]
113+
114+
def describe(self) -> str:
115+
return "my_threshold_test"
116+
117+
def run(self, data: BytesView, params: dict) -> TestResult:
118+
bits = data.bit_view()
119+
ones = sum(bits)
120+
n = len(bits)
121+
threshold = float(params.get("threshold", 0.5))
122+
passed = True if n == 0 else (ones / n) > threshold
123+
metrics = {"ones": ones, "total_bits": n, "threshold": threshold}
124+
return TestResult(test_name=self.describe(), passed=passed, p_value=None, metrics=metrics)
125+
```
126+
127+
## Örnek Unit Test
128+
129+
Eklentinizi doğrulamak için pytest ile basit bir test yazın. Aşağıdaki örnek dosyayı [`tests/test_my_threshold.py`](tests/test_my_threshold.py:1) olarak oluşturabilirsiniz.
130+
131+
```python
132+
# python
133+
from patternlab.plugins.my_test import MyThresholdTest
134+
from patternlab.plugin_api import BytesView
135+
136+
def test_my_threshold_pass():
137+
plugin = MyThresholdTest()
138+
# örnek bit dizisi: 6 bit, 5 tane 1 -> oran 0.833
139+
data = BytesView(b'\xf8') # 11111000 (örnek)
140+
result = plugin.run(data, {"threshold": 0.7})
141+
assert result.passed is True
142+
assert result.metrics["ones"] >= 5
143+
144+
def test_my_threshold_fail():
145+
plugin = MyThresholdTest()
146+
data = BytesView(b'\x0f') # 00001111 (oran 0.5)
147+
result = plugin.run(data, {"threshold": 0.6})
148+
assert result.passed is False
149+
```
150+
151+
## Test ve CI Entegrasyonu
152+
153+
- Yeni eklentiyi ekledikten sonra `pytest` ile testleri çalıştırın.
154+
- Eklentinin bağımlılıkları varsa bunları `pyproject.toml` veya `docs/requirements.txt` içine ekleyin.
155+
- Otomatik test çalıştırma için GitHub Actions iş akışlarına test adımı ekleyin (ör: `pytest` çağrısı).
156+
157+
Ek referansler:
158+
- Eklenti API detayları: [`patternlab/plugin_api.py`](patternlab/plugin_api.py:1)
159+
- Mevcut eklenti örnekleri: [`patternlab/plugins/monobit.py`](patternlab/plugins/monobit.py:1)

docs/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mkdocs
2+
mkdocs-material
3+
mkdocstrings[pytkdocs]

0 commit comments

Comments
 (0)