commit 7e076f21803a86b35ea6f44aff243cd6554fad8a
parent e1fdb8e760445e65458df86c74e89bf0841a74f1
Author: Andrew D. Laack <andrew@laack.co>
Date: Thu, 19 Jun 2025 21:15:15 -0500
Merge pull request #3 from andrewlaack/feature/specify-directories-or-regex
Added path expansion for file specification.
Diffstat:
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ratchets"
-version = "0.1.3"
+version = "0.2.4"
description = "Ratcheted testing in Python."
authors = [
{ name = "Andrew Laack", email = "andrew@laack.co" }
diff --git a/src/ratchets/run_tests.py b/src/ratchets/run_tests.py
@@ -360,7 +360,7 @@ def print_issues_with_blames(
for test_name, matches in issues_dict.items():
if matches:
sorted_matches = sorted(
- matches, key=lambda m: _parse_time(m.get("blame_time"))
+ matches, key=lambda m: _parse_time(m.get("blame_time")), reverse=True
)
print()
print(
@@ -482,6 +482,28 @@ def add_blames(
return test_issues, shell_issues
+
+def expand_paths(file_args: Optional[List[str]]) -> Optional[List[str]]:
+ """Expands glob patterns and directories into a list of file paths."""
+ if not file_args:
+ return None
+
+ expanded_paths = []
+
+ for item in file_args:
+ path = Path(item)
+
+ if "*" in item or "?" in item or "[" in item:
+ expanded_paths.extend([str(p) for p in Path().rglob(item)])
+ elif path.is_dir():
+ expanded_paths.extend([str(p) for p in path.rglob("*.py")])
+ elif path.is_file():
+ expanded_paths.append(str(path))
+ else:
+ print(f"Warning: '{item}' does not exist or is not valid.")
+
+ return expanded_paths if expanded_paths else None
+
def cli():
"""Primary entry point for CLI usage, providing parsing and function calls."""
parser = argparse.ArgumentParser(description="Python ratchet testing")
@@ -542,7 +564,12 @@ def cli():
blame: bool = args.blame
verbose: bool = args.verbose
max_count: Optional[int] = args.max_count
- paths: List[str] = args.files
+ path_files: List[str] = args.files
+
+ paths = expand_paths(path_files)
+
+ if paths is not None:
+ paths = [path for path in paths if Path(path).suffix == ".py" and Path(path).is_file()]
excludes_path = get_excludes_path()