Skip to content

Commit

Permalink
added older version support (#12)
Browse files Browse the repository at this point in the history
* Updated README.md

* Add pytest tests and GitHub Actions workflow

* Add pytest tests and GitHub Actions workflow

* Add pytest tests and GitHub Actions workflow

* Added the Check version Capability

* added version.py

* added older version support
  • Loading branch information
muhammad-fiaz authored Dec 7, 2023
1 parent d7b96c2 commit b7cc61f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ CheckVersions is a powerful and intuitive version comparison tool designed to si

## Features

- **Semantic Version Analysis:** Leverage our sophisticated semantic versioning analysis engine to compare versions like "0.0.0-beta" effortlessly.
- **Automated Version Ranking:** Quickly identify the latest, older releases, or pre-releases with our automated version-ranking system.
- **Efficient Version Delta Assessment:** CheckVersions provides a detailed breakdown of the differences between versions, allowing you to make informed decisions about your software.
- **User-Friendly Interface:** Our intuitive user interface ensures that developers can effortlessly compare versions through graphical representations, providing detailed insights into the chronological order of your software iterations.
- **Secure Version Analysis:** Security is paramount. CheckVersions ensures version comparison is performed securely, protecting your intellectual property and facilitating risk-free decision-making in your development process.
- **Semantic Version Analysis:** 🧐 Leverage our sophisticated semantic versioning analysis engine to compare versions like "0.0.0-beta" effortlessly.

- **Automated Version Ranking:** 🚀 CheckVersions automatically ranks versions based on their priority, allowing you to quickly identify the latest version.

- **Efficient Version Delta Assessment:** 📊 CheckVersions provides a simple and efficient way to assess the difference between two versions.

- **User-Friendly Interface:** 🎨 Our intuitive user interface ensures that developers can effortlessly compare versions.

- **Secure Version Analysis:** 🔒 Security is paramount. CheckVersions ensures version comparison is performed securely, protecting your intellectual property and facilitating risk-free decision-making in your development process.

- **Custom Hierarchy** 📝 Customize the hierarchy of version words to suit your needs. For instance, you can assign a higher priority to "beta" than "alpha" if you wish.

- **Older Version Retrieval:** ⏳ Optionally retrieve the older version when comparing two versions by setting the `older_version` parameter to `True`.

## Getting Started

Expand All @@ -52,6 +60,8 @@ print(result)
In this example, we demonstrate a basic version comparison. The compare_versions function is used to compare the current_version (v1.0.0) with the latest_version (v1.0.0-beta). The result is printed, and it shows that the latest version is v1.0.0.

```python3
from checkversions import *

# Example 2: Comparing Versions with Hyphens and Words
version1 = "2.0.0-beta"
version2 = "2.0.1-alpha"
Expand Down Expand Up @@ -94,6 +104,19 @@ print(result)
```
In this example, we introduce a custom hierarchy for version comparison. The custom_hierarchy dictionary is defined with version words and their corresponding priority. The compare_versions function uses this custom hierarchy to compare version1 (v1.0.0-beta) with version2 (v1.0.1-alpha). The result is printed, indicating that the latest version is v1.0.1-alpha.

## Older Version

```python3
from checkversions import *
current_version = "v1.0.0"
latest_version = "v1.0.0-beta"
# Example with older_version=True
result_older = compare_versions(current_version, latest_version, older_version=True)
print(f"Older version: {result_older}")
# Output: Older version: v1.0.0-beta
```
In this example, by setting older_version=True, the function returns and prints the older version (v1.0.0-beta) based on the provided versions (v1.0.0 and v1.0.0-beta). If older_version is omitted or set to False, it would return and print the latest version.

## Contributing
Contributions are welcome! Before contributing, please read our [Contributing Guidelines](CONTRIBUTING.md) to ensure a smooth and collaborative development process.

Expand Down
19 changes: 10 additions & 9 deletions checkversions/checkversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def get_default_hierarchy_from_json():
print(f"Error loading default hierarchy from JSON: {e}")
return {"beta": 0, "prerelease": 1, "alpha": 2, "unstable": 3, "stable": 4, "release": 5}

def compare_versions(current_version, latest_version, custom_hierarchy=None):
def compare_versions(current_version, latest_version, custom_hierarchy=None, older_version=False):
"""
Compare two versions and determine the latest version.
Compare two versions and determine the latest or older version.
This function compares two versions, taking into account version numbers,
hyphen-separated parts, and additional words (e.g., beta, release, alpha).
Expand All @@ -44,9 +44,10 @@ def compare_versions(current_version, latest_version, custom_hierarchy=None):
current_version (str): The current version.
latest_version (str): The version to compare against.
custom_hierarchy (dict, optional): Custom version hierarchy. Defaults to None.
older_version (bool, optional): If True, return the older version. Defaults to False.
Returns:
str: The latest version, considering version numbers and hierarchy.
str: The latest or older version, considering version numbers and hierarchy.
Raises:
InvalidVersion: If there is an issue with the version comparison.
Expand Down Expand Up @@ -90,19 +91,19 @@ def compare_versions(current_version, latest_version, custom_hierarchy=None):

# Compare version numbers first
if current_version_obj < latest_version_obj:
return latest_version_output
return current_version_output if older_version else latest_version_output
elif current_version_obj > latest_version_obj:
return current_version_output
return latest_version_output if older_version else current_version_output

# Compare hierarchy only if version numbers are equal
if version_hierarchy.get(current_version_after_hyphen_word, 5) < version_hierarchy.get(latest_version_after_hyphen_word, 5):
return latest_version_output
return current_version_output if older_version else latest_version_output
elif version_hierarchy.get(current_version_after_hyphen_word, 5) > version_hierarchy.get(latest_version_after_hyphen_word, 5):
return current_version_output
return latest_version_output if older_version else current_version_output
elif version_hierarchy.get(current_version_words, 5) < version_hierarchy.get(latest_version_words, 5):
return latest_version_output
return current_version_output if older_version else latest_version_output
elif version_hierarchy.get(current_version_words, 5) > version_hierarchy.get(latest_version_words, 5):
return current_version_output
return latest_version_output if older_version else current_version_output

return current_version_output

Expand Down

0 comments on commit b7cc61f

Please sign in to comment.