Skip to content

Commit d001cde

Browse files
authored
fix windows dll directories (#11)
* use inner module * update test
1 parent 2030582 commit d001cde

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

project.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
import os
22
from pathlib import Path
33

4-
from pyqtbuild import PyQtBindings, PyQtProject
4+
from pyqtbuild import PyQtBindings, PyQtProject, QmakeBuilder
55

66

7+
class _Builder(QmakeBuilder):
8+
# small hack to make a custom __init__ file
9+
# not using Project.dunder_init... since that seems to affect PyQt6.__init__
10+
def install_project(self, target_dir, *, wheel_tag=None):
11+
super().install_project(target_dir, wheel_tag=wheel_tag)
12+
package = Path(target_dir, "PyQt6Ads")
13+
if os.name != "nt":
14+
contents = "from ._ads import *\n"
15+
else:
16+
contents = """
17+
try:
18+
import PyQt6 # force addition of Qt6/bin to dll_directories
19+
except ImportError:
20+
raise ImportError("PyQt6 must be installed in order to use PyQt6Ads.") from None
21+
22+
from ._ads import *
23+
del PyQt6
24+
"""
25+
(package / "__init__.py").write_text(contents)
26+
27+
# rename _ads.pyi to __init__.pyi
28+
(package / "_ads.pyi").rename(package / "__init__.pyi")
29+
(package / "py.typed").touch()
30+
731
class PyQt6Ads(PyQtProject):
832
def __init__(self):
933
super().__init__()
34+
self.builder_factory = _Builder
1035
self.bindings_factories = [PyQt6Adsmod]
1136
self.verbose = bool(os.getenv("CI") or os.getenv("CIBUILDWHEEL"))
1237

scripts/repair_wheel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main() -> None:
3737
RPATH_RE_MAC = re.compile(r"^\s*path (.+) \(offset \d+\)$", re.MULTILINE)
3838

3939

40-
def fix_rpath_macos(so: Path, new_rpath: str = "@loader_path/PyQt6/Qt6/lib") -> None:
40+
def fix_rpath_macos(so: Path, new_rpath: str = "@loader_path/../PyQt6/Qt6/lib") -> None:
4141
# delete all current rpaths
4242
current_rpath = run(["otool", "-l", str(so)], capture_output=True, text=True)
4343
for rpath in RPATH_RE_MAC.findall(current_rpath.stdout):
@@ -48,7 +48,7 @@ def fix_rpath_macos(so: Path, new_rpath: str = "@loader_path/PyQt6/Qt6/lib") ->
4848
print(f"Updated RPATH for {so} to {new_rpath}")
4949

5050

51-
def fix_rpath_linux(so: Path, new_rpath: str = "$ORIGIN/PyQt6/Qt6/lib") -> None:
51+
def fix_rpath_linux(so: Path, new_rpath: str = "$ORIGIN/../PyQt6/Qt6/lib") -> None:
5252
# delete all current rpaths
5353
current_rpath = run(
5454
["patchelf", "--print-rpath", str(so)], capture_output=True, text=True

sip/PyQt6Ads.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%Module(name=PyQt6Ads, call_super_init=True, keyword_arguments="Optional", use_limited_api=True)
1+
%Module(name=PyQt6Ads._ads, call_super_init=True, keyword_arguments="Optional", use_limited_api=True)
22
%HideNamespace(name=ads)
33

44
%Import QtCore/QtCoremod.sip

tests/test_examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from unittest.mock import patch
44

5+
import PyQt6Ads # noqa # import here to ensure that it works regardless of order
56
import pytest
67
from PyQt6.QtWidgets import QApplication
78

0 commit comments

Comments
 (0)