diff options
author | Christian Tismer <tismer@stackless.com> | 2022-03-30 16:37:08 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2022-04-01 08:25:04 +0200 |
commit | 4c0b1be1e2136b4c0c1f348cc1b80aeb9b179a11 (patch) | |
tree | e7e03b54d14c8720b04d0e1a78db5948a5a7303d | |
parent | 424620e72b2e0e9d71e178fe9a453583c8b5c59a (diff) |
setup: fix PySide6.__all__ after the wheel split
The __all__ variable can no longer reliably be generated
during compile time.
- look into the FS to get a list of available modules
- apply the existing __all__ order for convenience
- make sure to call this function outside of a build, only.
Change-Id: Ibaf300447e86127e39a98a9150b7e8b4d8ced27d
Pick-to: 6.2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | sources/pyside6/PySide6/__init__.py.in | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/__init__.py.in b/sources/pyside6/PySide6/__init__.py.in index 2631c346c..d8439985d 100644 --- a/sources/pyside6/PySide6/__init__.py.in +++ b/sources/pyside6/PySide6/__init__.py.in @@ -3,6 +3,7 @@ import sys from pathlib import Path from textwrap import dedent +# __all__ is also corrected below. __all__ = list("Qt" + body for body in "@all_module_shortnames@" .split(";")) @@ -111,4 +112,32 @@ def _setupQtDirectories(): finally: os.environ['PATH'] = path + +def _find_all_qt_modules(): + # Since the wheel split, the __all__ variable cannot be computed statically, + # because we don't know all modules in advance. + + # Instead, we look into the file system and quickly build a list of all + # existing .pyi files, because importing is not desired and also impossible during import. + # By using the initially created list, we can keep some order intact. + location = Path(__file__).resolve().parent + + # Note: We should _not_ call this function while still building, but use the existing value! + in_build = location.parents[1].name == "build" + if in_build: + return __all__ + + files = os.listdir(location) + unordered = set(name[:-4] for name in files if name.startswith("Qt") and name.endswith(".pyi")) + ordered_part = __all__ + result = [] + for name in ordered_part: + if name in unordered: + result.append(name) + unordered.remove(name) + result.extend(unordered) + return result + + +__all__ = _find_all_qt_modules() _setupQtDirectories() |