Skip to content

Commit 73bf826

Browse files
committed
Docs: generate hooks usage search links with macros
1 parent 2c717d8 commit 73bf826

4 files changed

Lines changed: 46 additions & 13 deletions

File tree

docs/hooks.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ At this point no entity existence decision has been made yet, no `allow_entity_c
147147
In practice, this makes `on_task_start` most useful for metrics, auditing, tracing, and similar task-level bookkeeping.
148148

149149
Real usage examples:
150-
[`on_task_start`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_task_hook%28%22on_task_start%22&type=code)
150+
{{ registrar_usage("on_task_start", 'register_task_hook("on_task_start"') }}
151151

152152
Code reference: [`register_task_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_task_hook]
153153

@@ -172,7 +172,7 @@ Returning `False` aborts processing before the entity record is created.
172172
Because this decision happens before creation completes, there is no persisted master record yet and no snapshot-time current values are available.
173173

174174
Real usage examples:
175-
[`allow_entity_creation`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_allow_entity_creation_hook%28&type=code)
175+
{{ registrar_usage("allow_entity_creation", "register_allow_entity_creation_hook(") }}
176176

177177
Code reference: [`register_allow_entity_creation_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_allow_entity_creation_hook]
178178

@@ -198,7 +198,7 @@ Because they originate from ingestion, they are pushed to the **priority** task
198198
This registration also supports `refresh=` and `may_change=` for recomputation during module-config refresh; see [Refresh-on-config-change behavior for ingestion hooks](#refresh-on-config-change-behavior-for-ingestion-hooks).
199199

200200
Real usage examples:
201-
[`on_entity_creation`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_on_entity_creation_hook%28&type=code)
201+
{{ registrar_usage("on_entity_creation", "register_on_entity_creation_hook(") }}
202202

203203
Code reference: [`register_on_entity_creation_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_on_entity_creation_hook]
204204

@@ -225,7 +225,7 @@ The hook may return `None` or a list of `DataPointTask` objects to be re-ingeste
225225
As with `on_entity_creation`, this registration also supports `refresh=` and `may_change=` for recomputation during module-config refresh; see [Refresh-on-config-change behavior for ingestion hooks](#refresh-on-config-change-behavior-for-ingestion-hooks).
226226

227227
Real usage examples:
228-
[`on_new_attr`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_on_new_attr_hook%28&type=code)
228+
{{ registrar_usage("on_new_attr", "register_on_new_attr_hook(") }}
229229

230230
Code reference: [`register_on_new_attr_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_on_new_attr_hook]
231231

@@ -315,7 +315,7 @@ It is therefore best suited to preparing shared state before correlation callbac
315315
The hook may return `list[DataPointTask]`, which are queued into the main task queue.
316316

317317
Real usage examples:
318-
[`snapshot_init`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_snapshot_init_hook%28&type=code)
318+
{{ registrar_usage("snapshot_init", "register_snapshot_init_hook(") }}
319319

320320
Code reference: [`register_snapshot_init_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_snapshot_init_hook]
321321

@@ -341,7 +341,7 @@ The hook may return `list[DataPointTask]`.
341341
Those tasks are queued back into ingestion, and DP3 also attempts to fold same-entity outputs into the in-memory snapshot-preparation path before correlation hooks run, so timeseries-derived values may influence the same snapshot run.
342342

343343
Real usage examples:
344-
[`timeseries_hook`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_timeseries_hook%28&type=code)
344+
{{ registrar_usage("timeseries_hook", "register_timeseries_hook(") }}
345345

346346
Code reference: [`register_timeseries_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_timeseries_hook]
347347

@@ -372,8 +372,8 @@ In practice, `register_correlation_hook(...)` is the right choice when the modul
372372
Both variants run during snapshot creation, after current values have been computed from the stored master record and after linked entity records have been loaded for the relation paths used by registered hooks.
373373

374374
Real usage examples:
375-
[`correlation_hook`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_correlation_hook%28&type=code)
376-
[`correlation_hook_with_master_record`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_correlation_hook_with_master_record%28&type=code)
375+
{{ registrar_usage("correlation_hook", "register_correlation_hook(") }}
376+
{{ registrar_usage("correlation_hook_with_master_record", "register_correlation_hook_with_master_record(") }}
377377

378378
Code reference: [`register_correlation_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_correlation_hook]
379379
[`register_correlation_hook_with_master_record`][dp3.common.callback_registrar.CallbackRegistrar.register_correlation_hook_with_master_record]
@@ -456,7 +456,7 @@ The callback receives no arguments.
456456
It is mainly used to finish or clean up snapshot-run state after correlation callbacks have completed, and it may return `list[DataPointTask]` queued into the main task queue.
457457

458458
Real usage examples:
459-
[`snapshot_finalize`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_snapshot_finalize_hook%28&type=code)
459+
{{ registrar_usage("snapshot_finalize", "register_snapshot_finalize_hook(") }}
460460

461461
Code reference: [`register_snapshot_finalize_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_snapshot_finalize_hook]
462462

@@ -471,7 +471,7 @@ For `on_entity_creation`, the refresh path re-invokes the hook with the entity `
471471
For `on_new_attr`, the refresh path likewise does not replay an original datapoint payload.
472472
In practice, refresh mode should therefore be reserved for hooks that can recompute from persisted state and do not require the original incoming datapoint contents to be present again.
473473

474-
[Real usages of `refresh=`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+refresh%3D&type=code)
474+
{{ query_cesnet_apps("Real usages of `refresh=`", "refresh=") }}
475475

476476
## Periodic updater hooks: periodic processing over master records
477477

@@ -529,7 +529,7 @@ When registering it, `hook_id` must be unique.
529529
It is also important to set `period` realistically for the hook's execution cost; if the period is too short, runs may overlap with later batches and effectively stretch the refresh cadence.
530530

531531
Real usage examples:
532-
[`periodic_update_hook`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_periodic_update_hook%28&type=code)
532+
{{ registrar_usage("periodic_update_hook", "register_periodic_update_hook(") }}
533533

534534
Code reference: [`register_periodic_update_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_periodic_update_hook]
535535

@@ -557,7 +557,7 @@ The callback therefore receives only `entity_type` and `eid`, and it may return
557557
As with `periodic_update_hook`, `hook_id` must be unique and `period` should be configured realistically so updater batches can complete before the next sweep is due.
558558

559559
Real usage examples:
560-
[`periodic_eid_update_hook`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.register_periodic_eid_update_hook%28&type=code)
560+
{{ registrar_usage("periodic_eid_update_hook", "register_periodic_eid_update_hook(") }}
561561

562562
Code reference: [`register_periodic_eid_update_hook`][dp3.common.callback_registrar.CallbackRegistrar.register_periodic_eid_update_hook]
563563

@@ -592,7 +592,7 @@ Its return value is ignored by DP3.
592592
In practice, this hook is most useful for housekeeping, external polling, maintenance, metrics emission, periodic cleanup, and similar module-level maintenance work.
593593

594594
Real usage examples:
595-
[`scheduler_register`](https://github.com/search?q=repo%3ACESNET%2FAmfora+OR+repo%3ACESNET%2FADiCT+OR+repo%3ACESNET%2FNERD2+registrar.scheduler_register%28&type=code)
595+
{{ registrar_usage("scheduler_register", "scheduler_register(") }}
596596

597597
Code reference: [`scheduler_register`][dp3.common.callback_registrar.CallbackRegistrar.scheduler_register]
598598

macros.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from urllib.parse import quote_plus
2+
3+
CESNET_APP_REPOS = (
4+
"CESNET/Amfora",
5+
"CESNET/ADiCT",
6+
"CESNET/NERD2",
7+
)
8+
9+
GITHUB_CODE_SEARCH_URL = "https://github.com/search?q={query}&type=code"
10+
11+
12+
def _repo_query(repos: tuple[str, ...]) -> str:
13+
return " OR ".join(f"repo:{repo}" for repo in repos)
14+
15+
16+
def _github_code_search_link(label: str, query: str) -> str:
17+
encoded_query = quote_plus(query)
18+
return f"[{label}]({GITHUB_CODE_SEARCH_URL.format(query=encoded_query)})"
19+
20+
21+
def define_env(env):
22+
@env.macro
23+
def query_cesnet_apps(label: str, query: str) -> str:
24+
full_query = f"{_repo_query(CESNET_APP_REPOS)} {query}"
25+
return _github_code_search_link(label, full_query)
26+
27+
@env.macro
28+
def registrar_usage(label: str, registrar_call: str) -> str:
29+
return query_cesnet_apps(f"`{label}`", f"registrar.{registrar_call}")

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ markdown_extensions:
107107
plugins:
108108
# Default search bar
109109
- search
110+
# Macros/helpers for shared docs snippets and generated links
111+
- macros:
112+
module_name: macros
110113
# Automatically link across pages
111114
- autorefs
112115
# Generating code reference

requirements.dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mkdocs>=1.0.3
22
mkdocs-gen-files>=0.4
33
mkdocs-literate-nav>=0.6
4+
mkdocs-macros-plugin==1.5.0
45
mkdocs-material==9.0.12
56
mkdocs-section-index>=0.3
67
mkdocstrings>=0.19

0 commit comments

Comments
 (0)