Skip to content

Commit 8382a4c

Browse files
authored
Merge pull request #187 from dbt-labs/fix/issue-185-recursive-glob
fix: enable recursive glob patterns with **
2 parents 0b1d401 + 898b5e6 commit 8382a4c

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/dbt_jobs_as_code/cloud_yaml_mapping/change_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ def build_change_set(
197197
if os.path.isdir(config):
198198
config = os.path.join(config, "*.yml")
199199
# Get list of files matching the glob pattern
200-
config_files = glob.glob(config)
200+
config_files = glob.glob(config, recursive=True)
201201
if not config_files:
202202
logger.error(f"No files found matching pattern: {config}")
203203
return ChangeSet()
204204

205-
yml_vars_files = glob.glob(yml_vars) if yml_vars else None
205+
yml_vars_files = glob.glob(yml_vars, recursive=True) if yml_vars else None
206206

207207
try:
208208
configuration = load_job_configuration(config_files, yml_vars_files)

src/dbt_jobs_as_code/loader/load.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _resolve_pattern(pattern: str) -> List[str]:
197197
yaml_files = glob.glob(os.path.join(pattern, "*.yaml"))
198198
return yml_files + yaml_files
199199
else:
200-
return glob.glob(pattern)
200+
return glob.glob(pattern, recursive=True)
201201

202202

203203
def resolve_file_paths(

tests/loader/test_loader.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ def test_resolve_file_paths_directory_for_vars(self, tmp_path):
456456
assert config_files == [str(config_file)]
457457
assert len(vars_files) == 2
458458

459+
def test_resolve_file_paths_recursive_glob(self, tmp_path):
460+
"""Test resolving files with recursive ** glob pattern (issue #185)"""
461+
jobs_dir = tmp_path / "jobs"
462+
# Create nested directory structure
463+
(jobs_dir / "category1" / "subcategory1").mkdir(parents=True)
464+
(jobs_dir / "category2").mkdir(parents=True)
465+
466+
(jobs_dir / "top_level.yml").write_text("content")
467+
(jobs_dir / "category1" / "job1.yml").write_text("content1")
468+
(jobs_dir / "category1" / "subcategory1" / "job2.yml").write_text("content2")
469+
(jobs_dir / "category2" / "job3.yml").write_text("content3")
470+
471+
config_files, vars_files = resolve_file_paths(str(jobs_dir / "**" / "*.yml"))
472+
assert len(config_files) == 4
473+
assert all(f.endswith(".yml") for f in config_files)
474+
459475
def test_resolve_file_paths_with_vars(self, tmp_path):
460476
"""Test resolving both config and vars files"""
461477
config_file = tmp_path / "config.yml"

0 commit comments

Comments
 (0)