From cb61bf7be701b7b3d83b5a834567fff77522715f Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Mon, 20 May 2024 16:12:56 -0400 Subject: [PATCH] Allow concat to glob --- src/marvin/tools/filesystem.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/marvin/tools/filesystem.py b/src/marvin/tools/filesystem.py index 31fca796f..7998d4701 100644 --- a/src/marvin/tools/filesystem.py +++ b/src/marvin/tools/filesystem.py @@ -217,19 +217,26 @@ def ls(path: str) -> str: def glob(pattern: str) -> list[str]: """ Returns a list of paths matching a valid glob pattern. The pattern can - include ** for recursive matching, such as '~/path/to/root/**/*.py'. Only - simple glob patterns are supported, no braces or other advanced features - like searching multiple file extensions at once. + include ** for recursive matching, such as '/path/**/dir/*.py'. Only simple + glob patterns are supported, compound queries like '/path/*.{py, md}' are + NOT supported. """ return glob_module.glob(pattern, recursive=True) def concat(source_paths: list[str], dest_path: str, add_headers: bool = True) -> str: """ - Concatenates the contents of multiple source files into a single - destination file. The result should be markdown. If add_headers is True, the - file path will be added as a header above the contents of each file. + Concatenates the contents of multiple source files into a single destination + file. The result should be markdown. If add_headers is True, the file path + will be added as a header above the contents of each file. + + Note that source paths can include simple glob patterns, such as + '/path/**/dir/*.py'. Compound queries like '/path/*.{py, md}' are NOT + supported. """ + # source_paths can include glob patterns + source_paths = [path for pattern in source_paths for path in glob(pattern)] + dest_path = _safe_create_file(dest_path) with open(dest_path, "w") as dest_file: for source_path in source_paths: