Skip to content

Commit

Permalink
FIX: CSIPSTR3 false positive
Browse files Browse the repository at this point in the history
- solution a bit hacky but the message now honours the state of the original path.
  • Loading branch information
carlwilson committed Sep 11, 2024
1 parent 34343eb commit e94d4c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions eark_validator/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, package_path: Path, version: SpecificationVersion = Specifica
self._report = _report_from_bad_path(package_path)
return

self._report = self.validate(self._version, self._to_proc)
self._report = self.validate(self._version, self._to_proc, PackageHandler.is_archive(package_path))

@property
def original_path(self) -> Path:
Expand All @@ -86,10 +86,10 @@ def version(self) -> SpecificationVersion:
return self._version

@classmethod
def validate(cls, version: SpecificationVersion, to_validate: Path) -> ValidationReport:
def validate(cls, version: SpecificationVersion, to_validate: Path, is_archive: bool=False) -> ValidationReport:
"""Returns the validation report that results from validating the path
to_validate as a folder. The method does not validate archive files."""
is_struct_valid, struct_results = structure.validate(to_validate)
is_struct_valid, struct_results = structure.validate(to_validate, is_archive)
if not is_struct_valid:
return ValidationReport.model_validate({'structure': struct_results})
validator = MetsValidator(str(to_validate))
Expand Down
12 changes: 6 additions & 6 deletions eark_validator/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
class StructureParser():
_package_handler = PackageHandler()
"""Encapsulates the set of tests carried out on folder structure."""
def __init__(self, package_path: Path):
self._is_archive = PackageHandler.is_archive(package_path)
def __init__(self, package_path: Path, is_archive: bool = False):
self._is_archive = is_archive
self.md_folders: set[str]= set()
self.folders: set[str] = set()
self.files : set[str] = set()
Expand Down Expand Up @@ -117,9 +117,9 @@ def is_archive(self) -> bool:
return self._is_archive

class StructureChecker():
def __init__(self, dir_to_scan: Path):
def __init__(self, dir_to_scan: Path, is_archive: bool=False):
self.name: str = os.path.basename(dir_to_scan)
self.parser: StructureParser = StructureParser(dir_to_scan)
self.parser: StructureParser = StructureParser(dir_to_scan, is_archive)
self.representations: Dict[Representation, StructureParser] = {}
if self.parser.is_parsable:
_reps = os.path.join(self.parser.resolved_path, DIR_NAMES['REPS'])
Expand Down Expand Up @@ -245,9 +245,9 @@ def _get_str1_result_list(name: str) -> List[Result]:
def _root_loc(name: str) -> str:
return f'{ROOT} {name}'

def validate(to_validate) -> Tuple[bool, StructResults]:
def validate(to_validate, is_archive: bool=False) -> Tuple[bool, StructResults]:
try:
struct_tests = StructureChecker(to_validate).get_test_results()
struct_tests = StructureChecker(to_validate, is_archive).get_test_results()
return struct_tests.status == StructureStatus.WELLFORMED, struct_tests
except PackageError:
return False, get_bad_path_results(to_validate)

0 comments on commit e94d4c0

Please sign in to comment.