Skip to content

Commit

Permalink
plugins v1 and no more dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnance committed Oct 31, 2023
1 parent e7893db commit 30e4c3b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ klippy/.version
ci_build/
ci_cache/
_test_.*
klippy/plugins/*
!klippy/plugins/__init__.py
47 changes: 18 additions & 29 deletions klippy/klippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"])
Expand Down
5 changes: 5 additions & 0 deletions klippy/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Package definition for the plugin directory
#
# Copyright (C) 2023 Brandon Nance <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.

0 comments on commit 30e4c3b

Please sign in to comment.