Skip to content

Conversation

@lopsided98
Copy link
Contributor

@lopsided98 lopsided98 commented Jul 16, 2021

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

`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.
@mikepurvis
Copy link
Member

mikepurvis commented Jul 16, 2021

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
Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix and the link the the python-poppler-qt5 example. Mind opening a PR wit the fixes you'd like to see in ROS 2 on the main branch?

@sloretz sloretz merged commit 7095b4d into ros-visualization:melodic-devel Jul 21, 2021
@lopsided98 lopsided98 deleted the patch-1 branch July 22, 2021 00:05
lopsided98 added a commit to lopsided98/python_qt_binding that referenced this pull request Jul 22, 2021
`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.
clalancette pushed a commit to lopsided98/python_qt_binding that referenced this pull request Nov 19, 2021
`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.
clalancette pushed a commit that referenced this pull request Nov 19, 2021
* Use PyQt5 module path to find SIP bindings (#105)

`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.

Co-authored-by: Akash Patel <17132214+acxz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants