Skip to content

Commit 00075df

Browse files
author
Alan Christie
committed
feat: Initial structure
0 parents  commit 00075df

File tree

9 files changed

+369
-0
lines changed

9 files changed

+369
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
**/__pycache__/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Informatics Matters Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Informatics Matters Data Manager Workflow Decoder
2+
A package that simplifies the validation and decoding of Data Manager
3+
Workflow definitions.
4+
5+
## Installation (Python)
6+
The Job decoder is published on PyPI and can be installed from there:
7+
8+
pip install im-data-manager-workflow-decoder
9+
10+
Once installed you can validate the definition (expected to be a dictionary
11+
formed from the definition YAML file) with:
12+
13+
>>> from workflow import decoder
14+
>>> error: Optional[str] = decoder.validate_schema(workflow)

poetry.lock

Lines changed: 249 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool.poetry]
2+
name = "im-data-manager-workflow-decoder"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Alan Christie <[email protected]>"]
6+
readme = "README.md"
7+
packages = [
8+
{ include = "workflow", from = "." }
9+
]
10+
11+
[tool.poetry.dependencies]
12+
python = "^3.12"
13+
jsonschema = "^4.21.1"
14+
pyyaml = ">= 5.3.1, < 7.0"
15+
16+
[build-system]
17+
requires = ["poetry-core"]
18+
build-backend = "poetry.core.masonry.api"

tests/__init__.py

Whitespace-only changes.

workflow/__init__.py

Whitespace-only changes.

workflow/decoder.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""A module to validate and decode workflow definitions.
2+
3+
This is typically used by the Data Manager's Workflow Engine.
4+
"""
5+
import os
6+
from typing import Any, Dict, Optional
7+
8+
import jsonschema
9+
import yaml
10+
11+
# The (built-in) schemas...
12+
# from the same directory as us.
13+
_WORKFLOW_SCHEMA_FILE: str = os.path.join(
14+
os.path.dirname(__file__), "workflow-schema.yaml"
15+
)
16+
17+
# Load the Workflow schema YAML file now.
18+
# This must work as the file is installed along with this module.
19+
assert os.path.isfile(_WORKFLOW_SCHEMA_FILE)
20+
with open(_WORKFLOW_SCHEMA_FILE, "r", encoding="utf8") as schema_file:
21+
_WORKFLOW_SCHEMA: Dict[str, Any] = yaml.load(schema_file, Loader=yaml.FullLoader)
22+
assert _WORKFLOW_SCHEMA
23+
24+
25+
def validate_schema(workflow: Dict[str, Any]) -> Optional[str]:
26+
"""Checks the Workflow Definition against the built-in schema.
27+
If there's an error the error text is returned, otherwise None.
28+
"""
29+
assert isinstance(workflow, dict)
30+
31+
try:
32+
jsonschema.validate(workflow, schema=_WORKFLOW_SCHEMA)
33+
except jsonschema.ValidationError as ex:
34+
return str(ex.message)
35+
36+
# OK if we get here
37+
return None

workflow/workflow-schema.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# The JSONSchema for 'Workflow' YAML files.
3+
#
4+
# See https://json-schema.org/understanding-json-schema/index.html
5+
6+
$schema: http://json-schema.org/draft-07/schema#
7+
8+
title: Data Manager Workflow Schema
9+
description: >-
10+
The Schema for Data Manager Workflows
11+
12+
type: object
13+
properties:
14+
kind:
15+
const: DataManagerWorkflow
16+
kind-version:
17+
enum:
18+
- '2024.1'
19+
name:
20+
type: string
21+
description: The name of the workflow
22+
description:
23+
type: string
24+
description: A description of the workflow
25+
required:
26+
- kind
27+
- kind-version
28+
- name

0 commit comments

Comments
 (0)