Skip to content

Commit

Permalink
pyside6: ensure PySide6 can be imported and used
Browse files Browse the repository at this point in the history
The PySide6/__init__.py script is at runtime trying to find the
dependent Qt libraries in subdirectories of its path in the installed
site-packages directory. This fails because the dependent
pyside6-essentials and pyside6-addons packages aren't installed into the
same site-packages directory. As a work-around this commit symlinks
those files into the site-packages directory of the `pyside6` package.

This commit also adds a small application that imports
and verifies that PySide6 can be used after building.
  • Loading branch information
Viktor Kronvall committed Sep 16, 2024
1 parent f684558 commit f98eb8d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
40 changes: 27 additions & 13 deletions overrides/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ lib.composeManyExtensions [

msgspec = prev.msgspec.overridePythonAttrs (old: {
# crash during integer serialization - see https://github.com/jcrist/msgspec/issues/730
hardeningDisable = old.hardeningDisable or [] ++ [ "fortify" ];
hardeningDisable = old.hardeningDisable or [ ] ++ [ "fortify" ];
});

munch = prev.munch.overridePythonAttrs (
Expand Down Expand Up @@ -2746,7 +2746,7 @@ lib.composeManyExtensions [
pyqt6;

pyqt6-qt6 = prev.pyqt6-qt6.overridePythonAttrs (old: {
autoPatchelfIgnoreMissingDeps = [ "libmysqlclient.so.21" "libmimerapi.so" "libQt6*" ];
autoPatchelfIgnoreMissingDeps = [ "libmysqlclient.so.21" "libmimerapi.so" ];
preFixup = ''
addAutoPatchelfSearchPath $out/${final.python.sitePackages}/PyQt6/Qt6/lib
'';
Expand Down Expand Up @@ -2774,15 +2774,12 @@ lib.composeManyExtensions [
});

pyside6-essentials = prev.pyside6-essentials.overridePythonAttrs (old: lib.optionalAttrs stdenv.isLinux {
autoPatchelfIgnoreMissingDeps = [ "libmysqlclient.so.21" "libmimerapi.so" "libQt6*" ];
autoPatchelfIgnoreMissingDeps = [ "libmysqlclient.so.21" "libmimerapi.so" "libQt6EglFsKmsGbmSupport.so*" ];
preFixup = ''
addAutoPatchelfSearchPath $out/${final.python.sitePackages}/PySide6
addAutoPatchelfSearchPath ${final.shiboken6}/${final.python.sitePackages}/shiboken6
'';
postInstall = ''
rm -r $out/${final.python.sitePackages}/PySide6/__pycache__
'';
propagatedBuildInputs = old.propagatedBuildInputs or [ ] ++ [
pkgs.qt6.full
pkgs.libxkbcommon
pkgs.gtk3
pkgs.speechd
Expand All @@ -2802,30 +2799,47 @@ lib.composeManyExtensions [
pkgs.xorg.xcbutilwm
pkgs.libdrm
pkgs.pulseaudio
final.shiboken6
];
pythonImportsCheck = [
"PySide6"
"PySide6.QtCore"
];
postInstall = ''
python -c 'import PySide6; print(PySide6.__all__)'
'';
});

pyside6-addons = prev.pyside6-addons.overridePythonAttrs (old: lib.optionalAttrs stdenv.isLinux {
autoPatchelfIgnoreMissingDeps = [
"libmysqlclient.so.21"
"libmimerapi.so"
"libQt6Quick3DSpatialAudio.so.6"
"libQt6Quick3DHelpersImpl.so.6"
];
preFixup = ''
addAutoPatchelfSearchPath ${final.shiboken6}/${final.python.sitePackages}/shiboken6
addAutoPatchelfSearchPath ${final.pyside6-essentials}/${final.python.sitePackages}/PySide6
addAutoPatchelfSearchPath $out/${final.python.sitePackages}/PySide6
'';
propagatedBuildInputs = old.propagatedBuildInputs or [ ] ++ [
buildInputs = [
pkgs.nss
pkgs.xorg.libXtst
pkgs.alsa-lib
pkgs.xorg.libxshmfence
pkgs.xorg.libxkbfile
];
postInstall = ''
rm -r $out/${final.python.sitePackages}/PySide6/__pycache__
});
pyside6 = prev.pyside6.overridePythonAttrs (old: {
# The PySide6/__init__.py script tries to find the Qt libraries
# relative to its own path in the installed site-packages directory.
# This then fails to find the paths from pyside6-essentials and
# pyside6-addons because they are installed into different directories.
#
# To work around this issue we symlink all of the files resulting from
# those packages into the aggregated `pyside6` output directories.
#
# See https://github.com/nix-community/poetry2nix/issues/1791 for more details.
postFixup = ''
${pkgs.xorg.lndir}/bin/lndir ${final.pyside6-essentials}/${final.python.sitePackages}/PySide6 $out/${final.python.sitePackages}/PySide6
${pkgs.xorg.lndir}/bin/lndir ${final.pyside6-addons}/${final.python.sitePackages}/PySide6 $out/${final.python.sitePackages}/PySide6
'';
});

Expand Down
29 changes: 22 additions & 7 deletions tests/pyside6/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
{ lib, poetry2nix, python310 }:

poetry2nix.mkPoetryApplication {
python = python310;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
src = lib.cleanSource ./.;
{ lib, poetry2nix, python310, runCommand, gnugrep }:
let
app = poetry2nix.mkPoetryApplication {
python = python310;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
src = lib.cleanSource ./.;
pythonImportsCheck = [
"test_pyside6"
];
};
in
(runCommand "test-pyside6"
{
nativeBuildInputs = [ gnugrep ];
} ''
set -euo pipefail
${app}/bin/test_pyside6 > $out
grep QPoint < $out
grep Success < $out
'') // {
inherit (app.python.pkgs) pyside6-addons pyside6-essentials;
}
4 changes: 4 additions & 0 deletions tests/pyside6/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "test_pyside6"
version = "0.1.0"
description = ""
authors = ["considerate <[email protected]>"]
packages = [{include = "test_pyside6", from = "."}]

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
Expand All @@ -11,6 +12,9 @@ pyside6 = "<6.5.3"

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
test_pyside6 = "test_pyside6:main"

[build-system]
requires = ["poetry-core>=1"]
build-backend = "poetry.core.masonry.api"
Empty file removed tests/pyside6/test_pyside6.py
Empty file.
11 changes: 11 additions & 0 deletions tests/pyside6/test_pyside6/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from PySide6.QtCore import QPoint
import sys


def main():
print(QPoint(2.5,6.0))

print("Success")

if __name__ == '__main__':
main()

0 comments on commit f98eb8d

Please sign in to comment.