Skip to content

Commit

Permalink
Add rapids-version and rapids-version-major-minor (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA authored Mar 7, 2024
1 parent 6ccaf06 commit 52408d2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_rapids-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from os import path
import pytest
import subprocess
import tempfile

TOOLS_DIR = path.join(path.dirname(path.realpath(__file__)), "..", "tools")


def run_rapids_version(tool_name, cwd, exit_code, output):
process = subprocess.Popen([path.join(TOOLS_DIR, tool_name)], cwd=cwd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.wait()
assert process.returncode == exit_code
assert process.stdout.read() == output
assert process.stderr.read() == ""

@pytest.mark.parametrize(
"version_contents, exit_code, version, version_major_minor",
[
("24.00.00\n", 0, "24.00.00\n", "24.00\n"),
("24.02.00a1\n", 0, "24.02.00\n", "24.02\n"),
("invalid\n", 1, "", ""),
("", 1, "", ""),
(None, 1, "", ""),
]
)
def test_rapids_version(version_contents, exit_code, version, version_major_minor):
with tempfile.TemporaryDirectory() as d:
if version_contents is not None:
with open(path.join(d, "VERSION"), "w") as f:
f.write(version_contents)

run_rapids_version("rapids-version", d, exit_code, version)
run_rapids_version("rapids-version-major-minor", d, exit_code, version_major_minor)
15 changes: 15 additions & 0 deletions tools/rapids-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Prints the full RAPIDS version based on the VERSION file. Its output is meant to be stored in a variable.
# Assumed to be run from the repository root.
# Note that this strips off anything after the patch version (Python dev suffixes, etc.)
# See also: rapids-version-major-minor
#
# $ rapids-version
# 24.00.00
set -euo pipefail

readonly regex="^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$"

[[ -f VERSION ]]
grep -E -q "$regex" VERSION
sed -E -e "s/$regex/\1.\2.\3/" VERSION
14 changes: 14 additions & 0 deletions tools/rapids-version-major-minor
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Prints the RAPIDS version major/minor based on the VERSION file. Its output is meant to be stored in a variable.
# Assumed to be run from the repository root.
# See also: rapids-version
#
# $ rapids-version-major-minor
# 24.00
set -euo pipefail

readonly regex="^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$"

[[ -f VERSION ]]
grep -E -q "$regex" VERSION
sed -E -e "s/$regex/\1.\2/" VERSION

0 comments on commit 52408d2

Please sign in to comment.