diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8dfbc31f..4a828c26 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,11 +10,13 @@ jobs: matrix: python-version: ["3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: setup.py - name: Install dependencies run: | scripts/ci-install-deps.sh diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 8bc0b28d..f59d0484 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -13,12 +13,14 @@ jobs: python-version: ["3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: setup.py - uses: reviewdog/action-setup@master with: reviewdog_version: latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3825660a..d43023e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,11 +11,14 @@ jobs: matrix: python-version: ["3.7", "3.11"] # min and max supported versions? steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + # broken "Error: Cache folder path is retrieved for pip but doesn't exist on disk: /home/runner/.cache/pip" + # cache: 'pip' + # cache-dependency-path: setup.py - name: Install dependencies run: | # Install deps as root since we will run tests as root @@ -25,4 +28,10 @@ jobs: run: | # FIXME: Had some permissions issues, currently worked around by running tests as root mkdir test_tmp - TMPDIR="$(realpath test_tmp)" sudo python tests/test.py --start-dir unit + export TMPDIR="$(realpath test_tmp)" + + export DATA_DIR="/home/runner/work/input-remapper/input-remapper/data/" + # try this if input-remappers data cannot be found, and set DATA_DIR to a matching directory + # find / -type f -name "input-remapper.glade" + + sudo -E python tests/test.py --start-dir unit diff --git a/inputremapper/configs/data.py b/inputremapper/configs/data.py index 49afbee9..7635d251 100644 --- a/inputremapper/configs/data.py +++ b/inputremapper/configs/data.py @@ -33,20 +33,23 @@ logged = False def _try_standard_locations(): - """Look for the data dir where it typically can be found.""" - candidates = [ - "/usr/share/input-remapper", - "/usr/local/share/input-remapper", - os.path.join(site.USER_BASE, "share/input-remapper"), - ] - - # try any of the options - for candidate in candidates: + # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html + # ensure at least /usr/local/share/ and /usr/share/ are tried + xdg_data_dirs = set( + os.environ.get("XDG_DATA_DIRS", "").split(":") + + [ + "/usr/local/share/", + "/usr/share/", + os.path.join(site.USER_BASE, "share/"), + ] + ) + + for xdg_data_dir in xdg_data_dirs: + candidate = os.path.join(xdg_data_dir, "input-remapper") if os.path.exists(candidate): - data = candidate - break + return candidate - return data + return None def _try_python_package_location(): @@ -55,8 +58,8 @@ def _try_python_package_location(): try: source = pkg_resources.require("input-remapper")[0].location # failed in some ubuntu installations - except pkg_resources.DistributionNotFound: - logger.debug("DistributionNotFound") + except Exception: + logger.debug("failed to figure out package location") pass data = None @@ -73,6 +76,21 @@ def _try_python_package_location(): return data +def _try_env_data_dir(): + """Check if input-remappers data can be found at DATA_DIR.""" + data_dir = os.environ.get("DATA_DIR", None) + + if data_dir is None: + return None + + if os.path.exists(data_dir): + return data_dir + else: + logger.error(f'"{ data_dir }" does not exist') + + return None + + def get_data_path(filename=""): """Depending on the installation prefix, return the data dir. @@ -86,7 +104,11 @@ def get_data_path(filename=""): # prefix path for data # https://docs.python.org/3/distutils/setupscript.html?highlight=package_data#installing-additional-files # noqa pylint: disable=line-too-long - data = _try_python_package_location() or _try_standard_locations() + data = ( + _try_env_data_dir() + or _try_python_package_location() + or _try_standard_locations() + ) if data is None: logger.error("Could not find the application data")