3434
3535# Regular expressions to parse the headers for cffi.
3636RE_COMMENT = re .compile (r"\s*/\*.*?\*/|\s*//*?$" , re .DOTALL | re .MULTILINE )
37- RE_CPLUSPLUS = re .compile (
38- r"#ifdef __cplusplus.*?#endif.*?$" , re .DOTALL | re .MULTILINE
39- )
40- RE_PREPROCESSOR = re .compile (
41- r"(?!#define\s+\w+\s+\d+$)#.*?(?<!\\)$" , re .DOTALL | re .MULTILINE
42- )
37+ RE_CPLUSPLUS = re .compile (r"#ifdef __cplusplus.*?#endif.*?$" , re .DOTALL | re .MULTILINE )
38+ RE_PREPROCESSOR = re .compile (r"(?!#define\s+\w+\s+\d+$)#.*?(?<!\\)$" , re .DOTALL | re .MULTILINE )
4339RE_INCLUDE = re .compile (r'#include "([^"]*)"' )
4440RE_TAGS = re .compile (
4541 r"TCODLIB_C?API|TCOD_PUBLIC|TCOD_NODISCARD|TCOD_DEPRECATED_NOMESSAGE"
4642 r"|(TCOD_DEPRECATED|TCODLIB_FORMAT)\([^)]*\)|__restrict"
4743)
4844RE_VAFUNC = re .compile (r".*\(.*va_list.*\);" )
49- RE_INLINE = re .compile (
50- r"(^.*?inline.*?\(.*?\))\s*\{.*?\}$" , re .DOTALL | re .MULTILINE
51- )
45+ RE_INLINE = re .compile (r"(^.*?inline.*?\(.*?\))\s*\{.*?\}$" , re .DOTALL | re .MULTILINE )
5246
5347
5448class ParsedHeader :
@@ -121,8 +115,7 @@ def resolve_dependencies(
121115 if not unresolved & resolved :
122116 raise RuntimeError (
123117 "Could not resolve header load order.\n "
124- "Possible cyclic dependency with the unresolved headers:\n %s"
125- % (unresolved ,)
118+ "Possible cyclic dependency with the unresolved headers:\n %s" % (unresolved ,)
126119 )
127120 unresolved -= resolved
128121 return result
@@ -176,9 +169,7 @@ def unpack_sdl2(version: str) -> str:
176169 assert sdl2_arc .endswith (".dmg" )
177170 subprocess .check_call (["hdiutil" , "mount" , sdl2_arc ])
178171 subprocess .check_call (["mkdir" , "-p" , sdl2_dir ])
179- subprocess .check_call (
180- ["cp" , "-r" , "/Volumes/SDL2/SDL2.framework" , sdl2_dir ]
181- )
172+ subprocess .check_call (["cp" , "-r" , "/Volumes/SDL2/SDL2.framework" , sdl2_dir ])
182173 subprocess .check_call (["hdiutil" , "unmount" , "/Volumes/SDL2" ])
183174 return sdl2_path
184175
@@ -234,9 +225,7 @@ def unpack_sdl2(version: str) -> str:
234225else :
235226 matches = re .findall (
236227 r"-I(\S+)" ,
237- subprocess .check_output (
238- ["sdl2-config" , "--cflags" ], universal_newlines = True
239- ),
228+ subprocess .check_output (["sdl2-config" , "--cflags" ], universal_newlines = True ),
240229 )
241230 assert matches
242231
@@ -249,9 +238,7 @@ def unpack_sdl2(version: str) -> str:
249238if sys .platform == "win32" :
250239 include_dirs .append (SDL2_INCLUDE )
251240 ARCH_MAPPING = {"32bit" : "x86" , "64bit" : "x64" }
252- SDL2_LIB_DIR = os .path .join (
253- SDL2_BUNDLE_PATH , "lib/" , ARCH_MAPPING [BITSIZE ]
254- )
241+ SDL2_LIB_DIR = os .path .join (SDL2_BUNDLE_PATH , "lib/" , ARCH_MAPPING [BITSIZE ])
255242 library_dirs .append (SDL2_LIB_DIR )
256243 SDL2_LIB_DEST = os .path .join ("tcod" , ARCH_MAPPING [BITSIZE ])
257244 if not os .path .exists (SDL2_LIB_DEST ):
@@ -287,21 +274,9 @@ def fix_header(filepath: str) -> None:
287274 define_macros .append (("HAVE_UNISTD_H" , 1 ))
288275
289276if sys .platform not in ["win32" , "darwin" ]:
290- extra_parse_args += (
291- subprocess .check_output (
292- ["sdl2-config" , "--cflags" ], universal_newlines = True
293- )
294- .strip ()
295- .split ()
296- )
277+ extra_parse_args += subprocess .check_output (["sdl2-config" , "--cflags" ], universal_newlines = True ).strip ().split ()
297278 extra_compile_args += extra_parse_args
298- extra_link_args += (
299- subprocess .check_output (
300- ["sdl2-config" , "--libs" ], universal_newlines = True
301- )
302- .strip ()
303- .split ()
304- )
279+ extra_link_args += subprocess .check_output (["sdl2-config" , "--libs" ], universal_newlines = True ).strip ().split ()
305280
306281tdl_build = os .environ .get ("TDL_BUILD" , "RELEASE" ).upper ()
307282
@@ -399,9 +374,7 @@ def parse_sdl_attrs(prefix: str, all_names: List[str]) -> Tuple[str, str]:
399374 """
400375 names = []
401376 lookup = []
402- for name , value in sorted (
403- find_sdl_attrs (prefix ), key = lambda item : item [1 ]
404- ):
377+ for name , value in sorted (find_sdl_attrs (prefix ), key = lambda item : item [1 ]):
405378 all_names .append (name )
406379 names .append ("%s = %s" % (name , value ))
407380 lookup .append ('%s: "%s"' % (value , name ))
@@ -446,9 +419,7 @@ def update_module_all(filename: str, new_all: str) -> None:
446419def generate_enums (prefix : str ) -> Iterator [str ]:
447420 """Generate attribute assignments suitable for a Python enum."""
448421 prefix_len = len (prefix ) - len ("SDL_" ) + 1
449- for name , value in sorted (
450- find_sdl_attrs (prefix ), key = lambda item : item [1 ]
451- ):
422+ for name , value in sorted (find_sdl_attrs (prefix ), key = lambda item : item [1 ]):
452423 name = name .split ("_" , 1 )[1 ]
453424 if name .isdigit ():
454425 name = f"N{ name } "
@@ -473,9 +444,7 @@ def write_library_constants() -> None:
473444 continue
474445 if name in EXCLUDE_CONSTANTS :
475446 continue
476- if any (
477- name .startswith (prefix ) for prefix in EXCLUDE_CONSTANT_PREFIXES
478- ):
447+ if any (name .startswith (prefix ) for prefix in EXCLUDE_CONSTANT_PREFIXES ):
479448 continue
480449 value = getattr (lib , name )
481450 if name [:5 ] == "TCOD_" :
@@ -511,28 +480,16 @@ def write_library_constants() -> None:
511480 all_names = []
512481 f .write (EVENT_CONSTANT_MODULE_HEADER )
513482 f .write ("# --- SDL scancodes ---\n " )
514- f .write (
515- "%s\n _REVERSE_SCANCODE_TABLE = %s\n "
516- % parse_sdl_attrs ("SDL_SCANCODE" , all_names )
517- )
483+ f .write ("%s\n _REVERSE_SCANCODE_TABLE = %s\n " % parse_sdl_attrs ("SDL_SCANCODE" , all_names ))
518484
519485 f .write ("\n # --- SDL keyboard symbols ---\n " )
520- f .write (
521- "%s\n _REVERSE_SYM_TABLE = %s\n "
522- % parse_sdl_attrs ("SDLK" , all_names )
523- )
486+ f .write ("%s\n _REVERSE_SYM_TABLE = %s\n " % parse_sdl_attrs ("SDLK" , all_names ))
524487
525488 f .write ("\n # --- SDL keyboard modifiers ---\n " )
526- f .write (
527- "%s\n _REVERSE_MOD_TABLE = %s\n "
528- % parse_sdl_attrs ("KMOD" , all_names )
529- )
489+ f .write ("%s\n _REVERSE_MOD_TABLE = %s\n " % parse_sdl_attrs ("KMOD" , all_names ))
530490
531491 f .write ("\n # --- SDL wheel ---\n " )
532- f .write (
533- "%s\n _REVERSE_WHEEL_TABLE = %s\n "
534- % parse_sdl_attrs ("SDL_MOUSEWHEEL" , all_names )
535- )
492+ f .write ("%s\n _REVERSE_WHEEL_TABLE = %s\n " % parse_sdl_attrs ("SDL_MOUSEWHEEL" , all_names ))
536493 all_names = ",\n " .join ('"%s"' % name for name in all_names )
537494 f .write ("\n __all__ = [\n %s,\n ]\n " % (all_names ,))
538495
0 commit comments