Skip to content

Commit a8de0b7

Browse files
committed
throw exception if an unused file exists in the
lookups directory
1 parent b8e8f2d commit a8de0b7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

contentctl/actions/validate.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
2+
import pathlib
33
from dataclasses import dataclass
44

55
from pydantic import ValidationError
@@ -42,8 +42,19 @@ def execute(self, input_dto: validate) -> DirectorOutputDto:
4242

4343
director = Director(director_output_dto)
4444
director.execute(input_dto)
45+
self.ensure_no_orphaned_lookup_files(input_dto.path, director_output_dto)
4546
return director_output_dto
4647

48+
def ensure_no_orphaned_lookup_files(self, repo_path:pathlib.Path, director_output_dto:DirectorOutputDto):
49+
# get all files in the lookup folder
50+
usedLookupFiles:list[pathlib.Path] = [lookup.filename for lookup in director_output_dto.lookups if lookup.filename is not None] + [lookup.file_path for lookup in director_output_dto.lookups if lookup.file_path is not None]
51+
lookupsDirectory = repo_path/"lookups"
52+
unusedLookupFiles:list[pathlib.Path] = [testFile for testFile in lookupsDirectory.glob("**/*.*") if testFile not in usedLookupFiles]
53+
if len(unusedLookupFiles) > 0:
54+
raise ValueError(f"The following files exist in '{lookupsDirectory}', but either do not end in .yml, .csv, or .mlmodel or are not used by a YML file: {[str(path) for path in unusedLookupFiles]}")
55+
return
56+
57+
4758
def validate_duplicate_uuids(
4859
self, security_content_objects: list[SecurityContentObject_Abstract]
4960
):

0 commit comments

Comments
 (0)