Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ deprecate semver in favor of semantic_version #209

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pydantic_extra_types/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
else:
from typing import Annotated # pragma: no cover

import warnings

from pydantic import GetJsonSchemaHandler
from pydantic.json_schema import JsonSchemaValue
from pydantic_core import core_schema
from semver import Version

warnings.warn(
'Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.', DeprecationWarning
)


class _VersionPydanticAnnotation(Version):
"""
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ classifiers = [
'Topic :: Internet',
]
requires-python = '>=3.8'
dependencies = ['pydantic>=2.5.2']
dependencies = ['pydantic>=2.5.2','typing-extensions']
dynamic = ['version']

[project.optional-dependencies]
Expand Down Expand Up @@ -123,7 +123,8 @@ filterwarnings = [
# This ignore will be removed when pycountry will drop py36 & support py311
'ignore:::pkg_resources',
# This ignore will be removed when pendulum fixes https://github.com/sdispater/pendulum/issues/834
'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning'
'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning',
' ignore:Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.:DeprecationWarning'
]

# configuring https://github.com/pydantic/hooky
Expand Down
12 changes: 7 additions & 5 deletions tests/test_semantic_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ class Application(BaseModel):
return Application


def test_valid_semantic_version(SemanticVersionObject):
application = SemanticVersionObject(version='1.0.0')
@pytest.mark.parametrize('version', ['1.0.0', '1.0.0-alpha.1', '1.0.0-alpha.1+build.1', '1.2.3'])
def test_valid_semantic_version(SemanticVersionObject, version):
application = SemanticVersionObject(version=version)
assert application.version
assert application.model_dump() == {'version': '1.0.0'}
assert application.model_dump() == {'version': version}


def test_invalid_semantic_version(SemanticVersionObject):
@pytest.mark.parametrize('invalid_version', ['no dots string', 'with.dots.string', ''])
def test_invalid_semantic_version(SemanticVersionObject, invalid_version):
with pytest.raises(ValidationError):
SemanticVersionObject(version='Peter Maffay')
SemanticVersionObject(version=invalid_version)
Loading