Package: awesomeversion
AwesomeVersionOne version package to rule them all, One version package to find them, One version package to bring them all, and in the darkness bind them.Make anything a version object, and compare against a vast section of other version formats.Installationpython3-mpipinstallawesomeversionAwesomeVersion classThe AwesomeVersion class takes a version as the first argument, you can also pass in additional kwargs to customize the version object.ArgumentDescriptionversionThe version string to parse.ensure_strategyMatch theAwesomeVersionobject against spesific strategies when creating if. If it does not matchAwesomeVersionStrategyExceptionwill be raisedfind_first_matchIf True, the version given will be scanned for the first match of the givenensure_strategy. RaisesAwesomeVersionStrategyExceptionIf it is not found for any of the given strategies.AwesomeVersion methodsAwesomeVersion.in_rangeThis is a helper method to check if the version is in a range.
This method takes two arguments,lowestandhighest, both are required, and returns a boolean.NoteThis method is the same as doinglowest <= AwesomeVersion <= highestExample:fromawesomeversionimportAwesomeVersionprint(AwesomeVersion("1.2.2").in_range("1.2.1","1.3"))>Trueprint(AwesomeVersion("1.2.0").in_range("1.2.1","1.3"))>FalseAwesomeVersion.diffThis is a helper method to get the difference between two versions.
This method takes one argument which is the version to compare against, and returns aAwesomeVersionDiffobject.NoteThis method is the same as doingAwesomeVersion - versionExample:fromawesomeversionimportAwesomeVersion>print(AwesomeVersion("1.0").diff("2.1"))AwesomeVersionDiff(major=True,minor=True,patch=False,modifier=False,strategy=False)AwesomeVersion.sectionThis is a helper method to get a section of the version.
This method takes one argument which is the section to get, and returns an integer representing it (or 0 if it does not exist).Example:fromawesomeversionimportAwesomeVersion>print(AwesomeVersion("1.0").section(0))1AwesomeVersion propertiesArgumentDescriptionalphaThis is a boolean representing if the version is an alpha version.betaThis is a boolean representing if the version is a beta version.devThis is a boolean representing if the version is a dev version.majorThis is anAwesomeVersionobject representing the major version orNoneif not present.microThis is anAwesomeVersionobject representing the micro version orNoneif not present.minorThis is anAwesomeVersionobject representing the minor version orNoneif not present.modifier_typeThis is a string representing the modifier type of the version orNoneif not present.modifierThis is a string representing the modifier of the version orNoneif not present.patchThis is anAwesomeVersionobject representing the patch version orNoneif not present.prefixThis is the prefix of the version orNoneif not present.release_candidateThis is a boolean representing if the version is a release candidate version.simpleThis is a boolean representing if the version is a simple version.strategy_descriptionThis is aAwesomeVersionStrategyDescriptionobject representing the strategy description of the version.strategyThis is aAwesomeVersionStrategyobject representing the strategy of the version.stringThis is the string representation of the version (without the v prefix if present).validThis is a boolean representing if the version is valid (not unknown strategy).yearThis is alias tomajor, and is anAwesomeVersionobject representing the year.Example usageHere are some examples of how you can use this package, more examples can be found in thetestsdirectory.Basic comparefromawesomeversionimportAwesomeVersioncurrent=AwesomeVersion("1.2.2")upstream=AwesomeVersion("1.2.3")print(upstream>current)>TrueCompare beta versionfromawesomeversionimportAwesomeVersioncurrent=AwesomeVersion("2021.1.0")upstream=AwesomeVersion("2021.1.0b2")print(current>upstream)>TrueCheck if version is a beta versionfromawesomeversionimportAwesomeVersionprint(AwesomeVersion("1.2.3b0").beta)>Trueprint(AwesomeVersion("1.2.3").beta)>FalseUseAwesomeVersionwithwith ...fromawesomeversionimportAwesomeVersionwithAwesomeVersion("20.12.0")ascurrent:withAwesomeVersion("20.12.1")asupstream:print(upstream>current)>TrueCompareAwesomeVersionwith other non-AwesomeVersionformatsfromawesomeversionimportAwesomeVersionbase=AwesomeVersion("20.12.0")print(base>"20.12.1")>Falseprint(base>"19")>Trueprint(base>5)>TrueGeneral behaviorYou can test your versions on thedemo page.ModifiersWhen comparing versions with modifiers, if the base version is the same the modifier will be used to determine the order.
If one of the versions do not have a modifier, the one without will be considered newer.The order of the modifiers are:No modifierRCBetaAlphaDevExamplesfromawesomeversionimportAwesomeVersionprint(AwesomeVersion("1.0.0")>AwesomeVersion("1.0.0b6"))>Trueprint(AwesomeVersion("1.0.0")>AwesomeVersion("1.0.0.dev6"))>Trueprint(AwesomeVersion("1.0.0.dev19")>AwesomeVersion("1.0.0b4"))>FalseSpecial versions (container)There are some special versions for container that are handled differently than typical version formats.
The special versions are in the following order:dev(newest)latestbetastable(oldest)If only the first version is this special version, it will be considered newer.
If only the second version is this special version, it will be considered older.ExamplesfromawesomeversionimportAwesomeVersionprint(AwesomeVersion("latest")>AwesomeVersion("1.0.0b6"))>Trueprint(AwesomeVersion("1.0.0")>AwesomeVersion("latest"))>Falseprint(AwesomeVersion("stable")>AwesomeVersion("latest"))>Falseprint(AwesomeVersion("beta")>AwesomeVersion("dev"))>FalseContributeAllcontributions are welcome!Fork the repositoryClone the repository locally and open the devcontainer or use GitHub codespacesDo your changesLint the files withmake lintEnsure all tests passes withmake testEnsure 100% coverage withmake coverageCommit your work, and push it to GitHubCreate a PR against themainbranch