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 <eric@arcade-ai.com>
This commit is contained in:
Sam Partee 2024-10-17 13:51:16 -07:00 committed by GitHub
parent c81da86460
commit 8a1114ab62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View file

@ -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")

View file

@ -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]")