Skip to content

Commit 743ad38

Browse files
bjoernricksy0urself
authored andcommitted
Add: Introduce an abstract base class for a VersioningScheme
1 parent 88758e1 commit 743ad38

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

docs/pontos/version/scheme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# pontos.version.scheme package
2+
3+
```{eval-rst}
4+
.. automodule:: pontos.version.scheme
5+
:members:
6+
```

pontos/version/scheme/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2023 Greenbone Networks GmbH
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
from ._scheme import VersioningScheme
19+
from ._semantic import SemanticVersioningScheme
20+
21+
__all__ = ("VersioningScheme",)

pontos/version/scheme/_scheme.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (C) 2023 Greenbone Networks GmbH
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
from abc import ABC
19+
from typing import Type
20+
21+
from ..calculator import VersionCalculator
22+
from ..version import Version
23+
24+
25+
class VersioningScheme(ABC):
26+
"""
27+
An abstract base class for versioning schemes
28+
29+
Example:
30+
Example on how to implement a new VersioningScheme
31+
32+
.. code-block:: python
33+
34+
from pontos.version.scheme import VersioningScheme
35+
36+
class MyVersioningScheme(VersioningScheme):
37+
version_cls = MyVersion
38+
version_calculator_cls = MyVersionCalculator
39+
"""
40+
41+
version_cls: Type[Version]
42+
version_calculator_cls: Type[VersionCalculator]
43+
44+
@classmethod
45+
def parse_version(cls, version: str) -> Version:
46+
"""
47+
Parse a version from a version string
48+
49+
Raises:
50+
:py:class:`pontos.version.error.VersionError`: If the version
51+
string contains an invalid version
52+
53+
Returns:
54+
A version instance
55+
"""
56+
return cls.version_cls.from_string(version)
57+
58+
@classmethod
59+
def from_version(cls, version: Version) -> Version:
60+
return cls.version_cls.from_version(version)
61+
62+
@classmethod
63+
def calculator(cls) -> Type[VersionCalculator]:
64+
"""
65+
Return a matching version calculator for the implemented versioning
66+
schema.
67+
68+
Returns:
69+
A version calculator
70+
"""
71+
return cls.version_calculator_cls

0 commit comments

Comments
 (0)