Created
March 2, 2025 16:37
-
-
Save ayufan/494775584ec3c7d5a51be5158b759fc8 to your computer and use it in GitHub Desktop.
Klipper Loader to allow extras out of box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import fnmatch | |
import klippy | |
klippy_path = os.path.dirname(klippy.__file__) | |
matching_path = os.path.join(klippy_path, 'extras', '*.py') | |
org_exists = os.path.exists | |
def new_os_path_exists(path): | |
if org_exists(path): | |
return True | |
if fnmatch.fnmatch(path, matching_path): | |
module_path = os.path.relpath(path, klippy_path) | |
for sys_path in sys.path: | |
if sys_path == klippy_path: | |
break | |
if org_exists(os.path.join(sys_path, module_path)): | |
return True | |
return False | |
os.path.exists = new_os_path_exists | |
if __name__ == '__main__': | |
klippy.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run:
When using
[hello_world]
it will look for module in a following order:/path/to/dir/with/modules/extras/hello_world.py
/path/to/dir/with/modules/extras/hello_world/__init__.py
/path/to/klipper/klippy/extras/hello_world.py
/path/to/klipper/klippy/extras/hello_world/__init__.py
It will start Klipper from
/path/to/klipper/klippy/klippy.py
folder.