From 30e4c3bfe05c50f31132c68ea91577efd7642338 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 31 Oct 2023 18:57:46 +0000 Subject: [PATCH] plugins v1 and no more dirty --- .gitignore | 2 ++ klippy/klippy.py | 47 +++++++++++++++----------------------- klippy/plugins/__init__.py | 5 ++++ 3 files changed, 25 insertions(+), 29 deletions(-) create mode 100644 klippy/plugins/__init__.py diff --git a/.gitignore b/.gitignore index 2bc23f69f..a6bfa6ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ klippy/.version ci_build/ ci_cache/ _test_.* +klippy/plugins/* +!klippy/plugins/__init__.py \ No newline at end of file diff --git a/klippy/klippy.py b/klippy/klippy.py index 65c3ee527..55645894b 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -129,17 +129,30 @@ def load_object(self, config, section, default=configfile.sentinel): return self.objects[section] module_parts = section.split() module_name = module_parts[0] - py_name = os.path.join( + extras_py_name = os.path.join( os.path.dirname(__file__), "extras", module_name + ".py" ) - py_dirname = os.path.join( + extras_py_dirname = os.path.join( os.path.dirname(__file__), "extras", module_name, "__init__.py" ) - if not os.path.exists(py_name) and not os.path.exists(py_dirname): + + plugins_py_dirname = os.path.join( + os.path.dirname(__file__), "plugins", module_name, "__init__.py" + ) + plugins_py_name = os.path.join( + os.path.dirname(__file__), "plugins", module_name + ".py" + ) + + found_in_extras = os.path.exists(extras_py_name) or os.path.exists(extras_py_dirname) + found_in_plugins = os.path.exists(plugins_py_name) or os.path.exists(plugins_py_dirname) + if not found_in_extras and not found_in_plugins: if default is not configfile.sentinel: return default raise self.config_error("Unable to load module '%s'" % (section,)) - mod = importlib.import_module("extras." + module_name) + if found_in_extras: + mod = importlib.import_module("extras." + module_name) + else: + mod = importlib.import_module("plugins." + module_name) init_func = "load_config" if len(module_parts) > 1: init_func = "load_config_prefix" @@ -437,32 +450,8 @@ def main(): logging.info("Starting Klippy...") git_info = util.get_git_version() git_vers = git_info["version"] - extra_files = [ - fname - for code, fname in git_info["file_status"] - if ( - code in ("??", "!!") - and fname.endswith(".py") - and ( - fname.startswith("klippy/kinematics/") - or fname.startswith("klippy/extras/") - ) - ) - ] - modified_files = [ - fname for code, fname in git_info["file_status"] if code == "M" - ] + extra_git_desc = "" - if extra_files: - if not git_vers.endswith("-dirty"): - git_vers = git_vers + "-dirty" - if len(extra_files) > 10: - extra_files[10:] = ["(+%d files)" % (len(extra_files) - 10,)] - extra_git_desc += "\nUntracked files: %s" % (", ".join(extra_files),) - if modified_files: - if len(modified_files) > 10: - modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)] - extra_git_desc += "\nModified files: %s" % (", ".join(modified_files),) extra_git_desc += "\nBranch: %s" % (git_info["branch"]) extra_git_desc += "\nRemote: %s" % (git_info["remote"]) extra_git_desc += "\nTracked URL: %s" % (git_info["url"]) diff --git a/klippy/plugins/__init__.py b/klippy/plugins/__init__.py new file mode 100644 index 000000000..62f5df7b2 --- /dev/null +++ b/klippy/plugins/__init__.py @@ -0,0 +1,5 @@ +# Package definition for the plugin directory +# +# Copyright (C) 2023 Brandon Nance +# +# This file may be distributed under the terms of the GNU GPLv3 license.