From aec0b3d9bb517b8563678ae39db4da1222d75676 Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:01:11 -0400 Subject: [PATCH] add Path.walk backport --- .gitignore | 1 + orbiter/rules/rulesets.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 37c1e9c..94e914b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ test_binary workflow *.pyz orbiter-* +.python-version diff --git a/orbiter/rules/rulesets.py b/orbiter/rules/rulesets.py index c2ae14b..aba7cbe 100644 --- a/orbiter/rules/rulesets.py +++ b/orbiter/rules/rulesets.py @@ -751,7 +751,17 @@ def get_files_with_extension(self, input_dir: Path) -> Generator[Path, dict]: extensions.append(f".{other_extension}") logger.debug(f"Finding files with extension={extensions} in {input_dir}") - for directory, _, files in input_dir.walk(): + + def backport_walk(input_dir: Path): + """Path.walk() is only available in Python 3.12+, so, backport""" + import os + + for result in os.walk(input_dir): + yield Path(result[0]), result[1], result[2] + + for directory, _, files in ( + input_dir.walk() if hasattr(input_dir, "walk") else backport_walk(input_dir) + ): logger.debug(f"Checking directory={directory}") for file in files: file = directory / file