semantic-version-tools 1.3.0__tar.gz → 1.3.3__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,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: semantic-version-tools
3
+ Version: 1.3.3
4
+ Summary: Class to manage semantic versioning
5
+ Author: Romolo Politi
6
+ Author-email: romolo.politi@inaf.it
7
+ Requires-Python: >=3.10,<4.0
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
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: setuptools (>=80.9.0,<81.0.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+
18
+ # Version-Tools
19
+
20
+ ## Installation
21
+
22
+ ### From Repository
23
+
24
+ To install the Version-Tools package from the repository, run the following commands:
25
+
26
+ ```sh
27
+ git clone https://github.com/RomoloPoliti-INAF/version-tools.git
28
+ cd version-tools
29
+ poetry install
30
+ ```
31
+
32
+ ### From PyPi
33
+
34
+ To install the Version-Tools package from PyPi, run the following command:
35
+
36
+ ```sh
37
+ pip install semantic-version-tools
38
+ ```
39
+ ### Using poetry
40
+
41
+ To add the package to your poetry project, you can run the command:
42
+
43
+ ```sh
44
+ poetry add semantic-versioning-tools
45
+ ```
46
+
47
+
48
+ ## Usage
49
+
50
+ To use the library it's necessary import the class *Vers*, than you can comapare or manipulate the version numbers.
51
+
52
+ ### Initialize and print version
53
+
54
+ ```python
55
+ >>> from semantic_version_tools import Vers
56
+
57
+ >>> main_ver=Vers('1.0')
58
+ >>> print(main_ver)
59
+
60
+ Version 1.0
61
+ ```
62
+
63
+ The version number could be a string or a tuple, whit 2 or 5 elements:
64
+ - the major version number
65
+ - the minor version number
66
+ - the patch number
67
+ - pre-release type
68
+ - build number
69
+
70
+ For the pre-release are used letters as reported below:
71
+
72
+ - **d**: developing version
73
+ - **a**: alpha release
74
+ - **b**: beta release
75
+ - **rc**: release candidate
76
+ - **f**: final release
77
+
78
+ ```python
79
+ >>> main_version = Vers((0,1,0,'d',1))
80
+ >>> print(main_version)
81
+
82
+ Version 0.1.0-devel.1
83
+
84
+ >>> main_version = Vers('0.1.0-a.1')
85
+ >>> print(main_version)
86
+
87
+ Version 0.1.0-alpha.1
88
+ ```
89
+
90
+ ### Compare versions
91
+
92
+ In the class Vers are implemented the main comparison operators.
93
+ For example:
94
+
95
+ ```python
96
+ >>> a=Vers('1.0.0')
97
+ >>> b=Vers('1.0.1')
98
+
99
+ >>> a>b
100
+ False
101
+ >>> a==b
102
+ False
103
+ >>> a<b
104
+ True
105
+ a<=b
106
+ True
107
+ ```
108
+
109
+ ### Sum and increase
110
+
111
+ It's possible sum tro version number or icrease it.
112
+
113
+ ```python
114
+ >>> a = Vers('1.0.0')
115
+ >>> b = Vers('1.0.1')
116
+ >>> c=a+b
117
+ >>> c
118
+ Version 2.0.1
119
+
120
+
121
+ >>> a = Vers('1.0.0')
122
+ >>> a=a+1
123
+ >>> a
124
+ Version 1.1.0
125
+ # equivalent to
126
+ >>> a +=1
127
+ >>> a
128
+ Version 1.1.0
129
+ ```
130
+
131
+ The summ add a minor version. To add a major version you must add a float
132
+
133
+ ```python
134
+ >>> a = Vers('1.0.0')
135
+ >>> a += 1.0
136
+ >>> a
137
+ Version 2.0.0
138
+ ```
@@ -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
+ ```
@@ -1,20 +1,22 @@
1
1
  [project]
2
2
  name = "semantic-version-tools"
3
- version = "1.3.0"
4
- description = ""
3
+ version = "1.3.3"
4
+ description = "Class to manage semantic versioning"
5
5
  authors = [
6
6
  {name = "Romolo Politi",email = "romolo.politi@inaf.it"}
7
7
  ]
8
8
  readme = "README.md"
9
- requires-python = ">=3.10, <3.14"
9
+
10
+
11
+ requires-python = ">=3.10,<4.0"
10
12
  dependencies = [
11
- "setuptools (>=75.8.0,<76.0.0)"
13
+ "setuptools (>=80.9.0,<81.0.0)"
12
14
  ]
13
15
 
14
16
 
15
17
  [tool.poetry]
16
- packages = [{include = "version_tools", from = "src"}]
17
- include = ["CHANGELOG.md"]
18
+ packages = [{include = "semantic_version_tools", from = "src"}]
19
+
18
20
 
19
21
 
20
22
  [tool.poetry.group.dev.dependencies]
@@ -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 +0,0 @@
1
- from version_tools.version import Vers