One 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.
Project description
AwesomeVersion
One 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.
Installation
python3 -m pip install awesomeversion
Development
Note
Development is only supported inside the provided devcontainer (such as GitHub Codespaces or VS Code Remote - Containers). Other local or system Python environments are not supported for development or contribution. All scripts and workflows assume the devcontainer environment.
This project uses the "Scripts to Rule Them All" pattern for development tasks:
# Set up the project for development
./script/setup
# Run tests
./script/test
# Run linting and formatting
./script/lint
# Run coverage
./script/coverage
When using the devcontainer or GitHub Codespaces, a welcome message with available scripts is automatically displayed on startup.
AwesomeVersion class
The AwesomeVersion class takes a version as the first argument, you can also pass in additional kwargs to customize the version object.
| Argument | Description |
|---|---|
version |
The version string to parse. |
ensure_strategy |
Match the AwesomeVersion object against spesific strategies when creating if. If it does not match AwesomeVersionStrategyException will be raised |
find_first_match |
If True, the version given will be scanned for the first match of the given ensure_strategy. Raises AwesomeVersionStrategyException If it is not found for any of the given strategies. |
AwesomeVersion methods
AwesomeVersion.in_range
This is a helper method to check if the version is in a range.
This method takes two arguments, lowest and highest, both are required, and returns a boolean.
Note This method is the same as doing
lowest <= AwesomeVersion <= highest
Example:
from awesomeversion import AwesomeVersion
print(AwesomeVersion("1.2.2").in_range("1.2.1", "1.3"))
> True
print(AwesomeVersion("1.2.0").in_range("1.2.1", "1.3"))
> False
AwesomeVersion.diff
This 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 a AwesomeVersionDiff object.
Note This method is the same as doing
AwesomeVersion - version
Example:
from awesomeversion import AwesomeVersion
> print(AwesomeVersion("1.0").diff("2.1"))
AwesomeVersionDiff(major=True, minor=True, patch=False, modifier=False, strategy=False)
AwesomeVersion.section
This 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:
from awesomeversion import AwesomeVersion
> print(AwesomeVersion("1.0").section(0))
1
AwesomeVersion properties
| Argument | Description |
|---|---|
alpha |
This is a boolean representing if the version is an alpha version. |
beta |
This is a boolean representing if the version is a beta version. |
dev |
This is a boolean representing if the version is a dev version. |
major |
This is an AwesomeVersion object representing the major version or None if not present. |
micro |
This is an AwesomeVersion object representing the micro version or None if not present. |
minor |
This is an AwesomeVersion object representing the minor version or None if not present. |
modifier_type |
This is a string representing the modifier type of the version or None if not present. |
modifier |
This is a string representing the modifier of the version or None if not present. |
patch |
This is an AwesomeVersion object representing the patch version or None if not present. |
prefix |
This is the prefix of the version or None if not present. |
release_candidate |
This is a boolean representing if the version is a release candidate version. |
simple |
This is a boolean representing if the version is a simple version. |
strategy_description |
This is a AwesomeVersionStrategyDescription object representing the strategy description of the version. |
strategy |
This is a AwesomeVersionStrategy object representing the strategy of the version. |
string |
This is the string representation of the version (without the v prefix if present). |
valid |
This is a boolean representing if the version is valid (not unknown strategy). |
year |
This is alias to major, and is an AwesomeVersion object representing the year. |
Example usage
Here are some examples of how you can use this package, more examples can be found in the tests directory.
Basic compare
from awesomeversion import AwesomeVersion
current = AwesomeVersion("1.2.2")
upstream = AwesomeVersion("1.2.3")
print(upstream > current)
> True
Compare beta version
from awesomeversion import AwesomeVersion
current = AwesomeVersion("2021.1.0")
upstream = AwesomeVersion("2021.1.0b2")
print(current > upstream)
> True
Check if version is a beta version
from awesomeversion import AwesomeVersion
print(AwesomeVersion("1.2.3b0").beta)
> True
print(AwesomeVersion("1.2.3").beta)
> False
Use AwesomeVersion with with ...
from awesomeversion import AwesomeVersion
with AwesomeVersion("20.12.0") as current:
with AwesomeVersion("20.12.1") as upstream:
print(upstream > current)
> True
Compare AwesomeVersion with other non-AwesomeVersion formats
from awesomeversion import AwesomeVersion
base = AwesomeVersion("20.12.0")
print(base > "20.12.1")
> False
print(base > "19")
> True
print(base > 5)
> True
General behavior
You can test your versions on the demo page.
Modifiers
When 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 modifier
- RC
- Beta
- Alpha
- Dev
Examples
from awesomeversion import AwesomeVersion
print(AwesomeVersion("1.0.0") > AwesomeVersion("1.0.0b6"))
> True
print(AwesomeVersion("1.0.0") > AwesomeVersion("1.0.0.dev6"))
> True
print(AwesomeVersion("1.0.0.dev19") > AwesomeVersion("1.0.0b4"))
> False
Special 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.
Examples
from awesomeversion import AwesomeVersion
print(AwesomeVersion("latest") > AwesomeVersion("1.0.0b6"))
> True
print(AwesomeVersion("1.0.0") > AwesomeVersion("latest"))
> False
print(AwesomeVersion("stable") > AwesomeVersion("latest"))
> False
print(AwesomeVersion("beta") > AwesomeVersion("dev"))
> False
Contribute
All contributions are welcome!
- Fork the repository
- Clone the repository locally and open the devcontainer or use GitHub codespaces
- Do your changes
- Lint the files with
script/lint - Ensure all tests passes with
script/test - Ensure 100% coverage with
script/coverage - Commit your work, and push it to GitHub
- Create a PR against the
mainbranch
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awesomeversion-25.8.0.tar.gz.
File metadata
- Download URL: awesomeversion-25.8.0.tar.gz
- Upload date:
- Size: 70.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6cd08c90292a11f30b8de401863dcde7bc66a671d8173f9066ebd15d9310453
|
|
| MD5 |
62e9715757b58286f257471ab6b1eaf4
|
|
| BLAKE2b-256 |
4e3ac97ef69b8209aa9d7209b143345fe49c1e20126f62a775038ab6dcd78fd5
|
Provenance
The following attestation bundles were made for awesomeversion-25.8.0.tar.gz:
Publisher:
release.yml on ludeeus/awesomeversion
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awesomeversion-25.8.0.tar.gz -
Subject digest:
e6cd08c90292a11f30b8de401863dcde7bc66a671d8173f9066ebd15d9310453 - Sigstore transparency entry: 345674507
- Sigstore integration time:
-
Permalink:
ludeeus/awesomeversion@88a09dd69d61d836fedb025b07efca38a2e82f50 -
Branch / Tag:
refs/tags/25.8.0 - Owner: https://github.com/ludeeus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88a09dd69d61d836fedb025b07efca38a2e82f50 -
Trigger Event:
release
-
Statement type:
File details
Details for the file awesomeversion-25.8.0-py3-none-any.whl.
File metadata
- Download URL: awesomeversion-25.8.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c314683abfcc3e26c62af9e609b585bbcbf2ec19568df2f60ff1034fb1dae28
|
|
| MD5 |
f3e0e904456cd25a9e71c2f90772fc08
|
|
| BLAKE2b-256 |
99b3c6be343010721bfdd3058b708eb4868fa1a207534a3b6c80de74d35fb568
|
Provenance
The following attestation bundles were made for awesomeversion-25.8.0-py3-none-any.whl:
Publisher:
release.yml on ludeeus/awesomeversion
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awesomeversion-25.8.0-py3-none-any.whl -
Subject digest:
1c314683abfcc3e26c62af9e609b585bbcbf2ec19568df2f60ff1034fb1dae28 - Sigstore transparency entry: 345674513
- Sigstore integration time:
-
Permalink:
ludeeus/awesomeversion@88a09dd69d61d836fedb025b07efca38a2e82f50 -
Branch / Tag:
refs/tags/25.8.0 - Owner: https://github.com/ludeeus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@88a09dd69d61d836fedb025b07efca38a2e82f50 -
Trigger Event:
release
-
Statement type: