Skip to content

Commit

Permalink
Append /usr/local/lib to sys.path if import fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Dec 30, 2024
1 parent b4852f1 commit 2fd4b7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions bin/input-remapper-control
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@

"""Control the dbus service from the command line."""

import os
import sys


def fix_import_path():
# Installations via `sudo python3 setup.py install` install into /usr/local/lib
# instead of /usr/local. sys.path is missing /usr/local/lib when udev is running
# its rules.
try:
import inputremapper
except ModuleNotFoundError:
python_folder = f"python{sys.version_info.major}.{sys.version_info.minor}"
usr_local_lib = f"/usr/local/lib/{python_folder}/dist-packages"
if not os.path.exists(usr_local_lib):
return

print(f'Appending "{usr_local_lib}" to sys.path')
sys.path.append(usr_local_lib)


fix_import_path()


from inputremapper.bin.input_remapper_control import InputRemapperControlBin

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion inputremapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def refresh(self):
self.loads(pipe[0].recv())

if len(self._groups) == 0:
logger.debug("Did not find any input device")
logger.error("Did not find any input device")
else:
keys = [f'"{group.key}"' for group in self._groups]
logger.info("Found %s", ", ".join(keys))
Expand Down

0 comments on commit 2fd4b7c

Please sign in to comment.