From cfd09c48705bc33c6f98e5fecbfbd1552baa7ff6 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 | 33 ++++++++++++++++++++++++--------- setup.py | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/keymapper/data.py b/keymapper/data.py index c84fad29..f846ff22 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,24 @@ 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' + + candidates = [ + os.path.join(site.USER_BASE, 'share/key-mapper'), + '/usr/local/share/key-mapper', + '/usr/share/key-mapper', + os.path.join(source_path, 'data') + ] + + if '/site-packages' not in source_path: + print('shitcrap', source_path) + # probably installed with -e, running from the cloned git source + data_path = candidates[3] else: - # installed with -e, running from the cloned git source - data_path = os.path.join(source_path, 'data') + # 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']), ],