in utils/check_contrib_list.py [0:0]
def check_contrib_list(update: bool) -> NoReturn:
"""List `contrib` test suites.
Make sure `Makefile` and `.github/workflows/contrib-tests.yml` are consistent with
the list."""
# List contrib test suites
contrib_list = sorted(
path.name for path in CONTRIB_PATH.glob("*") if path.is_dir() and not path.name.startswith("_")
)
# Check Makefile is consistent with list
makefile_content = MAKEFILE_PATH.read_text()
makefile_expected_content = MAKEFILE_REGEX.sub(f"CONTRIB_LIBS := {' '.join(contrib_list)}", makefile_content)
# Check workflow is consistent with list
workflow_content = WORKFLOW_PATH.read_text()
_substitute = "\n".join(f'{" " * 10}"{lib}",' for lib in contrib_list)
workflow_content_expected = WORKFLOW_REGEX.sub(rf"\g<before>{_substitute}\n\g<after>", workflow_content)
#
failed = False
if makefile_content != makefile_expected_content:
if update:
print(
"✅ Contrib libs have been updated in `Makefile`."
"\n Please make sure the changes are accurate and commit them."
)
MAKEFILE_PATH.write_text(makefile_expected_content)
else:
print(
"❌ Expected content mismatch in `Makefile`.\n It is most likely that"
" you added a contrib test and did not update the Makefile.\n Please"
" run `make style` or `python utils/check_contrib_list.py --update`."
)
failed = True
if workflow_content != workflow_content_expected:
if update:
print(
f"✅ Contrib libs have been updated in `{WORKFLOW_PATH}`."
"\n Please make sure the changes are accurate and commit them."
)
WORKFLOW_PATH.write_text(workflow_content_expected)
else:
print(
f"❌ Expected content mismatch in `{WORKFLOW_PATH}`.\n It is most"
" likely that you added a contrib test and did not update the github"
" workflow file.\n Please run `make style` or `python"
" utils/check_contrib_list.py --update`."
)
failed = True
if failed:
exit(1)
print("✅ All good! (contrib list)")
exit(0)