Skip to content

Commit

Permalink
feat: add support for Pydantic V2 (#505)
Browse files Browse the repository at this point in the history
* feat(api): add Pydantic V2 support

* chore: update dependencies pyproject.toml

* chore(api): improved version management

* feat: improve Pydantic V2 compat checks
  • Loading branch information
camilovelezr authored Feb 21, 2024
1 parent 8aa8691 commit 5496b79
Show file tree
Hide file tree
Showing 32 changed files with 1,575 additions and 693 deletions.
29 changes: 21 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 @@ -27,27 +26,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: ^src\/polus\/plugins\/_plugins\/models\/\w*Schema.py$
exclude: |
(?x)(
test_[a-zA-Z0-9]+.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: ^src\/polus\/plugins\/_plugins\/models\/\w*Schema.py$
exclude: |
(?x)(
test_[a-zA-Z0-9]+.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]
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ 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"
python-on-whales = "^0.68.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"
pydantic = ">=1.10"
pytest = "^7.3.2"
pytest-benchmark = "^4.0.0"
pytest-cov = "^4.1.0"
pytest-sugar = "^0.9.7"
pytest-xdist = "^3.3.1"
python-on-whales = "^0.57.0"
python-on-whales = "^0.68.0"
pyyaml = "^6.0"
ruff = "^0.0.274"
tqdm = "^4.64.1"
Expand Down
9 changes: 9 additions & 0 deletions src/polus/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Initialize polus-plugins module."""

import logging
from pathlib import Path
from typing import Union

from polus.plugins._plugins.classes import (
Expand Down Expand Up @@ -30,6 +31,12 @@
"""
logger = logging.getLogger("polus.plugins")

with Path(__file__).parent.joinpath("_plugins/VERSION").open(
"r",
encoding="utf-8",
) as version_file:
VERSION = version_file.read().strip()


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

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

Expand Down
2 changes: 1 addition & 1 deletion src/polus/plugins/_plugins/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
4 changes: 4 additions & 0 deletions src/polus/plugins/_plugins/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Compat of Pydantic."""
import pydantic

PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
5 changes: 5 additions & 0 deletions src/polus/plugins/_plugins/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Plugin classes and functions."""

from polus.plugins._plugins.classes.plugin_classes import PLUGINS
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 _load_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
Expand All @@ -19,4 +22,6 @@
"remove_plugin",
"remove_all",
"load_config",
"_load_plugin",
"PLUGINS",
]
Loading

0 comments on commit 5496b79

Please sign in to comment.