diff --git a/utils/version_checker.py b/utils/version_checker.py deleted file mode 100644 index 45dd5425..00000000 --- a/utils/version_checker.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys -import os -import importlib.metadata -import subprocess -from utils.pypi_api import get_project_data, get_pypi_version, BASE_PATH - - -def parse_version(version: str) -> tuple[int, ...]: - parts = version.split(".") - - if len(parts) < 3: - print(f"Invalid version format: {version}", file=sys.stderr) - - return tuple(int(part) for part in parts) - - -def get_git_version(): - try: - result = subprocess.run( - ["git", "describe", "--tags", "--abbrev=0"], - capture_output=True, - text=True, - check=True, - ) - tag = result.stdout.strip() - - return tag[1:] if tag.startswith("v") else tag - except Exception: - return "0.0.0" - - -def get_pip_version(): - return importlib.metadata.version("vast-cli-fork") - - -def is_pip_package(): - script_path = sys.argv[0] - executable_name = os.path.basename(script_path) - - return executable_name != "vast.py" - - -def get_update_command(stable_version: str) -> str: - if is_pip_package(): - if "test.pypi.org" in BASE_PATH: - return f"{sys.executable} -m pip install --force-reinstall --no-cache-dir -i {BASE_PATH} vast-cli-fork=={stable_version}" - else: - return f"{sys.executable} -m pip install --force-reinstall --no-cache-dir vast-cli-fork=={stable_version}" - else: - return f"git fetch --all --tags --prune && git checkout tags/v{stable_version}" - - -def get_local_version(): - if is_pip_package(): - return get_pip_version() - return get_git_version() - - -def check_for_update(): - pypi_data = get_project_data("vast-cli-fork") - pypi_version = get_pypi_version(pypi_data) - - local_version = get_local_version() - - local_tuple = parse_version(local_version) - pypi_tuple = parse_version(pypi_version) - - if local_tuple >= pypi_tuple: - return - - user_wants_update = input( - f"Update available from {local_version} to {pypi_version}. Would you like to update [Y/n]: " - ).lower() - - if user_wants_update not in ["y", ""]: - print("You selected no. If you don't want to check for updates each time, update vast_config.py") - return - - update_command = get_update_command(pypi_version) - - print("Updating...") - _ = subprocess.run( - update_command, - shell=True, - check=True, - text=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - - print("Update completed successfully!\nAttempt to run your command again!") - sys.exit(0) diff --git a/vast.py b/vast.py index 87bba958..da9d40bf 100755 --- a/vast.py +++ b/vast.py @@ -99,14 +99,14 @@ def get_git_version(): return tag[1:] if tag.startswith("v") else tag except Exception: - return "0.0.0" + return "0.0.0-git" def get_pip_version(): try: return importlib.metadata.version("vastai") except Exception: - return "0.0.0" + return "0.0.0-pip" def is_pip_package(): @@ -157,6 +157,7 @@ def get_pypi_version(project_data: dict[str, dict[str, str]]) -> str: version_data: str = str(info_data.get("version")) return str(version_data) + def check_for_update(): pypi_data = get_project_data("vastai") pypi_version = get_pypi_version(pypi_data)