88import subprocess
99import sys
1010import zipfile
11- from typing import Any , Dict , Iterable , Iterator , List , Set , Tuple
11+ from typing import Any , Dict , Iterable , Iterator , List , Set , Tuple , Union
1212
1313try :
1414 from urllib import urlretrieve # type: ignore
@@ -165,7 +165,7 @@ def unpack_sdl2(version: str) -> str:
165165 if sdl2_arc .endswith (".zip" ):
166166 with zipfile .ZipFile (sdl2_arc ) as zf :
167167 zf .extractall ("dependencies/" )
168- else :
168+ elif sys . platform == "darwin" :
169169 assert sdl2_arc .endswith (".dmg" )
170170 subprocess .check_call (["hdiutil" , "mount" , sdl2_arc ])
171171 subprocess .check_call (["mkdir" , "-p" , sdl2_dir ])
@@ -190,7 +190,7 @@ def unpack_sdl2(version: str) -> str:
190190sources = [] # type: List[str]
191191
192192libraries = []
193- library_dirs = []
193+ library_dirs : List [ str ] = []
194194define_macros = [("Py_LIMITED_API" , 0x03060000 )] # type: List[Tuple[str, Any]]
195195
196196sources += walk_sources ("tcod/" )
@@ -281,7 +281,7 @@ def fix_header(filepath: str) -> None:
281281tdl_build = os .environ .get ("TDL_BUILD" , "RELEASE" ).upper ()
282282
283283MSVC_CFLAGS = {"DEBUG" : ["/Od" ], "RELEASE" : ["/GL" , "/O2" , "/GS-" , "/wd4996" ]}
284- MSVC_LDFLAGS = {"DEBUG" : [], "RELEASE" : ["/LTCG" ]}
284+ MSVC_LDFLAGS : Dict [ str , List [ str ]] = {"DEBUG" : [], "RELEASE" : ["/LTCG" ]}
285285GCC_CFLAGS = {
286286 "DEBUG" : ["-std=c99" , "-Og" , "-g" , "-fPIC" ],
287287 "RELEASE" : [
@@ -348,7 +348,7 @@ def fix_header(filepath: str) -> None:
348348'''
349349
350350
351- def find_sdl_attrs (prefix : str ) -> Iterator [Tuple [str , Any ]]:
351+ def find_sdl_attrs (prefix : str ) -> Iterator [Tuple [str , Union [ int , str , Any ] ]]:
352352 """Return names and values from `tcod.lib`.
353353
354354 `prefix` is used to filter out which names to copy.
@@ -378,9 +378,7 @@ def parse_sdl_attrs(prefix: str, all_names: List[str]) -> Tuple[str, str]:
378378 all_names .append (name )
379379 names .append ("%s = %s" % (name , value ))
380380 lookup .append ('%s: "%s"' % (value , name ))
381- names = "\n " .join (names )
382- lookup = "{\n %s,\n }" % (",\n " .join (lookup ),)
383- return names , lookup
381+ return "\n " .join (names ), "{\n %s,\n }" % (",\n " .join (lookup ),)
384382
385383
386384EXCLUDE_CONSTANTS = [
@@ -418,7 +416,6 @@ def update_module_all(filename: str, new_all: str) -> None:
418416
419417def generate_enums (prefix : str ) -> Iterator [str ]:
420418 """Generate attribute assignments suitable for a Python enum."""
421- prefix_len = len (prefix ) - len ("SDL_" ) + 1
422419 for name , value in sorted (find_sdl_attrs (prefix ), key = lambda item : item [1 ]):
423420 name = name .split ("_" , 1 )[1 ]
424421 if name .isdigit ():
@@ -471,10 +468,10 @@ def write_library_constants() -> None:
471468 f .write ("%s = %r\n " % (name [5 :], color ))
472469 all_names .append (name [5 :])
473470
474- all_names = ",\n " .join ('"%s"' % name for name in all_names )
475- f .write ("\n __all__ = [\n %s,\n ]\n " % (all_names ,))
476- update_module_all ("tcod/__init__.py" , all_names )
477- update_module_all ("tcod/libtcodpy.py" , all_names )
471+ all_names_merged = ",\n " .join ('"%s"' % name for name in all_names )
472+ f .write ("\n __all__ = [\n %s,\n ]\n " % (all_names_merged ,))
473+ update_module_all ("tcod/__init__.py" , all_names_merged )
474+ update_module_all ("tcod/libtcodpy.py" , all_names_merged )
478475
479476 with open ("tcod/event_constants.py" , "w" ) as f :
480477 all_names = []
@@ -490,8 +487,8 @@ def write_library_constants() -> None:
490487
491488 f .write ("\n # --- SDL wheel ---\n " )
492489 f .write ("%s\n _REVERSE_WHEEL_TABLE = %s\n " % parse_sdl_attrs ("SDL_MOUSEWHEEL" , all_names ))
493- all_names = ",\n " .join ('"%s"' % name for name in all_names )
494- f .write ("\n __all__ = [\n %s,\n ]\n " % (all_names ,))
490+ all_names_merged = ",\n " .join ('"%s"' % name for name in all_names )
491+ f .write ("\n __all__ = [\n %s,\n ]\n " % (all_names_merged ,))
495492
496493 with open ("tcod/event.py" , "r" ) as f :
497494 event_py = f .read ()
0 commit comments