in utils/check_all_variable.py [0:0]
def check_static_all(update: bool) -> NoReturn:
"""Check if __all__ is aligned with _SUBMOD_ATTRS or update it."""
content = INIT_FILE_PATH.read_text()
new_all = format_all_definition(_SUBMOD_ATTRS)
expected_items = sorted(attr for attrs in _SUBMOD_ATTRS.values() for attr in attrs)
current_items = list(parse_all_definition(content))
if current_items == expected_items:
print("✅ All good! the __all__ variable is up to date")
exit(0)
if update:
all_pattern = re.compile(r"__all__\s*=\s*\[[^\]]*\]", re.MULTILINE | re.DOTALL)
if all_pattern.search(content):
new_content = all_pattern.sub(new_all, content)
else:
submod_attrs_pattern = re.compile(r"_SUBMOD_ATTRS\s*=\s*{[^}]*}", re.MULTILINE | re.DOTALL)
match = submod_attrs_pattern.search(content)
if not match:
print("Error: _SUBMOD_ATTRS dictionary not found in `./src/huggingface_hub/__init__.py`.")
exit(1)
dict_end = match.end()
new_content = content[:dict_end] + "\n\n\n" + new_all + "\n\n" + content[dict_end:]
INIT_FILE_PATH.write_text(new_content)
print(
"✅ __all__ variable has been updated in `./src/huggingface_hub/__init__.py`."
"\n Please make sure the changes are accurate and commit them."
)
exit(0)
else:
print(
"❌ Expected content mismatch in"
" `./src/huggingface_hub/__init__.py`.\n It is most likely that"
" a module was added to the `_SUBMOD_ATTRS` mapping and did not update the"
" '__all__' variable.\n Please run `make style` or `python"
" utils/check_all_variable.py --update`."
)
exit(1)