Skip to content

Commit

Permalink
Add: Introduce an abstract base class for a VersioningScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks authored and y0urself committed Mar 14, 2023
1 parent 88758e1 commit 743ad38
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/pontos/version/scheme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# pontos.version.scheme package

```{eval-rst}
.. automodule:: pontos.version.scheme
:members:
```
21 changes: 21 additions & 0 deletions pontos/version/scheme/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2023 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from ._scheme import VersioningScheme
from ._semantic import SemanticVersioningScheme

__all__ = ("VersioningScheme",)
71 changes: 71 additions & 0 deletions pontos/version/scheme/_scheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (C) 2023 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from abc import ABC
from typing import Type

from ..calculator import VersionCalculator
from ..version import Version


class VersioningScheme(ABC):
"""
An abstract base class for versioning schemes
Example:
Example on how to implement a new VersioningScheme
.. code-block:: python
from pontos.version.scheme import VersioningScheme
class MyVersioningScheme(VersioningScheme):
version_cls = MyVersion
version_calculator_cls = MyVersionCalculator
"""

version_cls: Type[Version]
version_calculator_cls: Type[VersionCalculator]

@classmethod
def parse_version(cls, version: str) -> Version:
"""
Parse a version from a version string
Raises:
:py:class:`pontos.version.error.VersionError`: If the version
string contains an invalid version
Returns:
A version instance
"""
return cls.version_cls.from_string(version)

@classmethod
def from_version(cls, version: Version) -> Version:
return cls.version_cls.from_version(version)

@classmethod
def calculator(cls) -> Type[VersionCalculator]:
"""
Return a matching version calculator for the implemented versioning
schema.
Returns:
A version calculator
"""
return cls.version_calculator_cls

0 comments on commit 743ad38

Please sign in to comment.