Skip to content

Commit be423db

Browse files
committed
Automatically update __all__ in more places with constants.
Now I don't have to remember to do this, because I won't.
1 parent 426ebe4 commit be423db

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

build_libtcod.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ def parse_sdl_attrs(prefix: str, all_names: List[str]) -> Tuple[str, str]:
430430
]
431431

432432

433+
def update_module_all(filename: str, new_all: str) -> None:
434+
"""Update the __all__ of a file with the constants from new_all."""
435+
RE_CONSTANTS_ALL = re.compile(
436+
r"(.*# --- From constants.py ---).*(# --- End constants.py ---.*)",
437+
re.DOTALL,
438+
)
439+
with open(filename, "r") as f:
440+
match = RE_CONSTANTS_ALL.match(f.read())
441+
assert match, "Can't determine __all__ subsection in %s!" % (filename,)
442+
header, footer = match.groups()
443+
with open(filename, "w") as f:
444+
f.write("%s\n %s,\n %s" % (header, new_all, footer))
445+
446+
433447
def write_library_constants() -> None:
434448
"""Write libtcod constants into the tcod.constants module."""
435449
from tcod._libtcod import lib, ffi
@@ -476,6 +490,8 @@ def write_library_constants() -> None:
476490

477491
all_names = ",\n ".join('"%s"' % name for name in all_names)
478492
f.write("\n__all__ = [\n %s,\n]\n" % (all_names,))
493+
update_module_all("tcod/__init__.py", all_names)
494+
update_module_all("tcod/libtcodpy.py", all_names)
479495

480496
with open("tcod/event_constants.py", "w") as f:
481497
all_names = []

tcod/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,5 @@
807807
"violet",
808808
"white",
809809
"yellow",
810+
# --- End constants.py ---
810811
]

tcod/libtcodpy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,4 +5148,5 @@ def _atexit_verify() -> None:
51485148
"violet",
51495149
"white",
51505150
"yellow",
5151+
# --- End constants.py ---
51515152
]

0 commit comments

Comments
 (0)