Skip to content

Commit cf9eda7

Browse files
committed
Check and sort imports automatically.
Why not?
1 parent 6cc2e80 commit cf9eda7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

sdl3/SDL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
from .SDL_loadso import *
2828
from .SDL_locale import *
2929
from .SDL_log import *
30-
from .SDL_main_impl import *
3130
from .SDL_main import *
31+
from .SDL_main_impl import *
3232
from .SDL_messagebox import *
3333
from .SDL_metal import *
3434
from .SDL_misc import *

sdl3/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ def SDL_GET_OR_GENERATE_DOCS() -> bytes:
324324

325325
return SDL_GENERATE_DOCS().encode("utf-8")
326326

327+
if not __initialized__ and int(os.environ.get("SDL_CHECK_IMPORTS", "0")) > 0:
328+
existingModules = [i[:-3] for i in sorted(os.listdir(os.path.dirname(__file__))) if i.startswith("SDL_") and i.endswith(".py")]
329+
330+
with open(os.path.join(os.path.dirname(__file__), "SDL.py"), "r") as file:
331+
importedModules = [i.replace("\n", "")[6:-9] for i in file.readlines() if i.startswith("from .") and "import *" in i]
332+
333+
for index, module in enumerate(existingModules):
334+
if len(importedModules) <= index or module != importedModules[index]:
335+
print("\33[35m", f"regenerating main module.", "\33[0m", sep = "", flush = True)
336+
337+
with open(os.path.join(os.path.dirname(__file__), "SDL.py"), "w") as file:
338+
file.write("\n".join([f"from .{i} import *" for i in existingModules]))
339+
break
340+
327341
from sdl3.SDL import *
328342

329343
SDL_VERSIONNUM_STRING = lambda num: \

0 commit comments

Comments
 (0)