Allow imports of top level PyQt modules to work from the qt virtual module

This is needed for legacy compat of

from PyQt5 import QtCore, QtGui, etc
This commit is contained in:
Kovid Goyal
2022-01-01 09:43:05 +05:30
parent 924625e047
commit a78d3cd611
2 changed files with 23 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
# autogenerated by __main__.py do not edit
top_level_module_names=('QtCore', 'QtGui', 'QtWidgets', 'QtNetwork', 'QtSvg', 'QtPrintSupport', 'QtWebEngineCore', 'QtWebEngineWidgets')
def __getattr__(name):
if name in top_level_module_names:
import importlib
return importlib.import_module("PyQt6." + name)
raise AttributeError(name)
+13
View File
@@ -53,5 +53,18 @@ def scan(name):
print(')', file=f)
top_level_module_names = ()
for name in ('core', 'webengine'):
top_level_module_names += module_lists[name]
scan(name)
with open(f'{base}/__init__.py', 'w') as f:
print('# autogenerated by __main__.py do not edit', file=f)
print(f'{top_level_module_names=}', file=f)
print(f'''
def __getattr__(name):
if name in top_level_module_names:
import importlib
return importlib.import_module("{QT_WRAPPER}." + name)
raise AttributeError(name)
''', file=f)