ros-visualization / python_qt_binding

http://wiki.ros.org/python_qt_binding
BSD 3-Clause "New" or "Revised" License
34 stars 54 forks source link

Use PyQt5 module path to find SIP bindings #105

Closed lopsided98 closed 3 years ago

lopsided98 commented 3 years ago

sipconfig._pkg_config['default_mod_dir'] is currently used to find the PyQt5 SIP bindings, but this location is determined by where SIP is installed, which may not be the same as where PyQt5 is installed. A real world example of this is in Nix, where each package is installed to a separate isolated directory. Instead, we can use PyQt5.__path__[0], which will always point to the location of the PyQt5 module. This approach was based on python-poppler-qt5.

I made this PR against melodic-devel because it includes #95. I would appreciate it if both #95 and this PR could be included in a ROS2 release at some point.

cc @mikepurvis

mikepurvis commented 3 years ago

This is what the generated Nix sipconfig.py looks like for me:

_pkg_config = {
    'android_abi':        '',
    'arch':               '',
    'default_bin_dir':    '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/bin',
    'default_mod_dir':    '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/lib/python3.8/site-packages',
    'default_sip_dir':    '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/share/sip',
    'deployment_target':  '',
    'platform':           'linux-g++',
    'py_conf_inc_dir':    '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/include/python3.8',
    'py_inc_dir':         '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/include/python3.8',
    'py_lib_dir':         '/nix/store/6cfajs6lsy9b4wxp3jvyyl1g5x2pjmpr-python3-3.8.9/lib/python3.8/config',
    'py_version':         0x030809,
    'qt_framework':       0,
    'sip_bin':            '/nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/bin/sip',
    'sip_config_args':    '--sip-module sip -d /nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/lib/python3.8/site-packages -b /nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/bin -e /nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/include',
    'sip_inc_dir':        '/nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/include',
    'sip_module_dir':     '/nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/lib/python3.8/site-packages',
    'sip_root_dir':       '/nix/store/clr06cdrd3gfn35aas9hbq5nq0laf9hm-python3.8-sip-4.19.25/lib/python3.8/site-packages',
    'sip_version':        0x041319,
    'sip_version_str':    '4.19.25',
    'universal':          ''
}

So another possible option here could be to change it from sipconfig._pkg_config['default_mod_dir'] to sipconfig._pkg_config['sip_module_dir'], which doesn't require a build-time import (if that matters? maybe for cross-compiling?) and may be a bit more in the spirit of the original design here.

Not sure which of these is a better fit for platforms that are on SIP 5 (Arch) and SIP 6 (NixOS default), though.


For comparison, this is what it looks like on Ubuntu Focal:

_pkg_config = {
    'arch':               '',
    'default_bin_dir':    '/usr/bin',
    'default_mod_dir':    '/usr/lib/python3/dist-packages',
    'default_sip_dir':    '/usr/share/sip',
    'deployment_target':  '',
    'platform':           'linux-g++',
    'py_conf_inc_dir':    '/usr/include/python3.8',
    'py_inc_dir':         '/usr/include/python3.8',
    'py_lib_dir':         '/usr/lib/python3.8/config',
    'py_version':         0x030802,
    'qt_framework':       0,
    'sip_bin':            '/usr/bin/sip',
    'sip_config_args':    '--destdir /usr/lib/python3/dist-packages --debug CFLAGS=-g -O2 -ffile-prefix-map=/build/sip4-Bb7aBW/sip4-4.19.21+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 CXXFLAGS=-g -O2 -ffile-prefix-map=/build/sip4-Bb7aBW/sip4-4.19.21+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 LFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro',
    'sip_inc_dir':        '/usr/include/python3.8',
    'sip_module_dir':     '/usr/lib/python3/dist-packages',
    'sip_root_dir':       '/usr/lib/python3/dist-packages',
    'sip_version':        0x041315,
    'sip_version_str':    '4.19.21',
    'universal':          ''
}
lopsided98 commented 3 years ago

Neither default_mod_dir or sip_module_dir are correct for Nix. The correct directory is within the PyQt5 package.

Arch Linux uses SIP 6 as well now.

mikepurvis commented 3 years ago

So you're right; I agree then that PyQt5.__path__[0] is the best choice here.