semantic-version-tools 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.3
2
+ Name: semantic-version-tools
3
+ Version: 1.3.0
4
+ Summary:
5
+ Author: Romolo Politi
6
+ Author-email: romolo.politi@inaf.it
7
+ Requires-Python: >=3.10, <3.14
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: setuptools (>=75.8.0,<76.0.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+
17
+ # Version-Tools
18
+
19
+ ## Installation
20
+
21
+ ### From Repository
22
+
23
+ To install the Version-Tools package from the repository, run the following commands:
24
+
25
+ ```sh
26
+ git clone https://github.com/RomoloPoliti-INAF/version-tools.git
27
+ cd version-tools
28
+ poetry install
29
+ ```
30
+
31
+ ### From PyPi
32
+
33
+ To install the Version-Tools package from PyPi, run the following command:
34
+
35
+ ```sh
36
+ pip install version-tools
37
+ ```
38
+
@@ -0,0 +1,5 @@
1
+ version_tools/__init__.py,sha256=uUtTvHDzsFj0I5Dn-og4i4JNHu8KvzUZsTaS-7MHCPE,38
2
+ version_tools/version.py,sha256=5fUubvHl30bpcV0Rh5Kkl-T4-MJNZ_52geEAzA--lbM,5796
3
+ semantic_version_tools-1.3.0.dist-info/METADATA,sha256=wix3r0ipLjA7pVRiY17bJX7Xorw4YOMYJ9H6ct2BBEQ,882
4
+ semantic_version_tools-1.3.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
5
+ semantic_version_tools-1.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1 @@
1
+ from version_tools.version import Vers
@@ -0,0 +1,184 @@
1
+
2
+ import re
3
+ from importlib.metadata import version
4
+
5
+ ###################################
6
+ # Versioning Class
7
+ ###################################
8
+ #
9
+ # This class is used to manage the versioning of the
10
+ # software or other products
11
+ #
12
+ # The versioning is based on the Semantic Versioning 2.0.0
13
+ #
14
+ # History:
15
+ #
16
+ # 2025-02-25: Moved to standalone module (1.3.0)
17
+ # 2024-11-18: accept string as imput (1.2.0)
18
+ # 2024-10-04: The patch is now not mandatory (1.1.0)
19
+ # 2021-09-07: First implementation of the class (1.0.0)
20
+
21
+
22
+ #__version__ = pkg_resources.get_distribution("version_tools").version
23
+ __version__ = version('version_tools')
24
+
25
+ code = {"d": "devel", "a": "alpha", "b": "beta", "rc": "ReleaseCandidate", "f": "Final"}
26
+
27
+ numeric_map = {"d": 1, "a": 2, "b": 3, "rc": 4, "f": 5}
28
+
29
+
30
+ class Vers:
31
+ """
32
+ Class for the manipulation of objects version following the Semantic Versioning
33
+
34
+ major.minor.patch-<prerel>.<build>
35
+
36
+ Is implemented a special dialect.
37
+
38
+
39
+
40
+ The admitted pre-release values are
41
+
42
+ * d for the developing version
43
+ * a for the alpha version
44
+ * b for the beta version
45
+ * rc for the release candidate
46
+ * f for the final version
47
+ """
48
+
49
+ def __init__(self, ver: tuple | str) -> None:
50
+ if isinstance(ver, str):
51
+ a = re.match(
52
+ r"(\d+)\.(\d+)(?:\.(\d+))?(?:[-\.]([a-zA-Z]*)(?:\.?(\d+))?)?", ver
53
+ )
54
+ prt = list(a.groups())
55
+ prt[0:3] = [int(i) for i in prt[0:3]]
56
+ if prt[3] is not None:
57
+ if prt[3].lower() in "development":
58
+ prt[3] = "d"
59
+ elif prt[3].lower() in "alpha":
60
+ prt[3] = "a"
61
+ elif prt[3].lower() in "beta":
62
+ prt[3] = "b"
63
+ elif prt[3].lower() in "releasecandidate":
64
+ prt[3] = "rc"
65
+ elif prt[3].lower() in "final":
66
+ prt[3] = "f"
67
+ else:
68
+ prt[3] = "f"
69
+ if prt[3] is not None and prt[4] is None:
70
+ prt[4] = 1
71
+ prt[4] = int(prt[4])
72
+ ver = tuple(prt)
73
+
74
+ self._len = 3
75
+ if len(ver) < 3:
76
+ self.major, self.minor, *extra = ver
77
+ self.patch = 0
78
+ self._len = 2
79
+ else:
80
+ self.major, self.minor, self.patch, *extra = ver
81
+ # self.patch = extra[0] if extra else None
82
+ self.type = extra[0] if len(extra) != 0 else None
83
+ if self.type is not None:
84
+ if not isinstance(self.type, str):
85
+ raise Exception(
86
+ f"The fourth element of the version number must be a string"
87
+ )
88
+ if not self.type in code.keys():
89
+ raise ValueError(
90
+ f"the fourth element of the version mus be one of {
91
+ ','.join(code.keys())}"
92
+ )
93
+ self.build = extra[1] if len(extra) > 1 else None
94
+
95
+ def full(self) -> str:
96
+ """
97
+ Return the full version
98
+
99
+ Returns:
100
+ str: the version string
101
+ """
102
+ if self.type is None or self.type.lower() == "f":
103
+ nVer = f"{self.major}.{self.minor}{
104
+ f'.{self.patch}' if self._len == 3 else ''}"
105
+ # elif:
106
+ # nVer = f"{self.major}.{self.minor}.{self.patch}"
107
+ else:
108
+ nVer = f"{self.major}.{self.minor}.{
109
+ self.patch}-{code[self.type]}.{self.build}"
110
+ return nVer
111
+
112
+ def short(self) -> str:
113
+ """
114
+ Return the version in the form major.minor.patch
115
+
116
+ Returns:
117
+ str: the version string
118
+ """
119
+ return f"{self.major}.{self.minor}{f'.{self.patch}' if self._len==3 else ''}"
120
+
121
+ def __repr__(self) -> str:
122
+ return f"Version {self.full()}"
123
+
124
+ def __str__(self) -> str:
125
+ return f"Version {self.full()}"
126
+
127
+ def __eq__(self, other) -> bool:
128
+ if (
129
+ self.major == other.major
130
+ and self.minor == other.minor
131
+ and self.patch == other.patch
132
+ ):
133
+ if self.type is None:
134
+ return True
135
+ else:
136
+ if self.type == other.type and self.build == other.build:
137
+ return True
138
+ else:
139
+ return False
140
+ else:
141
+ return False
142
+ # return all(getattr(self, item) == getattr(other, item) for item in self.__dict__ if not item.startswith('_'))
143
+
144
+ def __ne__(self, other) -> bool:
145
+ return not self == other
146
+
147
+ def __gt__(self, other) -> bool:
148
+ if self.major != other.major:
149
+ return self.major > other.major
150
+ elif self.minor != other.minor:
151
+ return self.minor > other.minor
152
+ elif self.patch != other.patch:
153
+ return self.patch > other.patch
154
+ elif numeric_map[self.type] != numeric_map[other.type]:
155
+ return numeric_map[self.type] > numeric_map[other.type]
156
+ else:
157
+ return self.build > other.build
158
+
159
+ def __ge__(self, other) -> bool:
160
+ if self > other or self == other:
161
+ return True
162
+ else:
163
+ return False
164
+
165
+ def __lt__(self, other) -> bool:
166
+ if self.major != other.major:
167
+ return self.major < other.major
168
+ elif self.minor != other.minor:
169
+ return self.minor < other.minor
170
+ elif self.patch != other.patch:
171
+ return self.patch < other.patch
172
+ elif numeric_map[self.type] != numeric_map[other.type]:
173
+ return numeric_map[self.type] < numeric_map[other.type]
174
+ else:
175
+ return self.build < other.build
176
+
177
+ def __le__(self, other) -> bool:
178
+ if self < other or self == other:
179
+ return True
180
+ else:
181
+ return False
182
+
183
+
184
+ # version = Vers(VERSION)