Skip to content

Commit

Permalink
Merge pull request #337 from opensafely-core/remove-pydantic
Browse files Browse the repository at this point in the history
Remove pydantic dependency
  • Loading branch information
inglesp authored Sep 27, 2024
2 parents 71a56a1 + ecf3e31 commit 162b2d0
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 358 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For example:
data = load_pipeline(f.read())


The returned object is a Pydantic model, `Pipeline`, defined in `pipeline/models.py`.
The returned object is an instance of `pipeline.models.Pipeline`.


## Developer docs
Expand Down
4 changes: 4 additions & 0 deletions pipeline/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ class InvalidPatternError(ProjectValidationError):

class YAMLError(Exception):
pass


class ValidationError(Exception):
pass
4 changes: 2 additions & 2 deletions pipeline/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

def get_all_output_patterns_from_project_file(project_file: str) -> list[str]:
config = load_pipeline(project_file)
all_patterns = set()
all_patterns: set[str] = set()
for action in config.actions.values():
for patterns in action.outputs.dict(exclude_unset=True).values():
for patterns in action.outputs.dict().values():
all_patterns.update(patterns.values())
return list(all_patterns)
8 changes: 3 additions & 5 deletions pipeline/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from pathlib import Path

import pydantic

from .exceptions import ProjectValidationError, YAMLError
from .exceptions import ProjectValidationError, ValidationError, YAMLError
from .loading import parse_yaml_file
from .models import Pipeline

Expand All @@ -27,8 +25,8 @@ def load_pipeline(pipeline_config: str | Path, filename: str | None = None) -> P

# validate
try:
return Pipeline(**parsed_data)
except pydantic.ValidationError as exc:
return Pipeline.build(**parsed_data)
except ValidationError as exc:
raise ProjectValidationError(
f"Invalid project: {filename or ''}\n{exc}"
) from exc
Loading

0 comments on commit 162b2d0

Please sign in to comment.