Skip to content

Fix issue with pytask --version and click v8. #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
`Anaconda.org <https://anaconda.org/conda-forge/pytask>`_.


0.0.15 - 2021-xx-xx
0.0.16 - 2021-xx-xx
-------------------

- :gh:`111` fixes error when using ``pytask --version`` with click v8.



0.0.15 - 2021-06-24
-------------------

- :gh:`80` replaces some remaining formatting using ``pprint`` with ``rich``.
Expand Down
12 changes: 9 additions & 3 deletions src/_pytask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
from _pytask.config import hookimpl
from _pytask.pluginmanager import get_plugin_manager
from click_default_group import DefaultGroup
from pkg_resources import packaging


CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
_CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}

if packaging.version.parse(click.__version__) < packaging.version.parse("8"):
_VERSION_OPTION_KWARGS = {}
else:
_VERSION_OPTION_KWARGS = {"package_name": "pytask"}


def _extend_command_line_interface(command_line_interface):
Expand Down Expand Up @@ -78,11 +84,11 @@ def pytask_add_hooks(pm):

@click.group(
cls=DefaultGroup,
context_settings=CONTEXT_SETTINGS,
context_settings=_CONTEXT_SETTINGS,
default="build",
default_if_no_args=True,
)
@click.version_option()
@click.version_option(**_VERSION_OPTION_KWARGS)
def cli():
"""The command line interface of pytask."""
pass
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import subprocess

from pytask import __version__


def test_version_option():
process = subprocess.run(["pytask", "--version"], capture_output=True)
assert "pytask, version " + __version__ in process.stdout.decode("utf-8")