From e54460912946fc403d47aed6945d3e9f6ff2d541 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Thu, 24 Oct 2024 08:38:02 -0400 Subject: [PATCH] Add a script to check the pixi and rust environment dependencies --- scripts/check_env.py | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/check_env.py diff --git a/scripts/check_env.py b/scripts/check_env.py new file mode 100644 index 000000000000..7e735397399a --- /dev/null +++ b/scripts/check_env.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +"""Checks that the dev environment is set up correctly.""" + +from __future__ import annotations + +import subprocess + +PIXI_VERSION = "0.34.0" +CARGO_VERSION = "1.79.0" +RUST_VERSION = "1.79.0" + + +def check_version(cmd: str, expected: str, update: str, install: str) -> bool: + try: + output = subprocess.check_output([cmd, "--version"]) + + version = output.strip().decode("utf-8").split(" ")[1] + + if version != expected: + print(f"Expected {cmd} version {expected}, got {version}") + print(f"Please run `{update}`") + return False + else: + print(f"{cmd} version {version} is correct") + return True + + except FileNotFoundError: + print(f"{cmd} not found in PATH. Please install via {install}") + return False + + +def main() -> int: + success = True + + success &= check_version( + "pixi", + PIXI_VERSION, + f"pixi self-update --version {PIXI_VERSION}", + "https://pixi.sh/latest/", + ) + + success &= check_version( + "cargo", + CARGO_VERSION, + f"rustup install {CARGO_VERSION}", + "https://rustup.rs/", + ) + + success &= check_version( + "rustc", + RUST_VERSION, + f"rustup install {RUST_VERSION}", + "https://rustup.rs/", + ) + + if success: + exit(0) + else: + exit(1) + + +if __name__ == "__main__": + main()