Skip to content

Commit

Permalink
refactored finding the version (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC authored Sep 12, 2024
1 parent 2e9efdb commit 56da01d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions moccasin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sys
from moccasin.constants.vars import CONFIG_NAME

from importlib import metadata


GAB_CLI_VERSION_STRING = "Moccasin CLI v{}"

Expand Down Expand Up @@ -401,11 +403,15 @@ def add_network_args_to_parser(parser: argparse.ArgumentParser):


def get_version() -> str:
with open(
Path(__file__).resolve().parent.parent.joinpath("pyproject.toml"), "rb"
) as f:
moccasin_cli_data = tomllib.load(f)
return GAB_CLI_VERSION_STRING.format(moccasin_cli_data["project"]["version"])
version = metadata.version("moccasin")
# Attempt to parse from `pyproject.toml` if not found
if not version:
with open(
Path(__file__).resolve().parent.parent.joinpath("pyproject.toml"), "rb"
) as f:
moccasin_cli_data = tomllib.load(f)
version = moccasin_cli_data["project"]["version"]
return GAB_CLI_VERSION_STRING.format(version)


def validate_generate_args(args):
Expand Down

0 comments on commit 56da01d

Please sign in to comment.