diff --git a/mirth_client/models.py b/mirth_client/models.py index 0c713b9..7e63eba 100644 --- a/mirth_client/models.py +++ b/mirth_client/models.py @@ -21,15 +21,32 @@ from uuid import UUID import xmltodict -from pydantic import ( - BaseModel, - Protocol, - StrBytes, - ValidationError, - root_validator, - validator, -) -from pydantic.error_wrappers import ErrorWrapper +import typing +import pydantic +from packaging import version + +if typing.TYPE_CHECKING or version.parse(pydantic.__version__) >= version.parse("2.0"): + from pydantic.v1 import ( + BaseModel, + ValidationError, + root_validator, + validator, + StrBytes, + Protocol, + ) + from pydantic.v1.error_wrappers import ErrorWrapper +else: + from pydantic import ( + BaseModel, + Protocol, + StrBytes, + ValidationError, + root_validator, + validator, + ) + from pydantic.error_wrappers import ErrorWrapper + + from typing_extensions import TypedDict if TYPE_CHECKING: @@ -181,7 +198,7 @@ def parse_raw( # pylint: disable=arguments-differ *, content_type: Optional[str] = "xml", encoding: str = "utf8", - proto: Protocol = None, + proto: Optional[Protocol] = None, allow_pickle: bool = False, ) -> "Model": """Parse raw data into a Pydantic object. @@ -214,17 +231,17 @@ def parse_raw( # pylint: disable=arguments-differ raise ValidationError([ErrorWrapper(e, loc="__obj__")], cls) from e return super().parse_raw( # type: ignore b, - content_type=content_type, + content_type=content_type, # type: ignore encoding=encoding, - proto=proto, + proto=proto, # type: ignore allow_pickle=allow_pickle, ) def xml( self, *, - include: Union["SetIntStr", "DictIntStrAny"] = None, - exclude: Union["SetIntStr", "DictIntStrAny"] = None, + include: Union["SetIntStr", "DictIntStrAny", None] = None, + exclude: Union["SetIntStr", "DictIntStrAny", None] = None, by_alias: bool = True, exclude_unset: bool = False, ) -> str: diff --git a/pyproject.toml b/pyproject.toml index 128216b..8f1aefb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,11 +6,11 @@ packages = [ {include = "mirth_client"}, ] readme = "README.md" -version = "3.2.0" +version = "4.1.0" [tool.poetry.dependencies] Sphinx = {version = ">=3.5.3,<6.0.0", optional = true} -httpx = ">=0.23,<0.25" +httpx = ">=0.23,<0.28.1" pydantic = ">=1.8.2,<3.0.0" python = "^3.9" semver = ">=2.13,<4.0" @@ -21,17 +21,16 @@ xmltodict = ">=0.12,<0.14" [tool.poetry.extras] docs = ["Sphinx", "sphinx-rtd-theme"] -[tool.poetry.dev-dependencies] -bandit = "^1.7.0" -black = "^23.3" +[tool.poetry.group.dev.dependencies] +bandit = "^1.7.0" importlib-metadata = "<7" # Workaround for https://github.com/PyCQA/bandit/issues/951 isort = "^5.7.0" -lxml = "^5.2.2" -mypy = "^1.1" -pylint = "^2.8.2" +lxml = "^5.2.2" +mypy = "^1.1" pytest = "^7.0.0" pytest-cov = "^4.0.0" -tox = "^3.23.0" +tox = "^3.23.0" +ruff = "^0.12.0" [build-system] build-backend = "poetry.core.masonry.api" diff --git a/tests/_get_examples.py b/tests/_get_examples.py index cc51377..279c43c 100644 --- a/tests/_get_examples.py +++ b/tests/_get_examples.py @@ -31,7 +31,6 @@ for path in paths.values(): for method in path.keys(): - # Response examples response_examples_xml = ( path.get(method) diff --git a/tests/test_models/test_get_event_list.py b/tests/test_models/test_get_event_list.py index 0885fd5..abf477c 100644 --- a/tests/test_models/test_get_event_list.py +++ b/tests/test_models/test_get_event_list.py @@ -1,6 +1,5 @@ import datetime from pathlib import Path -from uuid import UUID from mirth_client.models import EventList EVENT_LIST_RESPONSE = ( diff --git a/tox.ini b/tox.ini index f0afcd8..045ab98 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,14 @@ [tox] isolated_build = true -envlist = black, mypy, pylint, bandit +envlist = ruff-format, mypy, pytest, ruff-lint, bandit [testenv] -whitelist_externals = poetry -commands = - poetry install -v +allowlist_externals = poetry +commands = poetry install -v --with dev -[testenv:black] -description = 'Check code style with Black' -commands = poetry run black . --check +[testenv:ruff-format] +description = 'Check code style with ruff' +commands = poetry run ruff format . --check [testenv:pytest] description = 'Run Python tests with pytest test runner.' @@ -19,9 +18,9 @@ commands = poetry run pytest --cov=mirth_client --cov-report term-missing --cov- description = 'Execute static analysis with mypy (type annotations).' commands = poetry run mypy mirth_client/ -[testenv:pylint] -description = 'Execute static analysis with pylint.' -commands = poetry run pylint mirth_client/ +[testenv:ruff-lint] +description = 'Execute static analysis with ruff.' +commands = poetry run ruff check mirth_client/ [testenv:bandit] description = 'Execute static analysis with bandit.'