From 8a1114ab62d86bf0e589e4a5cfa124a8ad6c9a13 Mon Sep 17 00:00:00 2001 From: Sam Partee Date: Thu, 17 Oct 2024 13:51:16 -0700 Subject: [PATCH] Fix `arcade-ai` versions in `arcade new` cmd` (#111) fix for version: Dynamic Version Retrieval: Replaces the hardcoded version import with dynamic retrieval using importlib.metadata.version. This ensures that __version__ in __init__.py accurately reflects the installed version of arcade-ai. fix to ``arcade-new``: Changes the default dependency specification for arcade-ai from ^{VERSION} to ~{VERSION} in DEFAULT_VERSIONS in ``new.py``. This adjustment allows for patch version updates while maintaining compatibility, enhancing stability. --------- Co-authored-by: Eric Gustin --- arcade/arcade/__init__.py | 4 ++-- arcade/arcade/cli/new.py | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/arcade/arcade/__init__.py b/arcade/arcade/__init__.py index cee50dc4..eb04cb60 100644 --- a/arcade/arcade/__init__.py +++ b/arcade/arcade/__init__.py @@ -1,3 +1,3 @@ -from arcade.core.version import VERSION +from importlib.metadata import version as get_version -__version__ = VERSION +__version__ = get_version("arcade-ai") diff --git a/arcade/arcade/cli/new.py b/arcade/arcade/cli/new.py index 2243283d..aecab58e 100644 --- a/arcade/arcade/cli/new.py +++ b/arcade/arcade/cli/new.py @@ -1,18 +1,24 @@ import os import re +from importlib.metadata import version as get_version from textwrap import dedent from typing import Optional import typer from rich.console import Console -from arcade.core.version import VERSION - console = Console() +# Retrieve the installed version of arcade-ai +try: + VERSION = get_version("arcade-ai") +except Exception as e: + console.print(f"[red]Failed to get arcade-ai version: {e}[/red]") + VERSION = "0.0.0" # Default version if unable to fetch + DEFAULT_VERSIONS = { "python": "^3.10", - "arcade-ai": f"^{VERSION}", + "arcade-ai": f"~{VERSION}", # allow patch version updates "pytest": "^8.3.0", } @@ -82,18 +88,19 @@ build-backend = "poetry.core.masonry.api" def create_new_toolkit(directory: str) -> None: """Generate a new Toolkit package based on user input.""" - name = ask_question("Name of the new toolkit?") - toolkit_name = name if name.startswith("arcade_") else f"arcade_{name}" + while True: + name = ask_question("Name of the new toolkit?") + toolkit_name = name if name.startswith("arcade_") else f"arcade_{name}" - # Check for illegal characters in the toolkit name - if not re.match(r"^[\w_]+$", toolkit_name): - console.print( - dedent( - "[red]Toolkit name contains illegal characters. \ - Only alphanumeric characters and underscores are allowed.[/red]" + # Check for illegal characters in the toolkit name + if re.match(r"^[\w_]+$", toolkit_name): + break + else: + console.print( + "[red]Toolkit name contains illegal characters. " + "Only alphanumeric characters and underscores are allowed. " + "Please try again.[/red]" ) - ) - return description = ask_question("Description of the toolkit?") author_name = ask_question("Author's name?") @@ -238,4 +245,4 @@ def create_new_toolkit(directory: str) -> None: ).strip(), ) - console.print(f"[green]Toolkit {toolkit_name} has been created.[/green]") + console.print(f"[green]Toolkit {toolkit_name} has been created in {top_level_dir} [/green]")