semantic-version-tools 1.3.0__tar.gz → 1.4.0__tar.gz

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,137 @@
1
+ Metadata-Version: 2.3
2
+ Name: semantic-version-tools
3
+ Version: 1.4.0
4
+ Summary: Class to manage semantic versioning
5
+ Author: Romolo Politi
6
+ Author-email: romolo.politi@inaf.it
7
+ Requires-Python: >=3.10,<3.15
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 (>=80.9.0,<81.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 semantic-version-tools
37
+ ```
38
+ ### Using poetry
39
+
40
+ To add the package to your poetry project, you can run the command:
41
+
42
+ ```sh
43
+ poetry add semantic-versioning-tools
44
+ ```
45
+
46
+
47
+ ## Usage
48
+
49
+ To use the library it's necessary import the class *Vers*, than you can comapare or manipulate the version numbers.
50
+
51
+ ### Initialize and print version
52
+
53
+ ```python
54
+ >>> from semantic_version_tools import Vers
55
+
56
+ >>> main_ver=Vers('1.0')
57
+ >>> print(main_ver)
58
+
59
+ Version 1.0
60
+ ```
61
+
62
+ The version number could be a string or a tuple, whit 2 or 5 elements:
63
+ - the major version number
64
+ - the minor version number
65
+ - the patch number
66
+ - pre-release type
67
+ - build number
68
+
69
+ For the pre-release are used letters as reported below:
70
+
71
+ - **d**: developing version
72
+ - **a**: alpha release
73
+ - **b**: beta release
74
+ - **rc**: release candidate
75
+ - **f**: final release
76
+
77
+ ```python
78
+ >>> main_version = Vers((0,1,0,'d',1))
79
+ >>> print(main_version)
80
+
81
+ Version 0.1.0-devel.1
82
+
83
+ >>> main_version = Vers('0.1.0-a.1')
84
+ >>> print(main_version)
85
+
86
+ Version 0.1.0-alpha.1
87
+ ```
88
+
89
+ ### Compare versions
90
+
91
+ In the class Vers are implemented the main comparison operators.
92
+ For example:
93
+
94
+ ```python
95
+ >>> a=Vers('1.0.0')
96
+ >>> b=Vers('1.0.1')
97
+
98
+ >>> a>b
99
+ False
100
+ >>> a==b
101
+ False
102
+ >>> a<b
103
+ True
104
+ a<=b
105
+ True
106
+ ```
107
+
108
+ ### Sum and increase
109
+
110
+ It's possible sum tro version number or icrease it.
111
+
112
+ ```python
113
+ >>> a = Vers('1.0.0')
114
+ >>> b = Vers('1.0.1')
115
+ >>> c=a+b
116
+ >>> c
117
+ Version 2.0.1
118
+
119
+
120
+ >>> a = Vers('1.0.0')
121
+ >>> a=a+1
122
+ >>> a
123
+ Version 1.1.0
124
+ # equivalent to
125
+ >>> a +=1
126
+ >>> a
127
+ Version 1.1.0
128
+ ```
129
+
130
+ The summ add a minor version. To add a major version you must add a float
131
+
132
+ ```python
133
+ >>> a = Vers('1.0.0')
134
+ >>> a += 1.0
135
+ >>> a
136
+ Version 2.0.0
137
+ ```
@@ -0,0 +1,122 @@
1
+
2
+ # Version-Tools
3
+
4
+ ## Installation
5
+
6
+ ### From Repository
7
+
8
+ To install the Version-Tools package from the repository, run the following commands:
9
+
10
+ ```sh
11
+ git clone https://github.com/RomoloPoliti-INAF/version-tools.git
12
+ cd version-tools
13
+ poetry install
14
+ ```
15
+
16
+ ### From PyPi
17
+
18
+ To install the Version-Tools package from PyPi, run the following command:
19
+
20
+ ```sh
21
+ pip install semantic-version-tools
22
+ ```
23
+ ### Using poetry
24
+
25
+ To add the package to your poetry project, you can run the command:
26
+
27
+ ```sh
28
+ poetry add semantic-versioning-tools
29
+ ```
30
+
31
+
32
+ ## Usage
33
+
34
+ To use the library it's necessary import the class *Vers*, than you can comapare or manipulate the version numbers.
35
+
36
+ ### Initialize and print version
37
+
38
+ ```python
39
+ >>> from semantic_version_tools import Vers
40
+
41
+ >>> main_ver=Vers('1.0')
42
+ >>> print(main_ver)
43
+
44
+ Version 1.0
45
+ ```
46
+
47
+ The version number could be a string or a tuple, whit 2 or 5 elements:
48
+ - the major version number
49
+ - the minor version number
50
+ - the patch number
51
+ - pre-release type
52
+ - build number
53
+
54
+ For the pre-release are used letters as reported below:
55
+
56
+ - **d**: developing version
57
+ - **a**: alpha release
58
+ - **b**: beta release
59
+ - **rc**: release candidate
60
+ - **f**: final release
61
+
62
+ ```python
63
+ >>> main_version = Vers((0,1,0,'d',1))
64
+ >>> print(main_version)
65
+
66
+ Version 0.1.0-devel.1
67
+
68
+ >>> main_version = Vers('0.1.0-a.1')
69
+ >>> print(main_version)
70
+
71
+ Version 0.1.0-alpha.1
72
+ ```
73
+
74
+ ### Compare versions
75
+
76
+ In the class Vers are implemented the main comparison operators.
77
+ For example:
78
+
79
+ ```python
80
+ >>> a=Vers('1.0.0')
81
+ >>> b=Vers('1.0.1')
82
+
83
+ >>> a>b
84
+ False
85
+ >>> a==b
86
+ False
87
+ >>> a<b
88
+ True
89
+ a<=b
90
+ True
91
+ ```
92
+
93
+ ### Sum and increase
94
+
95
+ It's possible sum tro version number or icrease it.
96
+
97
+ ```python
98
+ >>> a = Vers('1.0.0')
99
+ >>> b = Vers('1.0.1')
100
+ >>> c=a+b
101
+ >>> c
102
+ Version 2.0.1
103
+
104
+
105
+ >>> a = Vers('1.0.0')
106
+ >>> a=a+1
107
+ >>> a
108
+ Version 1.1.0
109
+ # equivalent to
110
+ >>> a +=1
111
+ >>> a
112
+ Version 1.1.0
113
+ ```
114
+
115
+ The summ add a minor version. To add a major version you must add a float
116
+
117
+ ```python
118
+ >>> a = Vers('1.0.0')
119
+ >>> a += 1.0
120
+ >>> a
121
+ Version 2.0.0
122
+ ```
@@ -0,0 +1,33 @@
1
+ [project]
2
+ name = "semantic-version-tools"
3
+ version = "1.4.0"
4
+ description = "Class to manage semantic versioning"
5
+ authors = [
6
+ {name = "Romolo Politi",email = "romolo.politi@inaf.it"}
7
+ ]
8
+ readme = "README.md"
9
+ dependencies = [
10
+ "setuptools (>=80.9.0,<81.0.0)"
11
+ ]
12
+
13
+
14
+ [tool.poetry]
15
+ packages = [{include = "semantic_version_tools", from = "src"}]
16
+ include = ["CHANGELOG.md"]
17
+ name="semantic-version-tools"
18
+ version="1.3.1"
19
+ description="Class to manage semantic versioning"
20
+ authors = [
21
+ "Romolo Politi <romolo.politi@inaf.it>"
22
+ ]
23
+
24
+ [tool.poetry.dependencies]
25
+ python = ">=3.10, <3.15"
26
+
27
+
28
+ [tool.poetry.group.dev.dependencies]
29
+ pytest = "^8.3.4"
30
+
31
+ [build-system]
32
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
33
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1 @@
1
+ from semantic_version_tools.version import Vers
@@ -2,6 +2,7 @@
2
2
  import re
3
3
  from importlib.metadata import version
4
4
 
5
+
5
6
  ###################################
6
7
  # Versioning Class
7
8
  ###################################
@@ -11,16 +12,9 @@ from importlib.metadata import version
11
12
  #
12
13
  # The versioning is based on the Semantic Versioning 2.0.0
13
14
  #
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
15
 
21
16
 
22
- #__version__ = pkg_resources.get_distribution("version_tools").version
23
- __version__ = version('version_tools')
17
+ __version__ = version('semantic_version_tools')
24
18
 
25
19
  code = {"d": "devel", "a": "alpha", "b": "beta", "rc": "ReleaseCandidate", "f": "Final"}
26
20
 
@@ -47,12 +41,15 @@ class Vers:
47
41
  """
48
42
 
49
43
  def __init__(self, ver: tuple | str) -> None:
44
+
50
45
  if isinstance(ver, str):
51
46
  a = re.match(
52
47
  r"(\d+)\.(\d+)(?:\.(\d+))?(?:[-\.]([a-zA-Z]*)(?:\.?(\d+))?)?", ver
53
48
  )
54
49
  prt = list(a.groups())
55
- prt[0:3] = [int(i) for i in prt[0:3]]
50
+ prt[0:2] = [int(i) for i in prt[0:2]]
51
+ if prt[2] is not None:
52
+ prt[2] = int(prt[2])
56
53
  if prt[3] is not None:
57
54
  if prt[3].lower() in "development":
58
55
  prt[3] = "d"
@@ -65,12 +62,14 @@ class Vers:
65
62
  elif prt[3].lower() in "final":
66
63
  prt[3] = "f"
67
64
  else:
68
- prt[3] = "f"
65
+ prt[3] = None
69
66
  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
-
67
+ prt[4] = None
68
+ else:
69
+ if prt[3] is not None:
70
+ prt[4] = int(prt[4])
71
+ ver = tuple([x for x in prt if x is not None])
72
+ # print(ver)
74
73
  self._len = 3
75
74
  if len(ver) < 3:
76
75
  self.major, self.minor, *extra = ver
@@ -79,7 +78,7 @@ class Vers:
79
78
  else:
80
79
  self.major, self.minor, self.patch, *extra = ver
81
80
  # self.patch = extra[0] if extra else None
82
- self.type = extra[0] if len(extra) != 0 else None
81
+ self.type = extra[0] if len(extra) != 0 else 'f'
83
82
  if self.type is not None:
84
83
  if not isinstance(self.type, str):
85
84
  raise Exception(
@@ -90,7 +89,7 @@ class Vers:
90
89
  f"the fourth element of the version mus be one of {
91
90
  ','.join(code.keys())}"
92
91
  )
93
- self.build = extra[1] if len(extra) > 1 else None
92
+ self.build = extra[1] if len(extra) > 1 else 1
94
93
 
95
94
  def full(self) -> str:
96
95
  """
@@ -180,5 +179,20 @@ class Vers:
180
179
  else:
181
180
  return False
182
181
 
183
-
182
+ def __add__(self, other:"Vers") -> "Vers":
183
+
184
+ if isinstance(other,int):
185
+ self.minor += other
186
+
187
+ if isinstance(other,float):
188
+ a=str(other).split(".")
189
+ self.major += int(a[0])
190
+ self.minor += int(a[1])
191
+
192
+ if isinstance(other, Vers):
193
+ self.major += other.major
194
+ self.minor += other.minor
195
+ if self._len == 3:
196
+ self.patch += other.patch
197
+ return self
184
198
  # version = Vers(VERSION)
@@ -1,38 +0,0 @@
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
-
@@ -1,22 +0,0 @@
1
-
2
- # Version-Tools
3
-
4
- ## Installation
5
-
6
- ### From Repository
7
-
8
- To install the Version-Tools package from the repository, run the following commands:
9
-
10
- ```sh
11
- git clone https://github.com/RomoloPoliti-INAF/version-tools.git
12
- cd version-tools
13
- poetry install
14
- ```
15
-
16
- ### From PyPi
17
-
18
- To install the Version-Tools package from PyPi, run the following command:
19
-
20
- ```sh
21
- pip install version-tools
22
- ```
@@ -1,25 +0,0 @@
1
- [project]
2
- name = "semantic-version-tools"
3
- version = "1.3.0"
4
- description = ""
5
- authors = [
6
- {name = "Romolo Politi",email = "romolo.politi@inaf.it"}
7
- ]
8
- readme = "README.md"
9
- requires-python = ">=3.10, <3.14"
10
- dependencies = [
11
- "setuptools (>=75.8.0,<76.0.0)"
12
- ]
13
-
14
-
15
- [tool.poetry]
16
- packages = [{include = "version_tools", from = "src"}]
17
- include = ["CHANGELOG.md"]
18
-
19
-
20
- [tool.poetry.group.dev.dependencies]
21
- pytest = "^8.3.4"
22
-
23
- [build-system]
24
- requires = ["poetry-core>=2.0.0,<3.0.0"]
25
- build-backend = "poetry.core.masonry.api"
@@ -1 +0,0 @@
1
- from version_tools.version import Vers