Skip to content

Commit

Permalink
Automatically validate oraganise configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aratz committed Sep 15, 2023
1 parent f649b10 commit 7777dd1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ jobs:
python -m pip install --upgrade pip
pip install wheel
pip install -r requirements/dev .
npm install -g pajv
- name: Launch tests
run: |
nosetests ./tests
- name: Lint config files
run: |
yamllint -c .yamllint.yml config/organise_configs/*.yml
- name: Validate config files
run: >
pajv
-s config/organise_configs/schema.json
-d config/organise_configs/*.yml
34 changes: 34 additions & 0 deletions config/organise_configs/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"type": "object",
"required": ["variables", "files_to_organise"],
"properties": {
"variables": {
"type": "object",
"additionalProperties": {"type": "string"}
},
"files_to_organise": {
"type": "array",
"items": {
"type": "object",
"required": ["source", "destination", "options"],
"properties": {
"source": {"type": "string"},
"destination": {"type": "string"},
"options": {
"type": "object",
"properties": {
"required": {"type": "boolean"},
"link_type": {
"type": "string",
"enum": ["softlink", "hardlink", "copy"]
},
"filter": {"type": "string"}
},
"additionalProperties": false
}
}
}
}
},
"additionalProperties": false
}
47 changes: 9 additions & 38 deletions delivery/handlers/organise_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,6 @@

log = logging.getLogger(__name__)

ORGANISE_CONFIG_SCHEMA = {
"type": "object",
"required": ["variables", "files_to_organise"],
"properties": {
"variables": {
"type": "object",
"additionalProperties": {"type": "string"},
},
"files_to_organise": {
"type": "array",
"items": {
"type": "object",
"required": ["source", "destination", "options"],
"properties": {
"source": {"type": "string"},
"destination": {"type": "string"},
"options": {
"type": "object",
"properties": {
"required": {"type": "boolean"},
"link_type": {
"type": "string",
"enum": ["softlink", "hardlink", "copy"],
},
"filter": {"type": "string"},
},
"additionalProperties": False,
}
}
}
}
},
"additionalProperties": False,
}


class BaseOrganiseHandler(BaseRestHandler):
pass
Expand Down Expand Up @@ -145,7 +110,9 @@ def post(self, analysis_pipeline, project):
f"Config file not found at {organise_config_path}")
with open(organise_config_path, 'r') as organise_config_file:
config = yaml.load(organise_config_file, Loader=yaml.CLoader)
jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA)
with open(organise_config_dir / "schema.json", 'r') as organise_config_schema:
schema = json.load(organise_config_schema)
jsonschema.validate(config, schema)

if not project_path.is_dir():
raise FileNotFoundError(
Expand Down Expand Up @@ -176,7 +143,9 @@ def post(self, project):
f"Config file not found at {organise_config_path}")
with open(organise_config_path, 'r') as organise_config_file:
config = yaml.load(organise_config_file, Loader=yaml.CLoader)
jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA)
with open(pathlib.Path(self.config["organise_config_dir"]) / "schema.json", 'r') as organise_config_schema:
schema = json.load(organise_config_schema)
jsonschema.validate(config, schema)

if not project_path.is_dir():
raise FileNotFoundError(
Expand Down Expand Up @@ -211,7 +180,9 @@ def post(self, runfolder):
f"Config file not found at {organise_config_path}")
with open(organise_config_path, 'r') as organise_config_file:
config = yaml.load(organise_config_file, Loader=yaml.CLoader)
jsonschema.validate(config, ORGANISE_CONFIG_SCHEMA)
with open(organise_config_dir / "schema.json", 'r') as organise_config_schema:
schema = json.load(organise_config_schema)
jsonschema.validate(config, schema)

if not runfolder_path.is_dir():
raise FileNotFoundError(
Expand Down

0 comments on commit 7777dd1

Please sign in to comment.