Skip to content

Commit

Permalink
Fixed version command
Browse files Browse the repository at this point in the history
  • Loading branch information
irarainey committed Dec 8, 2023
1 parent ee17150 commit cb25a0f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/azext_copilot/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from azext_copilot.configuration import show_config, update_config
from azext_copilot.copilot import copilot
from azext_copilot.version import get_version
from azext_copilot.version import __version__


# This is the entry point for the AZ CLI extension to call the Copilot
Expand Down Expand Up @@ -48,5 +48,6 @@ def show_config_cmd():
print(show_config())


# This is the entry point for the AZ CLI extension to show the version
def get_version_cmd():
print(get_version())
print(f"copilot version {__version__}")
37 changes: 2 additions & 35 deletions src/azext_copilot/version.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
import os
import toml
import importlib.metadata


def get_version():
return get_version_from_toml_file()


def get_version_from_toml_file(
pyproject_path=os.path.join(
os.path.dirname(__file__), '..', '..', 'pyproject.toml'
)
):
version = (0, 0, 0)

try:
with open(pyproject_path, 'r') as file:
pyproject_data = toml.load(file)
except FileNotFoundError:
raise FileNotFoundError(
f"The pyproject.toml file was not found at {pyproject_path}"
)

# Access the version information from the parsed data
if pyproject_data:
version_info = pyproject_data.get('tool', {}).get('poetry', {}).get(
'version', '0.0.0')
try:
version = tuple(map(int, version_info.split('.')))
except ValueError:
raise ValueError(
f"The pyproject.toml file has an invalid "
f"version number: {version_info}"
)

return version
__version__ = importlib.metadata.version("copilot")

0 comments on commit cb25a0f

Please sign in to comment.