Skip to content

Commit

Permalink
add --version flag and upgrade version handling (#88)
Browse files Browse the repository at this point in the history
* add --version flag and upgrade version handling
  • Loading branch information
The-Ludwig authored Nov 8, 2023
1 parent ab9b5fb commit 9a4fa2e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions panama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from .constants import PDGID_ERROR_VAL
from .read import read_DAT
from .run import CorsikaRunner
from .version import __logo__, __version__
from .weights import add_weight_prompt, add_weight_prompt_per_event, get_weights

__version__ = "0.7.1"

__all__ = (
"read_DAT",
"get_weights",
Expand All @@ -15,4 +14,5 @@
"cli",
"PDGID_ERROR_VAL",
"__version__",
"__logo__",
)
6 changes: 3 additions & 3 deletions panama/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import click

from ..version import __logo__
from .corsika_to_hdf5 import hdf5
from .run import run


@click.group()
@click.option("--debug", "-d", default=False, is_flag=True, help="Enable debug output")
def cli(
debug: bool,
) -> None:
@click.version_option(version=__logo__)
def cli(debug: bool) -> None:
"""
Command line interface for PANAMA, providing useful CORSIKA utilities.
Expand Down
4 changes: 2 additions & 2 deletions panama/cli/corsika_to_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import click

from .._logo import get_logo
from ..read import read_DAT
from ..version import __logo__


@click.command(context_settings={"show_default": True})
Expand Down Expand Up @@ -64,7 +64,7 @@ def hdf5(
logger.setLevel(logging.DEBUG)
logger.debug("debug log level activated")

logger.info(get_logo())
logger.info(__logo__)

files = list(input)

Expand Down
4 changes: 2 additions & 2 deletions panama/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import click

from .._logo import get_logo
from ..run import CorsikaRunner
from ..version import __logo__

DEFAULT_TMP_DIR = environ.get("TMP_DIR", "/tmp/PANAMA")
CORSIKA_PATH = environ.get(
Expand Down Expand Up @@ -133,7 +133,7 @@ def run(
logger.setLevel(logging.DEBUG)
logger.debug("debug log level activated")

logger.info(get_logo())
logger.info(__logo__)

n = 0
p = Path(tmp)
Expand Down
11 changes: 6 additions & 5 deletions panama/_logo.py → panama/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# from importlib.metadata import version, packages_distributions
# __version__ = version(__distribution__)
# __distribution__ = packages_distributions["panama"][0]
__version__ = "0.8.0"

LOGO_TEMPLATE = r"""
,-.----. ,--.das nd ____ ulticore utils for corsik 7
\ / \ ,---, ,--.'| ,---, ,' , `. ,---,
Expand All @@ -15,8 +20,4 @@
`---` '---' '---' {}
"""


def get_logo() -> str:
from . import __version__

return LOGO_TEMPLATE.format(f"v{__version__}")
__logo__ = LOGO_TEMPLATE.format(f"v{__version__}")
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
authors = [
{name = "Ludwig Neste", email = "ludwig.neste@tu-dortmund.de"},
{name = "Ludwig Neste", email = "ludwig.neste@fysik.su.se"},
]
license = {text = "MIT"}
requires-python = ">= 3.8,<3.12"
Expand Down Expand Up @@ -104,7 +104,7 @@ strict = false
plugins = [
"sync-pre-commit-lock"
]
version = { source = "file", path = "panama/__init__.py" }
version = { source = "file", path = "panama/version.py" }

[tool.pdm.dev-dependencies]
dev = [
Expand Down
6 changes: 0 additions & 6 deletions tests/test_logo.py

This file was deleted.

11 changes: 11 additions & 0 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from panama import __logo__, __version__
from importlib.metadata import version

def test_logo():
logo = __logo__
assert len(logo) > 500
assert "v" in logo


def test_version():
assert __version__ == version("corsika-panama").replace("+editable", "")

0 comments on commit 9a4fa2e

Please sign in to comment.