From 62feda5dafa5be55d151b1dded2fc635cc1e94c2 Mon Sep 17 00:00:00 2001 From: bdistin Date: Wed, 25 Oct 2023 10:53:36 -0500 Subject: [PATCH 1/3] config: Allow config includes to use subfolder globs This has been a minor change I have been using for a while to keep my config well organized. I was using index files to include subfolders, but this is a cleaner solution. ``` [include hardware/**/*.cfg] [include macros/**/*.cfg] ``` Signed-off-by: Ben Distin --- klippy/configfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/configfile.py b/klippy/configfile.py index dd32d47fd3c6..d3244453ebf3 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -223,7 +223,7 @@ def _resolve_include(self, source_filename, include_spec, fileconfig, dirname = os.path.dirname(source_filename) include_spec = include_spec.strip() include_glob = os.path.join(dirname, include_spec) - include_filenames = glob.glob(include_glob) + include_filenames = glob.glob(include_glob, recursive=True) if not include_filenames and not glob.has_magic(include_glob): # Empty set is OK if wildcard but not for direct file reference raise error("Include file '%s' does not exist" % (include_glob,)) From 2e3657fd95d381129f9c5d9320fe5409d947b9c2 Mon Sep 17 00:00:00 2001 From: bdistin Date: Thu, 26 Oct 2023 10:01:24 -0500 Subject: [PATCH 2/3] docs: Update documentation to show subdirectory wildcard support Signed-off-by: Ben Distin --- docs/Config_Reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 241391834e0f..1f5edf795a79 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1773,7 +1773,7 @@ aliases_: Include file support. One may include additional config file from the main printer config file. Wildcards may also be used (eg, -"configs/*.cfg"). +"configs/\*.cfg", "configs/\*\*/\*.cfg"). ``` [include my_other_config.cfg] From 4cc2d062233cbc849030ff9bc4b68cd8dcf9072f Mon Sep 17 00:00:00 2001 From: bdistin Date: Mon, 13 Nov 2023 15:51:39 -0600 Subject: [PATCH 3/3] config: Recursive globs only added in python version 3.5 and above Signed-off-by: Ben Distin --- docs/Config_Reference.md | 2 +- klippy/configfile.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 1f5edf795a79..aabc33891a1a 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -1773,7 +1773,7 @@ aliases_: Include file support. One may include additional config file from the main printer config file. Wildcards may also be used (eg, -"configs/\*.cfg", "configs/\*\*/\*.cfg"). +"configs/\*.cfg", or "configs/\*\*/\*.cfg" if using python version >=3.5). ``` [include my_other_config.cfg] diff --git a/klippy/configfile.py b/klippy/configfile.py index d3244453ebf3..3699b13c6a51 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -223,7 +223,11 @@ def _resolve_include(self, source_filename, include_spec, fileconfig, dirname = os.path.dirname(source_filename) include_spec = include_spec.strip() include_glob = os.path.join(dirname, include_spec) - include_filenames = glob.glob(include_glob, recursive=True) + include_filenames = None + if sys.version_info >= (3, 5): + include_filenames = glob.glob(include_glob, recursive=True) + else: + include_filenames = glob.glob(include_glob) if not include_filenames and not glob.has_magic(include_glob): # Empty set is OK if wildcard but not for direct file reference raise error("Include file '%s' does not exist" % (include_glob,))