Skip to content
Open
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions .github/scripts/compare_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

# Copyright The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Compare PEP 440 versions.

Usage:
python compare_versions.py <current_version> <target_version>

Exit codes:
0 - current_version < target_version (upgrade needed)
1 - current_version >= target_version (no upgrade needed)
2 - error parsing versions
"""

import sys

from packaging.version import InvalidVersion, Version


def main():
if len(sys.argv) != 3:
print(
"Usage: compare_versions.py <current_version> <target_version>",
file=sys.stderr,
)
sys.exit(2)

current_str = sys.argv[1]
target_str = sys.argv[2]

try:
current = Version(current_str)
target = Version(target_str)

# Exit 0 if current < target (upgrade needed)
# Exit 1 if current >= target (no upgrade needed)
sys.exit(0 if current < target else 1)
except InvalidVersion as e:
print(f"Error: Invalid version format - {e}", file=sys.stderr)
sys.exit(2)


if __name__ == "__main__":
main()
61 changes: 61 additions & 0 deletions .github/scripts/extract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3

# Copyright The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Extract package version from uv tree output.

This script parses uv tree output to extract the full version
(including pre-release, post-release, dev versions) of a package.

Usage:
uv tree --package <package> | python extract_version.py <package>

Exit codes:
0 - version found and printed to stdout
1 - version not found or error
"""

import re
import sys


def main():
if len(sys.argv) != 2:
print(
"Usage: uv tree --package <pkg> | extract_version.py <pkg>", file=sys.stderr
)
sys.exit(1)

package_name = sys.argv[1]

# Read from stdin (piped from uv tree)
tree_output = sys.stdin.read()

# Look for pattern: "package_name vX.Y.Z"
# Using non-greedy match to get version until whitespace
pattern = rf"{re.escape(package_name)}\s+v([^\s]+)"
match = re.search(pattern, tree_output)

if match:
version = match.group(1)
print(version)
sys.exit(0)
else:
print(f"Error: Could not find version for {package_name}", file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
main()
Loading
Loading