Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 20f2f6f
Showing
6 changed files
with
928 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/* | ||
*.egg-info/* | ||
build/* | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
|
||
## [0.1.0] - 19-02-10 | ||
### Added | ||
+ csemver class | ||
+ Docstrings for `number`,`incMajor, incMinor, incPatch` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# csemver | ||
csemver is the object orientied optimized Version of semver. It is much more consistent because you only need one object for all operations. | ||
|
||
## Features | ||
### Increase Versions | ||
To increase the different versions **csemver** provides three methods | ||
- incMajor | ||
- incMinor | ||
- incPatch | ||
|
||
```python | ||
from csemver import csemver as Version | ||
a = Version(); | ||
print(a) | ||
a.incMajor(); | ||
print(a) | ||
a.incMinor(); | ||
print(a) | ||
a.incPatch(); | ||
print(a) | ||
``` | ||
|
||
```console | ||
foo@bar:~$ python test.py | ||
0.1.0 | ||
1.0.0 | ||
1.1.0 | ||
1.1.1 | ||
``` | ||
|
||
### Overwrite Version | ||
To overwrite the current Version just set a new **Semver-String** for `csemver.number` | ||
```python | ||
from csemver import csemver as Version | ||
a = Version(); | ||
print(a) | ||
a.number ="1.0.0-pre+build.1"; | ||
print(a) | ||
``` | ||
```bash | ||
foo@bar:~$ python test.py | ||
0.1.0 | ||
1.0.0-pre+build.1 | ||
``` | ||
### Reset Version | ||
Delete the `number` property to reset the Version to `0.1.0` | ||
```python | ||
from csemver import csemver as Version | ||
a = Version("1.0.0"); | ||
print(a) | ||
del a.number | ||
print(a) | ||
``` | ||
|
||
```bash | ||
foo@bar:~$ python test.py | ||
1.0.0 | ||
0.1.0 | ||
``` | ||
|
||
### Compare different versions: | ||
You can compare **csemver** instances with `>, >=, ==, !=, <=, <` | ||
```python | ||
from csemver import csemver as Version | ||
|
||
a = Version("1.1.1") | ||
b = Version("1.1.1") | ||
repr(a) | ||
repr(b) | ||
print(a<b) | ||
|
||
b.incPatch() | ||
print(b) | ||
print(a<b) | ||
``` | ||
|
||
```bash | ||
foo@bar:~$ python test.py | ||
Version<1.1.1> instance at 0x00000159D2061BA8 | ||
Version<1.1.1> instance at 0x00000159D2061DD8 | ||
False | ||
1.1.2 | ||
True | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import semver as sv; | ||
import copy | ||
__author__ = "Sebastian Tilders" | ||
__version__ = "0.1.0" | ||
|
||
class csemver: | ||
""" Representation of an semantic software version """ | ||
|
||
__slots__ = ['major', 'minor', 'patch', 'prerelease', 'build', '_version', '_vInfo']; | ||
def __init__(self, version:str = "0.1.0"): | ||
""" Initialises a new Version instance""" | ||
self._version = sv.parse(version); | ||
self._updateVI(); | ||
|
||
@property | ||
def number(self): | ||
""" | ||
Propery which contains directory for the current version. | ||
Delete this property to reset the version to 0.1.0 | ||
""" | ||
return self._version; | ||
|
||
@number.setter | ||
def number(self,value): | ||
""" Setter for the version number """ | ||
self._version = sv.parse(value); | ||
self._updateVI(); | ||
|
||
@number.deleter | ||
def number(self): | ||
""" Resets version number to 0.1.0 """ | ||
self._version = sv.parse("0.1.0"); | ||
self._updateVI(); | ||
|
||
def incPatch(self, incBy:int=1): | ||
""" Increase patch version x.y.z -> x.y.(z+incBy) """ | ||
verStr = self._bumpN(sv.bump_patch, incBy); | ||
self._version = sv.parse(verStr); | ||
self._updateVI(); | ||
return self; | ||
|
||
def incMinor(self,incBy:int=1): | ||
""" Increase minor version x.y.z -> x.(y+incBy).0 """ | ||
verStr = self._bumpN(sv.bump_minor,incBy); | ||
self._version = sv.parse(verStr); | ||
self._updateVI(); | ||
return self; | ||
|
||
def incMajor(self, incBy:int=1): | ||
""" Increase major version x.y.z -> (x+incBy).0.0 """ | ||
verStr = self._bumpN(sv.bump_major, incBy); | ||
self._version = sv.parse(verStr); | ||
self._updateVI(); | ||
return self; | ||
|
||
def __getitem__(self, key): | ||
""" Returns either major, minor, patch, prerelease or build """ | ||
return self._version[key]; | ||
|
||
def __str__(self): | ||
""" Returns a string representation of the semantic version """ | ||
return sv.format_version(self._version['major'], self._version['minor'], self._version['patch'], self._version['prerelease'], self._version['build']); | ||
|
||
def _convertToVersion(self, val): | ||
return sv.VersionInfo(self._version['major'], self._version['minor'], self._version['patch'], self._version['prerelease'], self._version['build']); | ||
|
||
def _updateVI(self): | ||
self._vInfo = self._convertToVersion(self._version); | ||
|
||
def _bumpN(self, func, incBy): | ||
verStr = str(self); | ||
for i in range(0, incBy): | ||
verStr = func(verStr); | ||
return verStr; | ||
|
||
def __eq__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo == value._vInfo; | ||
|
||
def __gt__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo > value._vInfo; | ||
|
||
def __lt__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo < value._vInfo; | ||
|
||
def __le__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo <= value._vInfo; | ||
|
||
def __ge__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo >= value._vInfo; | ||
|
||
def __ne__(self, value): | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
return self._vInfo != value._vInfo; | ||
|
||
def __add__(self, value): | ||
""" | ||
Suppports addition of versions. The addition respects the semver rules | ||
""" | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
newV = copy.deepcopy(self); | ||
newV.incMajor(value['major']); | ||
newV.incMinor(value['minor']); | ||
newV.incPatch(value['patch']); | ||
return newV; | ||
|
||
def __iadd__(self, value): | ||
""" | ||
Suppports addition + assignment of versions. The addition respects the semver rules | ||
""" | ||
if not isinstance(value,csemver): | ||
raise TypeError("This type combination is not supported!"); | ||
self.incMajor(value['major']); | ||
self.incMinor(value['minor']); | ||
self.incPatch(value['patch']); | ||
return self; | ||
|
||
def __repr__(self): | ||
return "{:}<{:}> instance at 0x{:016X}".format(self.__class__.__name__,self.__str__(), id(self)); | ||
|
||
def parse(version): | ||
return csemver(version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import setuptools | ||
with open("README.md") as f: | ||
long_description = f.read(); | ||
|
||
setuptools.setup( | ||
name='csemver', | ||
version='0.1.0', | ||
platforms='any', | ||
description='Object orientied optimized variant of the semver package', | ||
author='Sebastian Tilders', | ||
author_email='info@informatikonline.net', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
license='GPL3', | ||
url='http://www.github.com/sebi2020/csemver', | ||
install_requires = ['semver'], | ||
py_modules = ['csemver'], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
"Operating System :: OS Independent", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Topic :: Software Development :: Libraries", | ||
"Topic :: Software Development :: Version Control" | ||
] | ||
); |