Skip to content

Commit

Permalink
Implemented a backwards compatibility feature for legacy check-IDs.
Browse files Browse the repository at this point in the history
All reporters are now listing which legacy check-IDs were used on the `--check-id` and `--exclude-checkid` options and instructing the users to update to the new naming scheme, because the old ones will be permanently deprecated in the next major release.

(issue #4942)
  • Loading branch information
felipesanches committed Dec 28, 2024
1 parent ccbfdce commit 8658bca
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 12 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ A more detailed list of changes is available in the corresponding milestones for
### Noteworthy code-changes
- Created a dictionary at `Lib/fontbakery/legacy_checkids.py` that documents the renaming of checks-IDs that is happenning between versions v0.12.10 and v0.13.0 (PR #4929)

This file contains a translation map that can be useful:
- to be read directly by humans
- to generate documentation
- to implement a backwards compatibility mechanism
- This file contains a translation map that can be useful to be read directly by humans and it is also used to implement a backwards compatibility mechanism to accept the old IDs.

- All reporters are now listing which legacy check-IDs were used on the --check-id and --exclude-checkid options and instructing the users to update to the new naming scheme, because the old ones will be permanently deprecated in the next major release. (issue #4942)

### New checks
#### Added to the Universal profile
Expand Down
48 changes: 40 additions & 8 deletions Lib/fontbakery/checkrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(
for testable in self.context.testables:
testable.context = self.context

self.legacy_checkid_references = set()

@staticmethod
def _check_result(result) -> Subresult:
"""Check that the check returned a well formed result:
Expand Down Expand Up @@ -231,17 +233,46 @@ def _run_check(self, identity: Identity):

@property
def order(self) -> Tuple[Identity, ...]:
from fontbakery.legacy_checkids import renaming_map

legacy_ids = {}
for k, v in renaming_map.items():
try:
legacy_ids[v].append(k)
except KeyError:
legacy_ids[v] = [k]

_order = []
for section in self.profile.sections:
for check in section.checks:
if self._explicit_checks and all(
explicit not in check.id for explicit in self._explicit_checks
):
continue
if self._exclude_checks and any(
excluded in check.id for excluded in self._exclude_checks
):
continue
if self._explicit_checks:
selected_via_new_checkid = any(
explicit in check.id for explicit in self._explicit_checks
)
selected_via_legacy_checkid = False
if not selected_via_new_checkid and check.id in legacy_ids:
for legacy in legacy_ids[check.id]:
if any(
explicit in legacy for explicit in self._explicit_checks
):
selected_via_legacy_checkid = True
self.legacy_checkid_references.add(legacy)

if not selected_via_legacy_checkid and not selected_via_new_checkid:
continue

if self._exclude_checks:
if any(excluded in check.id for excluded in self._exclude_checks):
continue

if check.id in legacy_ids:
for legacy in legacy_ids[check.id]:
if any(
excluded in legacy for excluded in self._exclude_checks
):
self.legacy_checkid_references.add(legacy)
continue

args = set(check.args)
context_args = set(arg for arg in args if arg in dir(self.context))

Expand Down Expand Up @@ -296,6 +327,7 @@ def distribute_result(result):

# Tell all the reporters we're done
for reporter in reporters:
reporter.legacy_checkid_references = list(self.legacy_checkid_references)
reporter.end()

def _override_status(self, subresult: Subresult, check):
Expand Down
24 changes: 24 additions & 0 deletions Lib/fontbakery/reporters/ghmarkdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ def template(self, data):
other_checks[key] = []
other_checks[key].append(check)

if self.legacy_checkid_references:
references = "\n - ".join(self.legacy_checkid_references)
deprecation_warning = (
"By late-December 2024, FontBakery version 0.13.0"
" introduced a new naming scheme for the check-IDs.\n"
"\n"
"Fontbakery detected usage of old IDs and performed an"
" automatic backwards-compatibility translation for you.\n"
"This automatic translation will be deprecated in the next"
" major release.\n"
"\n"
"Please start using the new check-IDs as documented at\n"
"https://github.com/fonttools/fontbakery/blob/"
"83db7cc2a6ad58585ddec9397306e0420843edb1/Lib/"
"fontbakery/legacy_checkids.py\n"
"\n"
"The following legacy check-IDs were detected:\n"
f" - {references}\n"
"\n"
)
else:
deprecation_warning = None

# Sort them by log-level results:
ordering = ["ERROR", "FATAL", "FAIL", "WARN", "INFO", "PASS", "SKIP"]
for check_group in [fatal_checks, experimental_checks, other_checks]:
Expand All @@ -94,4 +117,5 @@ def template(self, data):
other_checks=other_checks,
succinct=self.succinct,
total=num_checks,
deprecation_warning=deprecation_warning,
)
23 changes: 23 additions & 0 deletions Lib/fontbakery/reporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ def template(self, data) -> str:
(e for e in section["result"].elements() if e != "PASS"),
key=LOGLEVELS.index,
)
if self.legacy_checkid_references:
deprecation_warning = (
"By late-December 2024, FontBakery version 0.13.0"
" introduced a new naming scheme for the check-IDs.<br>"
"<br>"
"Fontbakery detected usage of old IDs and performed an"
" automatic backwards-compatibility translation for you.<br>"
"This automatic translation will be deprecated in the next"
" major release.<br>"
"<br>"
"Please start using the new check-IDs as documented at"
" <a href='https://github.com/fonttools/fontbakery/blob/"
"83db7cc2a6ad58585ddec9397306e0420843edb1/Lib/"
"fontbakery/legacy_checkids.py'>"
"/Lib/fontbakery/legacy_checkids.py</a><br>"
"<br>"
"The following legacy check-IDs were detected:<br>"
f" - {'<br> - '.join(self.legacy_checkid_references)}<br>"
"<br>"
)
else:
deprecation_warning = None

return self.template_engine().render(
sections=data["sections"],
Expand All @@ -118,4 +140,5 @@ def template(self, data) -> str:
total=total,
summary={k: data["result"][k] for k in LOGLEVELS},
succinct=self.succinct,
deprecation_warning=deprecation_warning,
)
4 changes: 4 additions & 0 deletions Lib/fontbakery/reporters/templates/html/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

<main>
{% include "top.html" %}
{% if deprecation_warning %}
<h3>DEPRECATION WARNING</h3>
<p>{{deprecation_warning|safe}}</p>
{% endif %}
{% include "summary_table.html" %}
{% include "summary_notes.html" %}
{% for section in sections %}
Expand Down
5 changes: 5 additions & 0 deletions Lib/fontbakery/reporters/templates/markdown/main.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

fontbakery version: {{fb_version}}

{% if deprecation_warning %}
### DEPRECATION WARNING
{{deprecation_warning}}
{% endif %}

{% if fatal_checks %}
## Checks with FATAL results

Expand Down
21 changes: 21 additions & 0 deletions Lib/fontbakery/reporters/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@ def end(self):
and self._counter[PASS.name] > 20
):
self._console.print(CUPCAKE)
if self.legacy_checkid_references:
references = "\n - ".join(self.legacy_checkid_references)
self._console.print(
"[message-FATAL]DEPRECATION WARNING[/]:\n"
"By late-December 2024, FontBakery version 0.13.0 introduced a new"
" naming scheme for the check-IDs.\n"
"\n"
"Fontbakery detected usage of old IDs and performed an automatic"
" backwards-compatibility translation for you.\n"
"This automatic translation will be deprecated in the next"
" major release.\n"
"\n"
"Please start using the new check-IDs as documented at\n"
"https://github.com/fonttools/fontbakery/blob/"
"83db7cc2a6ad58585ddec9397306e0420843edb1/Lib/"
"fontbakery/legacy_checkids.py\n"
"\n"
"The following legacy check-IDs were detected:\n"
f" - {references}\n"
"\n"
)
self._console.print("DONE!")

def receive_result(self, checkresult: CheckResult):
Expand Down

0 comments on commit 8658bca

Please sign in to comment.