Skip to content

Commit

Permalink
use dunamai to display versioning information (#831)
Browse files Browse the repository at this point in the history
makes use of the dunamai package to display versioning information (`popper version`). In addition, this commit adds a `--version` flag to the `popper` command.

fixes #783
  • Loading branch information
FernandaDguez committed May 20, 2020
1 parent e739b60 commit 9bbbe33
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ popper_status
popper_logs
popper_status
.pipeline_cache.yml
cli/popper/_version.py
22 changes: 21 additions & 1 deletion cli/popper/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
__version__ = "2.6.0-dev"
import importlib
import pathlib
import os


# check if dunamai is available
dunamai_spec = importlib.util.find_spec("dunamai")
dunamai_found = dunamai_spec is not None
if dunamai_found:
# if dunamai is found, then we use it to display the version
import dunamai

__version__ = dunamai.Version.from_any_vcs().serialize()
_ver = f'__popper_version__ = "{__version__}"'

_init_script_dir = pathlib.Path(__file__).parent.absolute()
_version_path_ = os.path.join(_init_script_dir, "_version.py")
with open(_version_path_, "w") as v:
v.write(_ver)
else:
from popper._version import __popper_version__ as __version__
1 change: 1 addition & 0 deletions cli/popper/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__popper_version__ = "0.0.0"
1 change: 1 addition & 0 deletions cli/popper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get_command(self, ctx, name):


@click.command(cls=PopperCLI)
@click.version_option(__version__, message=f"Popper version {popper_version}")
@pass_context
def cli(ctx):
"""Popper command line interface."""
Expand Down
8 changes: 5 additions & 3 deletions cli/setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup

version = {}
with open("popper/__init__.py") as f:
with open("popper/_version.py") as f:
exec(f.read(), version)

setup(
name="popper",
version=version["__version__"],
version=version["__popper_version__"],
author="The Popper Development Team",
author_email="ivo@cs.ucsc.edu",
url="http://falsifiable.us",
Expand All @@ -22,7 +22,9 @@
"pyyaml==5.3.1",
"spython==0.0.79",
],
extras_require={"dev": ["testfixtures==6.14.0", "black==19.10b0"]},
extras_require={
"dev": ["testfixtures==6.14.0", "black==19.10b0", "dunamai==1.1.0"]
},
entry_points="""
[console_scripts]
popper=popper.cli:cli
Expand Down
5 changes: 3 additions & 2 deletions cli/test/test_cmd_version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from click.testing import CliRunner

from popper import __version__
from popper._version import __popper_version__
from popper.commands import cmd_version

from .test_common import PopperTest


Expand All @@ -13,5 +13,6 @@ def test_version(self):
runner = CliRunner()
result = runner.invoke(cmd_version.cli)
self.assertEqual(result.exit_code, 0)

self.assertIsNot(__version__, "0.0.0")
self.assertEqual(__version__, __popper_version__)
self.assertTrue(__version__ in test.output[0])

0 comments on commit 9bbbe33

Please sign in to comment.