Repository navigation
Feature/macro api deprecation - #1189
Merged
Merged
Conversation
…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.
13 of 22 tasks
8 tasks
Closed
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1185. Part of #938.
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) onApiFunctionandParam(runtime.py) and onCacheField(cache_data.py). The header keys move into a newHEADER_KEYSregistry inmetadata.py, with the same field.API_STABLE = {4: "1.22.0"}inruntime.py: which API version went stable in which release.REMOVEDinruntime.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
opensak.old_name is deprecated since API 5 and will be removed in a later version; use opensak.new_name() instead (line 12)opensak.run_macro()gets its own warning, which names its file:(child.lua, line 3).opensak.transaction) get the warning from a small Lua wrapper, so their errors don't pass through Python and still name the macro line.rt._deprecated_param(func, param)where it maps the old name to the new one.macro_mgr_deprecated_keys, in all languages (machine-translated).Removed functions
opensak.old_namestaysnil, soif opensak.old_name thenstill works. Calling it stops the macro withopensak.old_name was removed in API 6; use opensak.new_name() insteadinstead of Lua's
attempt to call a nil value. To keep both, a metatable onopensak(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 withpcallstill 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: useopensak.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.---@deprecated Use opensak.new_name(), so calls are shown struck through in VS Code.(deprecated). UltraEdit's wordfile has no calltips, so nothing changes there.As CONTRIBUTING asks,
docs/macros/api.mdandmacros/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.pytakes 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 istests/fixtures/macro_api_baseline.json.test_api_matches_the_committed_baselineaccepts additions, deprecations, and changes to beta-only entries (feature-flagged). It also accepts a removal once the deprecation's API version is inAPI_STABLEand a later API version went stable too; the function must then be inREMOVED. It fails on any other removal or rename, including moving a stable function behind a feature flag.scripts/update_macro_api_baseline.pyrewrites 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 newestAPI_STABLEentry.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.pynow importsdeprecation.py, anddeprecated_names()needs OpenSAK installed.Tests
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.