Skip to content

Commit 8e7686e

Browse files
authored
Fix issue with pytask --version and click v8. (#113)
1 parent 2b36542 commit 8e7686e

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

docs/changes.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
77
`Anaconda.org <https://anaconda.org/conda-forge/pytask>`_.
88

99

10-
0.0.15 - 2021-xx-xx
10+
0.0.16 - 2021-xx-xx
11+
-------------------
12+
13+
- :gh:`111` fixes error when using ``pytask --version`` with click v8.
14+
15+
16+
17+
0.0.15 - 2021-06-24
1118
-------------------
1219

1320
- :gh:`80` replaces some remaining formatting using ``pprint`` with ``rich``.

src/_pytask/cli.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
from _pytask.config import hookimpl
66
from _pytask.pluginmanager import get_plugin_manager
77
from click_default_group import DefaultGroup
8+
from pkg_resources import packaging
89

910

10-
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
11+
_CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
12+
13+
if packaging.version.parse(click.__version__) < packaging.version.parse("8"):
14+
_VERSION_OPTION_KWARGS = {}
15+
else:
16+
_VERSION_OPTION_KWARGS = {"package_name": "pytask"}
1117

1218

1319
def _extend_command_line_interface(command_line_interface):
@@ -78,11 +84,11 @@ def pytask_add_hooks(pm):
7884

7985
@click.group(
8086
cls=DefaultGroup,
81-
context_settings=CONTEXT_SETTINGS,
87+
context_settings=_CONTEXT_SETTINGS,
8288
default="build",
8389
default_if_no_args=True,
8490
)
85-
@click.version_option()
91+
@click.version_option(**_VERSION_OPTION_KWARGS)
8692
def cli():
8793
"""The command line interface of pytask."""
8894
pass

tests/test_cli.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import subprocess
2+
3+
from pytask import __version__
4+
5+
6+
def test_version_option():
7+
process = subprocess.run(["pytask", "--version"], capture_output=True)
8+
assert "pytask, version " + __version__ in process.stdout.decode("utf-8")

0 commit comments

Comments
 (0)