Package: semvercomp
semvercomp🐍 Semantic Version Comparison for PythonImplementation of aVersionobject with comparison capabilities and tag validation followingsemverconventions.InstallationpipinstallsemvercompUsageClassesVersionComparison of Version ObjectsEqualGreaterLowerValidationvalidate_versionUtilsto_version_listClassesVersion(major=0 : int, minor=0 : int, patch=0 : int, pre_release="" : str, patch="" : str, has_v=False : str)ClassVersionrepresents a version tag followingsemverconventions.
A version tag is structured the following way:X.Y.Z-pre+buildValueNameDescriptionXMajorVersion when you make incompatible API changesYMinorVersion when you add functionality in a backwards-compatible mannerZPatchVersion when you make backwards-compatible bug fixesprePre ReleaseVersionpre-releasetagbuildBuildVersionbuildtagSource:Semantic Versioning 2.0.0Public PropertiesKeyValueTypehas_vboolFlag for precedingvorVin version tagmajorintMajor memberminorintMinor memberpatchintPatch memberpre_releasestrPre Release memberbuildstrBuild memberInstance of Versionfromsemvercomp.VersionimportVersionver=Version(1,0,0,'beta','20191224')print(str(ver))# 1.0.0-beta+20191224Creating a Version object from a version string:fromsemvercomp.VersionimportVersionstr_v=Version()str_v.parse_version_number('v1.0.0-beta')# str_v.major == 1# str_v.minor == 0# str_v.patch == 0# str_v.has_v == True# str_v.pre_release == 'beta'Comparison of Version ObjectsVersionclass implements__gt__,__lt__and__eq__built-in methods to implement comparison.Equalfromsemvercomp.VersionimportVersiona=Version(1,0,0)b=Version(1,0,0)print(a==b)# TrueGreaterfromsemvercomp.VersionimportVersiona=Version(1,1,0)b=Version(1,0,0)print(a>b)# TrueLowerfromsemvercomp.VersionimportVersiona=Version(0,1,0)b=Version(1,0,0)print(a<b)# TrueValidationIt is possible to validate and gather the different members of a version tag usingvalidate versionfromsemvercomp.validators.validate_version(version: str): (parts: dict(), is_ok: bool)Will return a tuple where, the first element is a dictionary with the properties of the given version tag destructured.The second element in the tuple is a boolean flag that stands as the validation result.fromsemvercomp.validatorsimportvalidate_versionver_str='v1.0.22'(parts,is_ok)=validate_version(ver_str)print(parts)# {'has_v': True, 'major': 1, 'minor': 0, 'patch': 22, 'pre_release': None, 'build': None}print(is_ok)# TrueUtilsto_version_list(coll: iterable): Version[]Create an array of Version objects from an iterable of version tags as strings.fromsemvercomp.utilsimportto_version_listall=['1.0.0-beta','0.1.0+1234','33.22.3']versions=to_version_list(all)DevelopmentRequirementspyenvpipenvVisual Studio CodeRecommendedDebuggingDebugging tests
Tests for this package are written withpytest.
The following json, is an example of the.vscode/settings.json:{"python.pythonPath":/* Your Python Binary Address*/,"python.testing.pytestArgs":["tests"],"python.testing.unittestEnabled":false,"python.testing.nosetestsEnabled":false,"python.testing.pytestEnabled":true}TestingRunning unit tests# from repository root directorypytestRunning test coverage# from repository root directorypytest--cov=semvercomptests/# or with html reportpytest--cov-reporthtml--cov=semvercomptests/