Skip to content

Feature/macro api deprecation - #1189

Merged
AgreeDK merged 2 commits into
OpenSAK-Org:betafrom
nagisml:feature/macro-api-deprecation
Oct 27, 2026
Merged

AgreeDK merged 2 commits into
OpenSAK-Org:betafrom
nagisml:feature/macro-api-deprecation

Conversation

@nagisml

@nagisml nagisml commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Closes #1185. Part of #938.

Stacked on #1188 (feature/rename-set-companion-table). Until that is merged, this PR also shows its commit. Please review/merge #1188 first.

What

The macro API from v1.22.0 needs a way to deprecate things. This PR adds that mechanism, as proposed in #1185. Nothing in API 4 is deprecated.

Registry

  • deprecated: Optional[tuple[int, str]] (API version, what to use instead) on ApiFunction and Param (runtime.py) and on CacheField (cache_data.py). The header keys move into a new HEADER_KEYS registry in metadata.py, with the same field.
  • API_STABLE = {4: "1.22.0"} in runtime.py: which API version went stable in which release.
  • REMOVED in runtime.py: functions removed after their deprecation period, kept here so a call gets a clear error.
  • deprecation.py: the message texts, so the runtime, the Macro manager and the CI helpers word them the same.

Warnings in the macro output

  • A deprecated function's first call in a run prints one line, and the function works as before:
    opensak.old_name is deprecated since API 5 and will be removed in a later version; use opensak.new_name() instead (line 12)
  • A macro started with opensak.run_macro() gets its own warning, which names its file: (child.lua, line 3).
  • Functions written in Lua (e.g. opensak.transaction) get the warning from a small Lua wrapper, so their errors don't pass through Python and still name the macro line.
  • Parameters: the function calls rt._deprecated_param(func, param) where it maps the old name to the new one.
  • Header keys: printed once when the macro starts, and shown in the Macro manager (warning icon and tooltip in the "Needs API" column). The tooltip has one new text, macro_mgr_deprecated_keys, in all languages (machine-translated).
  • Cache fields: no run-time warning, since watching every key read would slow down large loops. They are marked in the docs and editor files, and by the CI helpers.

Removed functions

opensak.old_name stays nil, so if opensak.old_name then still works. Calling it stops the macro with
opensak.old_name was removed in API 6; use opensak.new_name() instead
instead of Lua's attempt to call a nil value. To keep both, a metatable on opensak (and its sub-tables) notes which removed name was looked up, and the runtime rewrites Lua's error message. A macro that catches the error with pcall still sees Lua's original message.

Docs and editors (api_docs.py)

  • api.md: "4, deprecated in 5" in the function table, and Deprecated in API version 5: use opensak.new_name(). at the top of the function's section. Deprecated parameters, cache fields and header keys are marked too, and a short paragraph explains the deprecation rules.
  • Lua Language Server stub: ---@deprecated Use opensak.new_name(), so calls are shown struck through in VS Code.
  • Notepad++: the calltip starts with (deprecated). UltraEdit's wordfile has no calltips, so nothing changes there.

As CONTRIBUTING asks, docs/macros/api.md and macros/types/ are left to the Macro API docs workflow.

CI: API baseline

The N1 baseline didn't exist yet, so this adds a small one:

  • api_baseline.py takes a snapshot of the API: functions with their parameters, cache fields and header keys, each with its deprecation version and feature flag. The committed snapshot is tests/fixtures/macro_api_baseline.json.
  • test_api_matches_the_committed_baseline accepts additions, deprecations, and changes to beta-only entries (feature-flagged). It also accepts a removal once the deprecation's API version is in API_STABLE and a later API version went stable too; the function must then be in REMOVED. It fails on any other removal or rename, including moving a stable function behind a feature flag.
  • scripts/update_macro_api_baseline.py rewrites the baseline. Run it when a stable release ships a new API version; it refuses while the API breaks the current baseline. A test fails if the baseline is older than the newest API_STABLE entry.

For OpenSAK-Macros

metadata.deprecated_names() lists everything deprecated. metadata.find_deprecated(text) returns (line, message) for deprecated header keys, function calls and cache field reads in a macro, so the repository CI can warn. Parameters are positional and can't be found this way. metadata.py now imports deprecation.py, and deprecated_names() needs OpenSAK installed.

Tests

  • 41 new tests in test_macro_deprecation_1185.py. Nothing in API 4 is deprecated, so they mark registry entries as deprecated with monkeypatch. They cover the warnings (once per run, the line, Lua functions, run_macro, parameters, header keys), removed functions, the Macro manager marker, the docs and editor output, deprecated_names() / find_deprecated(), and the baseline rules.
  • Full unit suite passes locally: 7800 passed, 122 skipped.
  • Whole-repo mypy: clean.

…enSAK-Org#1186)

companion_table{} read like a getter for one entry of companion_tables(),
but it changes a table's settings (linked, code_column, description).
Functions that change something are named with a verb (set_center(),
set_corrected()), so it becomes set_companion_table{}. It takes the same
table, returns the same value and behaves the same.

No alias and no API version bump: the function exists only behind the
companion-db feature flag (beta builds), and API 4 isn't stable until
v1.22.0.

- runtime.py: ApiFunction name, bound method, error messages, comments
  and the reference in the opensak.companion() description
- api_docs.py: companion section text, example and Lua type comment
- dnf_stats.lua example and companion tests use the new name; new test
  that opensak.companion_table is nil
- CHANGELOG: Unreleased entry
- docs/macros/api.md and macros/types/ are left to the Macro API docs
  workflow

Part of OpenSAK-Org#938.
… keys (OpenSAK-Org#1185)

From API 4 (v1.22.0) the macro API only grows within an API version.
Renaming or removing a function, parameter, cache field or header key
needs a new API version and a deprecation period of at least one stable
release. This adds the mechanism for that; nothing in API 4 is
deprecated.

- deprecation.py: the message texts, shared by the runtime, the Macro
  manager and the metadata helpers
- runtime.py: `deprecated` on ApiFunction and Param, API_STABLE
  ({4: "1.22.0"}), REMOVED. A deprecated function's first call in a run
  prints one line naming the macro line (and the file in a macro
  started with run_macro()); Lua-written functions get it from a Lua
  wrapper so their errors stay on the Lua side. _deprecated_param()
  warns where a function maps an old parameter. Removed functions stay
  nil (`if opensak.x then` works), and calling one turns Lua's "attempt
  to call a nil value" into "opensak.x was removed in API N; use ...
  instead". Deprecated header keys are printed when the macro starts.
- cache_data.py: `deprecated` on CacheField (docs, editors and CI only,
  no run-time warning)
- metadata.py: HEADER_KEYS registry with `deprecated`,
  MacroInfo.deprecated_keys / deprecation_lines; deprecated_names() and
  find_deprecated() for the OpenSAK-Macros CI
- Macro manager: warning icon and tooltip in the "Needs API" column for
  deprecated header keys; new text macro_mgr_deprecated_keys in all
  languages (machine-translated)
- api_docs.py: api.md marks deprecated functions ("4, deprecated in 5",
  a bold note at the top of the section), parameters, cache fields and
  header keys, plus a short paragraph on how deprecation works. The Lua
  Language Server stub gets ---@deprecated, Notepad++ calltips start
  with "(deprecated)".
- api_baseline.py + tests/fixtures/macro_api_baseline.json +
  scripts/update_macro_api_baseline.py: the API as released. The tests
  accept additions, deprecations and changes to beta-only (flagged)
  entries, and fail on any other removal or rename. A removal is allowed
  only once the deprecation's API version and a later one are listed in
  API_STABLE, and the removed function must then be in REMOVED.
- Tests in test_macro_deprecation_1185.py; CHANGELOG entry
- docs/macros/api.md and macros/types/ are left to the Macro API docs
  workflow

Part of OpenSAK-Org#938.
@AgreeDK
AgreeDK merged commit 8129ee8 into OpenSAK-Org:beta Oct 27, 2026
8 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants