Skip to content

Commit b0cc367

Browse files
authored
Add support for copying files specified in subfolders of tests folder to the recipe folder (#90)
1 parent 42709af commit b0cc367

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

vinca/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def read_vinca_yaml(filepath):
194194

195195
tests = {}
196196
test_dir = Path(filepath).parent / "tests"
197+
# Store the test directory directly for use in template.py
198+
vinca_conf["_test_dir"] = test_dir
197199
for x in test_dir.glob("*.yaml"):
198200
tests[os.path.basename(x).split(".")[0]] = x
199201
vinca_conf["_tests"] = tests

vinca/template.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ def write_recipe(source, outputs, vinca_conf, single_file=True):
120120

121121
recipe_dir = (Path("recipes") / o["package"]["name"]).absolute()
122122
os.makedirs(recipe_dir, exist_ok=True)
123+
124+
# Copy test folder contents if corresponding test folder exists
125+
test_dir = vinca_conf.get("_test_dir")
126+
if test_dir is not None:
127+
test_folder_name = o["package"]["name"]
128+
test_folder_path = test_dir / test_folder_name
129+
130+
if test_folder_path.exists() and test_folder_path.is_dir():
131+
# Copy all contents of the test folder to the recipe directory
132+
for item in test_folder_path.iterdir():
133+
if item.is_file():
134+
shutil.copy2(item, recipe_dir / item.name)
135+
elif item.is_dir():
136+
# Use copytree for directories, but handle existing directories
137+
dest_dir = recipe_dir / item.name
138+
if dest_dir.exists():
139+
shutil.rmtree(dest_dir)
140+
shutil.copytree(item, dest_dir)
141+
123142
with open(recipe_dir / "recipe.yaml", "w") as stream:
124143
file.dump(meta, stream)
125144

0 commit comments

Comments
 (0)