okf-cli 0.6.1__tar.gz → 0.7.0__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.
Files changed (50) hide show
  1. {okf_cli-0.6.1 → okf_cli-0.7.0}/PKG-INFO +1 -1
  2. {okf_cli-0.6.1 → okf_cli-0.7.0}/pyproject.toml +1 -1
  3. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/api.py +44 -3
  4. {okf_cli-0.6.1 → okf_cli-0.7.0}/tests/test_api.py +131 -0
  5. {okf_cli-0.6.1 → okf_cli-0.7.0}/uv.lock +1 -1
  6. {okf_cli-0.6.1 → okf_cli-0.7.0}/.github/workflows/test.yml +0 -0
  7. {okf_cli-0.6.1 → okf_cli-0.7.0}/.gitignore +0 -0
  8. {okf_cli-0.6.1 → okf_cli-0.7.0}/.last-update.json +0 -0
  9. {okf_cli-0.6.1 → okf_cli-0.7.0}/AGENTS.md +0 -0
  10. {okf_cli-0.6.1 → okf_cli-0.7.0}/LICENSE +0 -0
  11. {okf_cli-0.6.1 → okf_cli-0.7.0}/README.md +0 -0
  12. {okf_cli-0.6.1 → okf_cli-0.7.0}/SPEC/OKF_SPEC_V0_1.md +0 -0
  13. {okf_cli-0.6.1 → okf_cli-0.7.0}/SPEC/OKF_SPEC_V0_2.md +0 -0
  14. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/.okfignore +0 -0
  15. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/README.md +0 -0
  16. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/blank-line/no-blank.md +0 -0
  17. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/blank-line/with-blank.md +0 -0
  18. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/computations/revenue.md +0 -0
  19. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/datasets/sales.md +0 -0
  20. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/domain.md +0 -0
  21. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/loose/deep/no-heading.md +0 -0
  22. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/loose/no-desc.md +0 -0
  23. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/loose/no-title.md +0 -0
  24. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/metrics/income-statement.md +0 -0
  25. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/playbooks/incident-response.md +0 -0
  26. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/playbooks/oncall-guide.md +0 -0
  27. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/references/revenue-recognition.md +0 -0
  28. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/smoke-ignore.md +0 -0
  29. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/tables/customers.md +0 -0
  30. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/tables/orders.md +0 -0
  31. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/tables/partitions/2026/q1/jan/january.md +0 -0
  32. {okf_cli-0.6.1 → okf_cli-0.7.0}/example/tables/partitions/daily.md +0 -0
  33. {okf_cli-0.6.1 → okf_cli-0.7.0}/skills/okf-cli/SKILL.md +0 -0
  34. {okf_cli-0.6.1 → okf_cli-0.7.0}/skills/writing-knowledge-base/SKILL.md +0 -0
  35. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/__init__.py +0 -0
  36. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/cli.py +0 -0
  37. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/commands/__init__.py +0 -0
  38. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/commands/bundle.py +0 -0
  39. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/commands/list.py +0 -0
  40. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/commands/read.py +0 -0
  41. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/commands/validate.py +0 -0
  42. {okf_cli-0.6.1 → okf_cli-0.7.0}/src/okf/core.py +0 -0
  43. {okf_cli-0.6.1 → okf_cli-0.7.0}/tests/test_cli.py +0 -0
  44. {okf_cli-0.6.1 → okf_cli-0.7.0}/tests/test_core.py +0 -0
  45. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/architecture.md +0 -0
  46. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/domain-model.md +0 -0
  47. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/operations.md +0 -0
  48. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/quickstart.md +0 -0
  49. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/testing.md +0 -0
  50. {okf_cli-0.6.1 → okf_cli-0.7.0}/wiki/workflows.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: okf-cli
3
- Version: 0.6.1
3
+ Version: 0.7.0
4
4
  Summary: Open Knowledge Format tooling
5
5
  License: MIT License
6
6
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "okf-cli"
3
- version = "0.6.1"
3
+ version = "0.7.0"
4
4
  description = "Open Knowledge Format tooling"
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -146,10 +146,17 @@ def _is_ignored(rel_posix: str, ignored: set[str]) -> bool:
146
146
  return any(pat.endswith("/") and rel_posix.startswith(pat) for pat in ignored)
147
147
 
148
148
 
149
- def _generate_indexes(processed: list[tuple[Path, dict]], dst: Path) -> None:
150
- """Generate index.md for every directory with concept files or subdirs."""
149
+ def _generate_indexes(
150
+ processed: list[tuple[Path, dict]], dst: Path, *, overwrite: bool = False
151
+ ) -> int:
152
+ """Generate index.md for every directory with concept files or subdirs.
153
+
154
+ Returns the number of index files written. Existing index files are kept
155
+ unless ``overwrite`` is true.
156
+ """
151
157
  dir_files: dict[Path, list[dict]] = {}
152
158
  dir_subdirs: dict[Path, set[str]] = {}
159
+ written = 0
153
160
 
154
161
  for rel, meta in processed:
155
162
  parent = rel.parent
@@ -167,7 +174,7 @@ def _generate_indexes(processed: list[tuple[Path, dict]], dst: Path) -> None:
167
174
 
168
175
  for dir_path in sorted(set(dir_files.keys()) | set(dir_subdirs.keys())):
169
176
  index_path = dst / dir_path / "index.md"
170
- if index_path.exists():
177
+ if index_path.exists() and not overwrite:
171
178
  continue
172
179
 
173
180
  lines: list[str] = []
@@ -199,6 +206,9 @@ def _generate_indexes(processed: list[tuple[Path, dict]], dst: Path) -> None:
199
206
  if lines:
200
207
  index_path.parent.mkdir(parents=True, exist_ok=True)
201
208
  index_path.write_text("\n".join(lines), encoding="utf-8")
209
+ written += 1
210
+
211
+ return written
202
212
 
203
213
 
204
214
  # ---------------------------------------------------------------------------
@@ -535,6 +545,37 @@ def bundle(
535
545
  )
536
546
 
537
547
 
548
+ def reindex(bundle_dir: str | Path) -> BundleResult:
549
+ """Rebuild every index.md in a bundle from the concept files on disk.
550
+
551
+ Args:
552
+ bundle_dir: Path to an OKF bundle directory.
553
+
554
+ Returns:
555
+ BundleResult with ``files_written`` set to the number of index files
556
+ written and ``output_dir`` set to ``bundle_dir``.
557
+
558
+ Raises:
559
+ NotADirectoryError: If bundle_dir is not a directory.
560
+ ValueError: If the directory is not a conformant OKF bundle.
561
+ """
562
+ dst = Path(bundle_dir)
563
+ entries = list_entries(dst)
564
+ processed = [
565
+ (
566
+ Path(e["id"] + ".md"),
567
+ {
568
+ "title": e["title"],
569
+ "description": e["description"],
570
+ "type": e["type"],
571
+ },
572
+ )
573
+ for e in entries
574
+ ]
575
+ count = _generate_indexes(processed, dst, overwrite=True)
576
+ return BundleResult(files_written=count, output_dir=dst)
577
+
578
+
538
579
  def _iter_concept_files(dir_path: Path):
539
580
  """Yield (concept_id, file_path) for every concept in a bundle.
540
581
 
@@ -14,6 +14,7 @@ from okf.api import (
14
14
  convert_file,
15
15
  list_concepts,
16
16
  list_entries,
17
+ reindex,
17
18
  show_concept,
18
19
  validate,
19
20
  )
@@ -1296,6 +1297,136 @@ class TestValidate:
1296
1297
  assert len(result.errors) == 2
1297
1298
 
1298
1299
 
1300
+ # ---------------------------------------------------------------------------
1301
+ # reindex()
1302
+ # ---------------------------------------------------------------------------
1303
+
1304
+
1305
+ class TestReindex:
1306
+ def test_updates_stale_root_index(self, tmp_path: Path):
1307
+ src = tmp_path / "src"
1308
+ dst = tmp_path / "out"
1309
+ src.mkdir()
1310
+ _write(src, {"tables/orders.md": "# Orders\n\n> One row.\n\nBody."})
1311
+ bundle(src, dst)
1312
+ convert_content(
1313
+ "# Fresh Concept\n\n> New root concept.\n\nBody.",
1314
+ dst / "fresh.md",
1315
+ type_="reference",
1316
+ )
1317
+ assert "Fresh Concept" not in (dst / "index.md").read_text()
1318
+
1319
+ result = reindex(dst)
1320
+
1321
+ assert isinstance(result, BundleResult)
1322
+ assert result.output_dir == dst
1323
+ assert "[Fresh Concept](fresh.md)" in (dst / "index.md").read_text()
1324
+
1325
+ def test_updates_subdir_index(self, tmp_path: Path):
1326
+ src = tmp_path / "src"
1327
+ dst = tmp_path / "out"
1328
+ src.mkdir()
1329
+ _write(src, {"tables/orders.md": "# Orders\n\n> One row.\n\nBody."})
1330
+ bundle(src, dst)
1331
+ convert_content(
1332
+ "# Extra\n\n> Extra table.\n\nBody.",
1333
+ dst / "tables" / "extra.md",
1334
+ type_="tables",
1335
+ )
1336
+
1337
+ reindex(dst)
1338
+
1339
+ assert "[Extra](extra.md)" in (dst / "tables" / "index.md").read_text()
1340
+
1341
+ def test_adds_subdir_to_root_index(self, tmp_path: Path):
1342
+ src = tmp_path / "src"
1343
+ dst = tmp_path / "out"
1344
+ src.mkdir()
1345
+ _write(src, {"tables/orders.md": "# Orders\n\n> One row.\n\nBody."})
1346
+ bundle(src, dst)
1347
+ convert_content(
1348
+ "# Q1\n\n> First quarter.\n\nBody.",
1349
+ dst / "reports" / "q1.md",
1350
+ type_="reports",
1351
+ )
1352
+
1353
+ reindex(dst)
1354
+
1355
+ assert "[reports](reports/)" in (dst / "index.md").read_text()
1356
+
1357
+ def test_idempotent(self, tmp_path: Path):
1358
+ src = tmp_path / "src"
1359
+ dst = tmp_path / "out"
1360
+ src.mkdir()
1361
+ _write(
1362
+ src,
1363
+ {
1364
+ "tables/orders.md": "# Orders\n\n> One row.\n\nBody.",
1365
+ "root.md": "# Root\n\n> Root concept.\n\nBody.",
1366
+ },
1367
+ )
1368
+ bundle(src, dst)
1369
+
1370
+ first = reindex(dst)
1371
+ root_first = (dst / "index.md").read_text()
1372
+ sub_first = (dst / "tables" / "index.md").read_text()
1373
+
1374
+ second = reindex(dst)
1375
+
1376
+ assert first.files_written == second.files_written
1377
+ assert (dst / "index.md").read_text() == root_first
1378
+ assert (dst / "tables" / "index.md").read_text() == sub_first
1379
+
1380
+ def test_keeps_root_okf_version(self, tmp_path: Path):
1381
+ src = tmp_path / "src"
1382
+ dst = tmp_path / "out"
1383
+ src.mkdir()
1384
+ _write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
1385
+ bundle(src, dst)
1386
+
1387
+ reindex(dst)
1388
+
1389
+ assert _read_frontmatter(dst / "index.md") == {"okf_version": "0.2"}
1390
+
1391
+ def test_passes_validate(self, tmp_path: Path):
1392
+ src = tmp_path / "src"
1393
+ dst = tmp_path / "out"
1394
+ src.mkdir()
1395
+ _write(src, {"tables/orders.md": "# Orders\n\n> One row.\n\nBody."})
1396
+ bundle(src, dst)
1397
+ convert_content(
1398
+ "# Fresh\n\n> New.\n\nBody.", dst / "tables" / "fresh.md", type_="tables"
1399
+ )
1400
+
1401
+ reindex(dst)
1402
+
1403
+ assert validate(dst).ok
1404
+
1405
+ def test_rejects_non_conformant_bundle(self, tmp_path: Path):
1406
+ d = tmp_path / "raw"
1407
+ d.mkdir()
1408
+ _write(d, {"plain.md": "# Title\n\n> Desc.\n\nBody."})
1409
+
1410
+ with pytest.raises(ValueError, match="not an OKF-conformant"):
1411
+ reindex(d)
1412
+
1413
+ def test_files_written_count(self, tmp_path: Path):
1414
+ src = tmp_path / "src"
1415
+ dst = tmp_path / "out"
1416
+ src.mkdir()
1417
+ _write(src, {"tables/a.md": "# A\n\n> Desc.\n"})
1418
+ bundle(src, dst)
1419
+
1420
+ result = reindex(dst)
1421
+
1422
+ # Root index plus one subdirectory index.
1423
+ assert result.files_written == 2
1424
+
1425
+ def test_not_a_dir(self, tmp_path: Path):
1426
+ with pytest.raises(NotADirectoryError):
1427
+ reindex(tmp_path / "nope")
1428
+
1429
+
1299
1430
  # ---------------------------------------------------------------------------
1300
1431
  # cross-command: bundle → validate/list/show
1301
1432
  # ---------------------------------------------------------------------------
@@ -52,7 +52,7 @@ wheels = [
52
52
 
53
53
  [[package]]
54
54
  name = "okf-cli"
55
- version = "0.6.0"
55
+ version = "0.7.0"
56
56
  source = { editable = "." }
57
57
  dependencies = [
58
58
  { name = "pyyaml" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes