Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packaging.version as a CLI tool #795

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,33 @@ def _cmpkey(
)

return epoch, _release, _pre, _post, _dev, _local

if __name__ == "__main__":
import argparse
import sys
import operator

operations = {
"lt": operator.lt,
"le": operator.le,
"eq": operator.eq,
"ne": operator.ne,
"ge": operator.ge,
"gt": operator.gt,
}

# Argument parsing
parser = argparse.ArgumentParser(description="Compare two semantic versions.")
parser.add_argument("version1", type=Version, help="First version to compare")
parser.add_argument(
"operator",
type=str,
choices=operations.keys(),
help="Comparison operator",
)
parser.add_argument("version2", type=Version, help="Second version to compare")
args = parser.parse_args()

result = operations[args.operator](args.version1, args.version2)
sys.exit(not result)

Loading