@@ -40,7 +40,7 @@ def SDL_PLATFORM_SPECIFIC(system: list[str] = None, arch: list[str] = None) -> b
4040__module__ : types .ModuleType = sys .modules [__name__ .split ("." )[0 ] if "." in __name__ else __name__ ]
4141
4242def SDL_FIND_BINARIES (libraries : list [str ]) -> list [str ]:
43- """Find binaries of system libraries."""
43+ """Search for binaries in system libraries."""
4444 libraries = libraries + [f"{ library } d" for library in libraries ]
4545 binaries = [f"./{ file } " if SDL_SYSTEM in ["Windows" ] and not ("/" in file or "\\ " in file ) else file for library in libraries if (file := ctypes .util .find_library (library ))]
4646
@@ -49,7 +49,7 @@ def SDL_FIND_BINARIES(libraries: list[str]) -> list[str]:
4949
5050 return binaries
5151
52- def SDL_DOWNLOAD_BINARIES (path : str , system : str = SDL_SYSTEM , arch : str = SDL_ARCH ) -> None :
52+ def SDL_DOWNLOAD_BINARIES (path : str , system : str = SDL_SYSTEM , arch : str = SDL_ARCH ) -> bool :
5353 """Download specific SDL3 binaries to the given path."""
5454 assert system .capitalize () in ["Darwin" , "Linux" , "Windows" ], "Unknown system."
5555 assert arch .upper () in ["AMD64" , "ARM64" ], "Unknown architecture."
@@ -61,7 +61,11 @@ def SDL_DOWNLOAD_BINARIES(path: str, system: str = SDL_SYSTEM, arch: str = SDL_A
6161 headers ["Authorization" ] = f"Bearer { os .environ ['SDL_GITHUB_TOKEN' ]} "
6262
6363 try :
64- for release in requests .get ("https://api.github.com/repos/Aermoss/PySDL3-Build/releases" , headers = headers ).json ():
64+ for release in (_ := requests .get ("https://api.github.com/repos/Aermoss/PySDL3-Build/releases" , headers = headers ).json ()):
65+ if isinstance (release , str ):
66+ print ("\33 [31m" , f"error: failed to download binaries: { _ [release ].lower ()} " , "\33 [0m" , sep = "" , flush = True )
67+ return False
68+
6569 if release ["draft" ] or release ["prerelease" ]:
6670 continue
6771
@@ -101,10 +105,14 @@ def SDL_DOWNLOAD_BINARIES(path: str, system: str = SDL_SYSTEM, arch: str = SDL_A
101105 json .dump (data , file , indent = 4 )
102106
103107 os .remove (os .path .join (path , asset ["name" ]))
104- return
105-
108+ return True
109+
110+ print ("\33 [31m" , "error: failed to download binaries: no binaries found." , "\33 [0m" , sep = "" , flush = True )
111+ return False
112+
106113 except requests .RequestException as exc :
107- print ("\33 [31m" , f"error: failed to download binaries: { str (exc ).lower ()} " , "\33 [0m" , sep = "" , flush = True )
114+ print ("\33 [31m" , f"error: failed to download binaries: { str (exc ).lower ()} ." , "\33 [0m" , sep = "" , flush = True )
115+ return False
108116
109117if not __initialized__ :
110118 if int (os .environ .get ("SDL_CHECK_VERSION" , str (int (not __frozen__ )))) > 0 :
@@ -155,11 +163,10 @@ def SDL_DOWNLOAD_BINARIES(path: str, system: str = SDL_SYSTEM, arch: str = SDL_A
155163 missing = True
156164
157165 if int (os .environ .get ("SDL_DOWNLOAD_BINARIES" , str (int (binaryData .get ("repair" , True ))))) > 0 and missing :
158- SDL_DOWNLOAD_BINARIES (binaryPath , SDL_SYSTEM , SDL_ARCH )
159-
160- with open (os .path .join (binaryPath , "metadata.json" ), "r" ) as file :
161- binaryData , missing = json .load (file ), None
162- binaryData ["files" ] = [absPath (i ) for i in binaryData ["files" ]]
166+ if _ := SDL_DOWNLOAD_BINARIES (binaryPath , SDL_SYSTEM , SDL_ARCH ):
167+ with open (os .path .join (binaryPath , "metadata.json" ), "r" ) as file :
168+ binaryData , missing = json .load (file ), None
169+ binaryData ["files" ] = [absPath (i ) for i in binaryData ["files" ]]
163170
164171 if int (os .environ .get ("SDL_FIND_BINARIES" , str (int (binaryData .get ("find" , missing is None ))))) > 0 :
165172 binaryData ["files" ] += SDL_FIND_BINARIES (list (SDL_BINARY_VAR_MAP_INV .keys ()))
@@ -361,30 +368,23 @@ async def SDL_GET_FUNC_DESCRIPTIONS(funcs: list[tuple[str, str]], rst: bool = Fa
361368
362369 for module , func in funcs :
363370 url = f"https://wiki.libsdl.org/{ module } /{ func } "
364- print ("\33 [32m" , f"info: sending a request to '{ url } '." , "\33 [0m" , sep = "" , flush = True )
371+ # print("\33[32m", f"info: sending a request to '{url}'.", "\33[0m", sep = "", flush = True)
365372 tasks .append (asyncio .create_task (session .get (url , ssl = False )))
366373
367374 responses = await asyncio .gather (* tasks )
368- print ("\33 [32m" , f"info: response gathering completed ({ len (responses )} response(s))." , "\33 [0m" , sep = "" , flush = True )
375+ # print("\33[32m", f"info: response gathering completed ({len(responses)} response(s)).", "\33[0m", sep = "", flush = True)
369376 descriptions , arguments , returns = [], [], []
370377
371378 for response in responses :
372379 if response .status != 200 :
373- print ("\33 [35m" , f"warning: failed to get description of '{ response .url } ', skipping (status: { response .status } )." , "\33 [0m" , sep = "" , flush = True )
380+ print ("\33 [35m" , f"warning: no such page: '{ response .url } ', skipping (status: { response .status } )." , "\33 [0m" , sep = "" , flush = True )
374381 descriptions .append (None )
375382 arguments .append (None )
376383 returns .append (None )
377384
378385 else :
379386 content = (await response .content .read ()).decode ()
380387
381- if "no such page" in content .lower ():
382- print ("\33 [35m" , f"warning: no such page found for '{ response .url } ', skipping." , "\33 [0m" , sep = "" , flush = True )
383- descriptions .append (None )
384- arguments .append (None )
385- returns .append (None )
386- continue
387-
388388 for a , b in zip (list (re .finditer (r"<p>" , content )), list (re .finditer (r"</p>" , content ))):
389389 if content [a .end ()] == "<" :
390390 continue
@@ -477,18 +477,18 @@ def SDL_PYTHONIZE_TYPE(type: type, name: str | None = None) -> str:
477477 for _index , func in enumerate (__module__ .functions [module ]):
478478 if (_ := __module__ .functions [module ][func ]).__name__ == "__inner__" : _ = _ .func
479479 vararg , restype , argtypes , (description , arguments , _return ) = _ .vararg , _ .restype , _ .argtypes , _ .__doc__
480- assert arguments is None or len (arguments ) == len (argtypes ), f"argument count mismatch for 'https://wiki.libsdl.org/{ module } /{ func } '."
480+ assert arguments is None or len (arguments ) == len (argtypes ), f"argument count mismatch for 'https://wiki.libsdl.org/{ module } /{ func } ' (expected: { len ( arguments ) } , got: { len ( argtypes ) } ) ."
481481
482482 if arguments is None :
483483 arguments = [f"_{ i } " for i in range (len (argtypes ))]
484484
485485 else :
486486 for __index , i in enumerate (arguments ):
487- assert SDL_PYTHONIZE_TYPE (arguments [i ], i ) == SDL_GET_NAME (argtypes [__index ]), f"argument type mismatch for 'https://wiki.libsdl.org/{ module } /{ func } '."
487+ assert SDL_PYTHONIZE_TYPE (arguments [i ], i ) == SDL_GET_NAME (argtypes [__index ]), f"argument type mismatch for 'https://wiki.libsdl.org/{ module } /{ func } ' (argument: { i } , expected: { SDL_PYTHONIZE_TYPE ( arguments [ i ], i ) } , got: { SDL_GET_NAME ( argtypes [ __index ]) } ) ."
488488
489489 arguments = [f"{ '_' if i in keyword .kwlist else '' } { i .replace ('[' , '' ).replace (']' , '' )} " for i in arguments ]
490490
491- assert _return is None or SDL_PYTHONIZE_TYPE (_return ) == SDL_GET_NAME (restype ), f"return type mismatch for 'https://wiki.libsdl.org/{ module } /{ func } '."
491+ assert _return is None or SDL_PYTHONIZE_TYPE (_return ) == SDL_GET_NAME (restype ), f"return type mismatch for 'https://wiki.libsdl.org/{ module } /{ func } ' (expected: { SDL_PYTHONIZE_TYPE ( _return ) } , got: { SDL_GET_NAME ( restype ) } ) ."
492492 definitions += f"def { func } ({ ', ' .join ([f'{ arg } : { SDL_GET_NAME (type )} ' for arg , type in zip (arguments , argtypes )] + (['*args: list[typing.Any]' ] if vararg else []))} ) -> { SDL_GET_NAME (restype )} :\n "
493493 if not rst or description is not None : definitions += f"{ ' ' * 4 } \" \" \" \n "
494494 if description is not None : definitions += f" { description } \n "
@@ -518,7 +518,11 @@ def SDL_GET_OR_GENERATE_DOCS() -> bytes:
518518 if "SDL_GITHUB_TOKEN" in os .environ :
519519 headers ["Authorization" ] = f"Bearer { os .environ ['SDL_GITHUB_TOKEN' ]} "
520520
521- for release in requests .get (f"https://api.github.com/repos/Aermoss/PySDL3/releases" , headers = headers ).json ():
521+ for release in (_ := requests .get (f"https://api.github.com/repos/Aermoss/PySDL3/releases" , headers = headers ).json ()):
522+ if isinstance (release , str ):
523+ print ("\33 [31m" , f"error: failed to get docs from github: { _ [release ].lower ()} " , "\33 [0m" , sep = "" , flush = True )
524+ break
525+
522526 if release ["tag_name" ] != f"v{ __version__ } " :
523527 continue
524528
@@ -529,10 +533,11 @@ def SDL_GET_OR_GENERATE_DOCS() -> bytes:
529533 with requests .get (asset ["browser_download_url" ], headers = headers , stream = True ) as response :
530534 assert response .status_code == 200 , f"failed to get docs from github, status: { response .status_code } ."
531535 return bytearray ().join ([chunk for chunk in response .iter_content (chunk_size = 8192 ) if chunk ])
532-
536+
533537 except requests .RequestException as exc :
534538 print ("\33 [31m" , f"error: failed to get docs from github: { str (exc ).lower ()} ." , "\33 [0m" , sep = "" , flush = True )
535539
540+ print ("\33 [35m" , "warning: generating docs, you can ignore the folowing warnings..." , "\33 [0m" , sep = "" , flush = True )
536541 return SDL_GENERATE_DOCS ().encode ("utf-8" )
537542
538543if not __initialized__ and int (os .environ .get ("SDL_CTYPES_ALIAS_FIX" , os .environ .get ("SDL_DEBUG" , "0" ))) > 0 :
@@ -570,7 +575,7 @@ def SDL_TRY_WRITE_DOCS() -> bool | None:
570575
571576 if os .path .exists (__doc_file__ ) and (not data or data ["meta" ]["target" ] != f"v{ __version__ } " or data ["meta" ]["system" ] != SDL_SYSTEM ) and SDL_TRY_WRITE_DOCS ():
572577 del sys .modules ["sdl3.__doc__" ]
573- print ("\33 [35m" , f"warning: reloading module: 'sdl3.__doc__'." , "\33 [0m" , sep = "" , flush = True )
578+ print ("\33 [35m" , f"warning: reloading module: 'sdl3.__doc__'... " , "\33 [0m" , sep = "" , flush = True )
574579 from .__doc__ import *
575580
576581 else :
0 commit comments