From 6c2160ff4e99c00eb3b957304375231a4a64a591 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Thu, 3 Dec 2020 18:29:46 +0100 Subject: [PATCH] possibly fixed the data path --- keymapper/data.py | 32 +++++++++++++++++++++++--------- setup.py | 1 + 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/keymapper/data.py b/keymapper/data.py index c84fad29..84d1173e 100644 --- a/keymapper/data.py +++ b/keymapper/data.py @@ -31,7 +31,12 @@ from keymapper.logger import logger def get_data_path(filename=''): - """Depending on the installation prefix, return the data dir.""" + """Depending on the installation prefix, return the data dir. + + Since it is a nightmare to get stuff installed with pip across + distros this is somewhat complicated. Ubuntu wants to use /usr/local + for data_files, but not everything can be placed there. + """ try: source_path = pkg_resources.require('key-mapper')[0].location except pkg_resources.DistributionNotFound as error: @@ -46,14 +51,23 @@ def get_data_path(filename=''): # depending on where this file is installed to, make sure to use the proper # prefix path for data # https://docs.python.org/3/distutils/setupscript.html?highlight=package_data#installing-additional-files # noqa pylint: disable=line-too-long - if source_path.startswith(site.USER_BASE): - data_path = os.path.join(site.USER_BASE, 'share/key-mapper') - elif source_path.startswith('/usr/local/'): - data_path = '/usr/local/share/key-mapper' - elif source_path.startswith('/usr/'): - data_path = '/usr/share/key-mapper' - else: - # installed with -e, running from the cloned git source + + candidates = [ + os.path.join(site.USER_BASE, 'share/key-mapper'), + '/usr/local/share/key-mapper', + '/usr/share/key-mapper' + ] + + print('source_path', source_path) + if '/site-packages' not in source_path: + # probably installed with -e, running from the cloned git source data_path = os.path.join(source_path, 'data') + else: + # try any of the options + for candidate in candidates: + if os.path.exists(candidate): + data_path = candidate + break + logger.error('Could not find the application data') return os.path.join(data_path, filename) diff --git a/setup.py b/setup.py index 03baeb7f..49bee486 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ setup( ('/usr/share/key-mapper/', glob.glob('data/*')), ('/usr/share/applications/', ['data/key-mapper.desktop']), ('/etc/xdg/autostart/', ['data/key-mapper-service.desktop']), + # manjaro installs the executables with pip, ubuntu doesn't. ('/usr/bin/', ['bin/key-mapper-gtk']), ('/usr/bin/', ['bin/key-mapper-service']), ],