Skip to content

Commit

Permalink
fix archive schema
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed May 27, 2024
1 parent 48a98e3 commit 7f2e721
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 48 deletions.
38 changes: 23 additions & 15 deletions code/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,39 @@ class ValidationResult(Enum):
SKIPPED = "SKIPPED"
PASSED = "PASSED"
FAILED = "FAILED"



logger = getLogger(__name__)
logger.setLevel(INFO)
logger.addHandler(StreamHandler())

ROOT_DIR = os.path.abspath(f"{os.path.dirname(os.path.realpath(__file__))}/..")

skip_path = ("venv", "maps")
skip_path = ("venv", "siibra-configurations/maps")

skip_types = (
"siibra/feature/timeseries/activity/v0.1",
"siibra/feature/connectivitymatrix/v0.3",
)


def populate_jsonschema_reg():
registry = referencing.Registry()
walk_path = Path(ROOT_DIR) / "siibra"
for dirpath, dirnames, filenames in os.walk(walk_path):
for filename in filenames:
if not filename.endswith(".json"):
continue

filepath = Path(dirpath) / filename
with open(filepath, "r") as fp:
uri = f"urn:siibra-local:{str(filepath.relative_to(ROOT_DIR))}"
resource = referencing.Resource.from_contents(json.load(fp=fp))
registry = registry.with_resource(uri=uri, resource=resource)

return registry


def validate_json(path_to_json, registry, fail_fast=False):
if any([path_fragment in path_to_json for path_fragment in skip_path]):
return (
Expand Down Expand Up @@ -81,34 +84,40 @@ def validate_json(path_to_json, registry, fail_fast=False):
return (path_to_json, ValidationResult.FAILED, e)
return (path_to_json, ValidationResult.PASSED, None)

def main(dir_to_validate: str=None, *args, debug=False):


def main(dir_to_validate: str = None, *args, debug=False):

if debug:
logger.setLevel(DEBUG)

jsonschema_reg = populate_jsonschema_reg()
# resolver = jsonschema_reg.resolver()

if dir_to_validate is None:
raise RuntimeError(f"pass the directory that needs to validated")
raise RuntimeError("pass the directory that needs to validated")

result = []
for dirpath, dirnames, filenames in os.walk(dir_to_validate):
for filename in filenames:
path_to_file = Path(dirpath) / filename
if not filename.endswith(".json"):
logger.debug(f"Skipping {path_to_file} because it does not end in .json")
logger.debug(
f"Skipping {path_to_file} because it does not end in .json"
)
continue
logger.debug(f"Processing {path_to_file}")
result.append(
validate_json(str(path_to_file), jsonschema_reg, fail_fast=False)
validate_json(str(path_to_file),
jsonschema_reg,
fail_fast=False)
)

passed = [r for r in result if r[1] == ValidationResult.PASSED]
failed = [r for r in result if r[1] == ValidationResult.FAILED]
skipped = [r for r in result if r[1] == ValidationResult.SKIPPED]
print(
f"Validation results: PASSED: {len(passed)} SKIPPED: {len(skipped)} FAILED: {len(failed)}"
f"Validation results: PASSED: {len(passed)} SKIPPED:"
f"{len(skipped)} FAILED: {len(failed)}"
)

if len(failed) > 0:
Expand All @@ -117,8 +126,7 @@ def main(dir_to_validate: str=None, *args, debug=False):
raise ValidationError(
message="\n-----\n".join([f"{f[0]}: {str(f[2])}" for f in failed])
)



if __name__ == "__main__":
main(*sys.argv[1:])
main(*sys.argv[1:])
30 changes: 0 additions & 30 deletions siibra/attr/data/archive/v0.1.json

This file was deleted.

3 changes: 0 additions & 3 deletions siibra/attr/data/v0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
},
{
"$ref": "urn:siibra-local:siibra/attr/data/tabular/v0.1.json"
},
{
"$ref": "urn:siibra-local:siibra/attr/data/archive/v0.1.json"
}
]
}
Expand Down
16 changes: 16 additions & 0 deletions siibra/attr/util/archived/v0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"archive": {
"type": "object",
"properties": {
"format": {
"$ref": "#/definitions/archive_type"
},
"file": {
"type": "string"
}
Expand All @@ -29,6 +32,19 @@
"type": "number"
}
}
},
"archive_type": {
"oneOf": [
{
"const": "tar.gz"
},
{
"const": "tar"
},
{
"const": "zip"
}
]
}
}
}

0 comments on commit 7f2e721

Please sign in to comment.