Skip to content

Commit

Permalink
feat(api): add Pydantic V2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
camilovelezr committed Jan 26, 2024
1 parent bf0885d commit 70fb877
Show file tree
Hide file tree
Showing 35 changed files with 2,637 additions and 670 deletions.
21 changes: 13 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fail_fast: true

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -26,35 +25,41 @@ repos:
args: ["--fix=lf"]
description: Forces to replace line ending by the UNIX 'lf' character.
- id: trailing-whitespace
exclude: '.bumpversion.cfg'
exclude: ".bumpversion.cfg"
- id: check-merge-conflict

- repo: https://github.com/psf/black
rev: '23.3.0'
rev: "23.3.0"
hooks:
- id: black
language_version: python3.9
exclude: ^src\/polus\/plugins\/_plugins\/models\/\w*Schema.py$
exclude: |
(?x)(
^src\/polus\/plugins\/_plugins\/models\/pydanticv1\/\w*Schema.py$|
^src\/polus\/plugins\/_plugins\/models\/pydanticv2\/\w*Schema.py$
)
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.274'
rev: "v0.0.274"
hooks:
- id: ruff
exclude: |
(?x)(
test_[a-zA-Z0-9]+.py$|
^src\/polus\/plugins\/_plugins\/models\/\w*Schema.py$
^src\/polus\/plugins\/_plugins\/models\/pydanticv1\/\w*Schema.py$|
^src\/polus\/plugins\/_plugins\/models\/pydanticv2\/\w*Schema.py$
)
args: [--fix]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.4.0'
rev: "v1.4.0"
hooks:
- id: mypy
exclude: |
(?x)(
test_[a-zA-Z0-9]+.py$|
^src\/polus\/plugins\/_plugins\/models\/\w*Schema.py$
^src\/polus\/plugins\/_plugins\/models\/pydanticv1\/\w*Schema.py$|
^src\/polus\/plugins\/_plugins\/models\/pydanticv2\/\w*Schema.py$
)
additional_dependencies: [types-requests==2.31.0.1]
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@ python = ">=3.9, <3.12"
click = "^8.1.3"
cwltool = "^3.1.20230513155734"
fsspec = "^2023.6.0"
pydantic = ">=1.10.9, <2.0"
pydantic = ">=1.10.0"
pygithub = "^1.58.2"
python-on-whales = "^0.57.0"
pyyaml = "^6.0"
tqdm = "^4.65.0"
validators = "^0.22.0"
xmltodict = "^0.13.0"

[tool.poetry.group.dev.dependencies]
python = ">=3.9, <3.12"

black = "^23.3.0"
bump2version = "^1.0.1"
datamodel-code-generator = "^0.17.1"
datamodel-code-generator = "^0.23.0"
flake8 = "^6.0.0"
fsspec = "^2023.1.0"
mypy = "^1.4.0"
nox = "^2022.11.21"
poetry = "^1.3.2"
pre-commit = "^3.3.3"
pydantic = "^1.10.4"
pydantic-to-typescript = "^1.0.10"
pytest = "^7.3.2"
pytest-benchmark = "^4.0.0"
pytest-cov = "^4.1.0"
Expand Down
4 changes: 4 additions & 0 deletions src/polus/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"""
logger = logging.getLogger("polus.plugins")

VERSION = "0.1.1"


refresh() # calls the refresh method when library is imported

Expand All @@ -39,6 +41,8 @@ def __getattr__(name: str) -> Union[Plugin, ComputePlugin, list]:
return list_plugins()
if name in list_plugins():
return get_plugin(name)
if name == "__version__":
return VERSION
msg = f"module '{__name__}' has no attribute '{name}'"
raise AttributeError(msg)

Expand Down
39 changes: 30 additions & 9 deletions src/polus/plugins/_plugins/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
"""Plugin classes and functions."""
from polus.plugins._plugins.classes.plugin_classes import ComputePlugin
from polus.plugins._plugins.classes.plugin_classes import Plugin
from polus.plugins._plugins.classes.plugin_classes import get_plugin
from polus.plugins._plugins.classes.plugin_classes import list_plugins
from polus.plugins._plugins.classes.plugin_classes import load_config
from polus.plugins._plugins.classes.plugin_classes import refresh
from polus.plugins._plugins.classes.plugin_classes import remove_all
from polus.plugins._plugins.classes.plugin_classes import remove_plugin
from polus.plugins._plugins.classes.plugin_classes import submit_plugin
import pydantic

PYDANTIC_VERSION = pydantic.__version__

if PYDANTIC_VERSION.split(".")[0] == "1":
from polus.plugins._plugins.classes.plugin_classes_v1 import PLUGINS
from polus.plugins._plugins.classes.plugin_classes_v1 import ComputePlugin
from polus.plugins._plugins.classes.plugin_classes_v1 import Plugin
from polus.plugins._plugins.classes.plugin_classes_v1 import _load_plugin
from polus.plugins._plugins.classes.plugin_classes_v1 import get_plugin
from polus.plugins._plugins.classes.plugin_classes_v1 import list_plugins
from polus.plugins._plugins.classes.plugin_classes_v1 import load_config
from polus.plugins._plugins.classes.plugin_classes_v1 import refresh
from polus.plugins._plugins.classes.plugin_classes_v1 import remove_all
from polus.plugins._plugins.classes.plugin_classes_v1 import remove_plugin
from polus.plugins._plugins.classes.plugin_classes_v1 import submit_plugin
elif PYDANTIC_VERSION.split(".")[0] == "2":
from polus.plugins._plugins.classes.plugin_classes_v2 import PLUGINS
from polus.plugins._plugins.classes.plugin_classes_v2 import ComputePlugin
from polus.plugins._plugins.classes.plugin_classes_v2 import Plugin
from polus.plugins._plugins.classes.plugin_classes_v2 import _load_plugin
from polus.plugins._plugins.classes.plugin_classes_v2 import get_plugin
from polus.plugins._plugins.classes.plugin_classes_v2 import list_plugins
from polus.plugins._plugins.classes.plugin_classes_v2 import load_config
from polus.plugins._plugins.classes.plugin_classes_v2 import refresh
from polus.plugins._plugins.classes.plugin_classes_v2 import remove_all
from polus.plugins._plugins.classes.plugin_classes_v2 import remove_plugin
from polus.plugins._plugins.classes.plugin_classes_v2 import submit_plugin

__all__ = [
"Plugin",
Expand All @@ -19,4 +38,6 @@
"remove_plugin",
"remove_all",
"load_config",
"_load_plugin",
"PLUGINS",
]
Loading

0 comments on commit 70fb877

Please sign in to comment.