Skip to content

Commit 09b1caf

Browse files
committed
Test on click 8.0.0a1 and fix some compatibility issues.
1 parent 0e09568 commit 09b1caf

15 files changed

+130
-35
lines changed

.github/workflows/python_ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
fail-fast: False
2020
matrix:
2121
config:
22-
- {python-version: "3.6", testenvs: "py36,build", experimental: False}
23-
- {python-version: "3.7", testenvs: "py37,build", experimental: False}
24-
- {python-version: "3.8", testenvs: "py38,build", experimental: False}
25-
- {python-version: "3.9", testenvs: "py39,build", experimental: False}
26-
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev,build", experimental: True}
22+
- {python-version: "3.6", testenvs: "py36-click{7.1,8.0.0a1},build", experimental: False}
23+
- {python-version: "3.7", testenvs: "py37-click{7.1,8.0.0a1},build", experimental: False}
24+
- {python-version: "3.8", testenvs: "py38-click{7.1,8.0.0a1},build", experimental: False}
25+
- {python-version: "3.9", testenvs: "py39-click{7.1,8.0.0a1},build", experimental: False}
26+
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev-click{7.1,8.0.0a1},build", experimental: True}
2727

2828
steps:
2929
- name: Checkout 🛎️

.github/workflows/python_ci_linux.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
fail-fast: False
2020
matrix:
2121
config:
22-
- {python-version: "3.6", testenvs: "py36,build", experimental: False}
23-
- {python-version: "3.7", testenvs: "py37,build", experimental: False}
24-
- {python-version: "3.8", testenvs: "py38,build", experimental: False}
25-
- {python-version: "3.9", testenvs: "py39,build", experimental: False}
26-
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev,build", experimental: True}
27-
- {python-version: "pypy-3.6", testenvs: "pypy3,build", experimental: False}
22+
- {python-version: "3.6", testenvs: "py36-click{7.1,8.0.0a1},build", experimental: False}
23+
- {python-version: "3.7", testenvs: "py37-click{7.1,8.0.0a1},build", experimental: False}
24+
- {python-version: "3.8", testenvs: "py38-click{7.1,8.0.0a1},build", experimental: False}
25+
- {python-version: "3.9", testenvs: "py39-click{7.1,8.0.0a1},build", experimental: False}
26+
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev-click{7.1,8.0.0a1},build", experimental: True}
27+
- {python-version: "pypy-3.6", testenvs: "pypy3-click{7.1,8.0.0a1},build", experimental: False}
2828

2929
steps:
3030
- name: Checkout 🛎️

.github/workflows/python_ci_macos.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
fail-fast: False
2020
matrix:
2121
config:
22-
- {python-version: "3.6", testenvs: "py36,build", experimental: False}
23-
- {python-version: "3.7", testenvs: "py37,build", experimental: False}
24-
- {python-version: "3.8", testenvs: "py38,build", experimental: False}
25-
- {python-version: "3.9", testenvs: "py39,build", experimental: False}
26-
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev,build", experimental: True}
27-
- {python-version: "pypy-3.6", testenvs: "pypy3,build", experimental: False}
22+
- {python-version: "3.6", testenvs: "py36-click{7.1,8.0.0a1},build", experimental: False}
23+
- {python-version: "3.7", testenvs: "py37-click{7.1,8.0.0a1},build", experimental: False}
24+
- {python-version: "3.8", testenvs: "py38-click{7.1,8.0.0a1},build", experimental: False}
25+
- {python-version: "3.9", testenvs: "py39-click{7.1,8.0.0a1},build", experimental: False}
26+
- {python-version: "3.10.0-alpha.3", testenvs: "py310-dev-click{7.1,8.0.0a1},build", experimental: True}
27+
- {python-version: "pypy-3.6", testenvs: "pypy3-click{7.1,8.0.0a1},build", experimental: False}
2828

2929
steps:
3030
- name: Checkout 🛎️

.isort.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ known_third_party =
1919
coverage_pyver_pragma
2020
domdf_python_tools
2121
github
22+
mistletoe
2223
pytest
2324
pytest_cov
2425
pytest_randomly

__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030

3131
repo_root = pathlib.Path(__file__).parent
3232
install_requires = (repo_root / "requirements.txt").read_text(encoding="utf-8").split('\n')
33-
extras_require = {"all": []}
33+
extras_require = {"terminals": ["psutil>=5.8.0"], "all": ["psutil>=5.8.0"]}

consolekit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import click
3535

3636
# this package
37-
from consolekit import input, terminal_colours, utils, commands # pylint: disable=redefined-builtin
37+
from consolekit import commands, input, terminal_colours, utils # pylint: disable=redefined-builtin
3838
from consolekit.commands import SuggestionGroup
3939
from consolekit.options import _Option
4040

consolekit/options.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060

6161
# stdlib
6262
import inspect
63-
from typing import Any, Callable, List, Optional, TypeVar, cast
63+
from typing import Any, Callable, Iterable, List, Optional, Tuple, TypeVar, cast
6464

6565
# 3rd party
6666
import click
67-
from click import Argument, Context, Option, OptionParser
67+
from click import Argument, Context, IntRange, Option, OptionParser
6868
from click.decorators import _param_memo # type: ignore
6969

7070
# this package
@@ -87,6 +87,24 @@
8787
_C = TypeVar("_C", bound=click.Command)
8888

8989

90+
class VerboseVersionCountType(click.IntRange):
91+
"""
92+
Subclass of :class:`click.IntRange` which doesn't show the range of valid values.
93+
94+
.. versionadded:: 0.8.1
95+
"""
96+
97+
def __init__(self):
98+
super().__init__(min=0)
99+
100+
def _describe_range(self):
101+
"""
102+
Describe the range for use in help text.
103+
"""
104+
105+
return ''
106+
107+
90108
def verbose_option(help_text: str = "Show verbose output.") -> Callable[..., click.Command]:
91109
"""
92110
Adds an option (via the parameter ``verbose``: :class:`int`) to enable verbose output.
@@ -98,12 +116,7 @@ def verbose_option(help_text: str = "Show verbose output.") -> Callable[..., cli
98116
:param help_text: The help text for the option.
99117
"""
100118

101-
return click.option(
102-
"-v",
103-
"--verbose",
104-
count=True,
105-
help=help_text,
106-
)
119+
return click.option("-v", "--verbose", count=True, help=help_text, type=VerboseVersionCountType())
107120

108121

109122
def version_option(callback: Callable[[Context, Option, int], Any]) -> Callable[..., click.Command]:
@@ -140,6 +153,7 @@ def version_callback(ctx: click.Context, param: click.Option, value: int):
140153
expose_value=False,
141154
is_eager=True,
142155
help="Show the version and exit.",
156+
type=VerboseVersionCountType(),
143157
callback=cast(Callback, callback),
144158
)
145159

@@ -386,6 +400,29 @@ def parser_process(value, state):
386400

387401
return retval
388402

403+
def process_value(self, ctx: click.Context, value: Any) -> Optional[Tuple]:
404+
"""
405+
Given a value and context, converts the value as necessary.
406+
407+
:param ctx:
408+
:param value:
409+
"""
410+
411+
# If the value we were given is None we do nothing.
412+
# This way code that calls this can easily figure out if something was not provided.
413+
# Otherwise, it would be converted into an empty tuple for multiple invocations,
414+
# which is inconvenient.
415+
416+
# assert isinstance(value, tuple), type(value)
417+
418+
if value is not None:
419+
if isinstance(value, Iterable) and not isinstance(value, str):
420+
return tuple(self.type_cast_value(ctx, v) for v in value)
421+
elif value in ("()", str(self.default)) or not value:
422+
return self.default
423+
else:
424+
return self.type_cast_value(ctx, value)
425+
389426

390427
class _Option(click.Option):
391428

repo_helper.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ extras_require:
3838
- psutil>=5.8.0
3939

4040
tox_testenv_extras: all
41+
42+
third_party_version_matrix:
43+
click:
44+
- 7.1
45+
- 8.0.0a1

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
colorama>=0.4.4; python_version == "3.10" and platform_system != "Windows"
22
coverage>=5.1
33
coverage-pyver-pragma>=0.0.6
4-
domdf-python-tools[testing]>=1.6.0
4+
domdf-python-tools[testing]>=2.0.1
55
iniconfig!=1.1.0,>=1.0.1
66
pytest>=6.0.0
77
pytest-cov>=2.8.1

tests/test_input.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 3rd party
22
import click
3+
import pytest
34
from click import echo
45
from domdf_python_tools.stringlist import StringList
56
from pytest_regressions.data_regression import DataRegressionFixture
@@ -34,7 +35,24 @@ def fake_input(prompt):
3435
data_regression.check(list(StringList(capsys.readouterr().out.splitlines())))
3536

3637

37-
def test_choice_numbers(capsys, monkeypatch, data_regression: DataRegressionFixture):
38+
@pytest.mark.parametrize(
39+
"click_version",
40+
[
41+
pytest.param(
42+
'7',
43+
marks=pytest.mark.skipif(
44+
not click.__version__.startswith('7'), reason="Output differs on click 8"
45+
)
46+
),
47+
pytest.param(
48+
'8',
49+
marks=pytest.mark.skipif(
50+
not click.__version__.startswith('8'), reason="Output differs on click 8"
51+
)
52+
),
53+
]
54+
)
55+
def test_choice_numbers(capsys, monkeypatch, data_regression: DataRegressionFixture, click_version):
3856

3957
inputs = iter(["20", '0', '5'])
4058

0 commit comments

Comments
 (0)