Skip to content

Commit dca287f

Browse files
authored
Fix --capture tee-sys. (#703)
1 parent e3878e3 commit dca287f

File tree

3 files changed

+35
-43
lines changed

3 files changed

+35
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask).
77

8+
## 0.5.6 - 2025-xx-xx
9+
10+
- {pull}`703` fixes {issue}`701` by allowing `--capture tee-sys` again.
11+
812
## 0.5.5 - 2025-07-25
913

1014
- {pull}`692` documents how to use pytask with workspaces.

justfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ install:
33
uv sync --all-groups
44

55
# Run tests
6-
test:
7-
uv run --group test pytest
6+
test *FLAGS:
7+
uv run --group test pytest {{FLAGS}}
88

99
# Run tests with coverage
10-
test-cov:
11-
uv run --group test pytest --nbmake --cov=src --cov=tests --cov-report=xml -n auto
10+
test-cov *FLAGS:
11+
uv run --group test pytest --nbmake --cov=src --cov=tests --cov-report=xml -n auto {{FLAGS}}
1212

1313
# Run tests with notebook validation
1414
test-nb:

src/_pytask/click.py

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import TYPE_CHECKING
1111
from typing import Any
1212
from typing import ClassVar
13-
from typing import TypeVar
1413

1514
import click
1615
from click import Choice
@@ -29,7 +28,6 @@
2928
from _pytask.console import create_panel_title
3029

3130
if TYPE_CHECKING:
32-
from collections.abc import Iterable
3331
from collections.abc import Sequence
3432

3533

@@ -38,50 +36,40 @@
3836

3937
if importlib.metadata.version("click") < "8.2":
4038
from click.parser import split_opt
39+
else:
40+
from click.parser import ( # type: ignore[attr-defined, no-redef, unused-ignore]
41+
_split_opt as split_opt,
42+
)
4143

42-
class EnumChoice(Choice): # type: ignore[type-arg, unused-ignore]
43-
"""An enum-based choice type.
44-
45-
The implementation is copied from https://github.com/pallets/click/pull/2210 and
46-
related discussion can be found in https://github.com/pallets/click/issues/605.
4744

48-
In contrast to using :class:`click.Choice`, using this type ensures that the
49-
error message does not show the enum members.
45+
class EnumChoice(Choice): # type: ignore[type-arg, unused-ignore]
46+
"""An enum-based choice type.
5047
51-
In contrast to the proposed implementation in the PR, this implementation does
52-
not use the members than rather the values of the enum.
48+
The implementation is copied from https://github.com/pallets/click/pull/2210 and
49+
related discussion can be found in https://github.com/pallets/click/issues/605.
5350
54-
"""
51+
In contrast to using :class:`click.Choice`, using this type ensures that the
52+
error message does not show the enum members.
5553
56-
def __init__(self, enum_type: type[Enum], case_sensitive: bool = True) -> None:
57-
super().__init__(
58-
choices=[element.value for element in enum_type],
59-
case_sensitive=case_sensitive,
60-
)
61-
self.enum_type = enum_type
62-
63-
def convert(
64-
self, value: Any, param: Parameter | None, ctx: Context | None
65-
) -> Any:
66-
if isinstance(value, Enum):
67-
value = value.value
68-
value = super().convert(value=value, param=param, ctx=ctx)
69-
if value is None:
70-
return None
71-
return self.enum_type(value)
54+
In contrast to the proposed implementation in the PR, this implementation does
55+
not use the members than rather the values of the enum.
7256
73-
else:
74-
from click.parser import ( # type: ignore[attr-defined, no-redef, unused-ignore]
75-
_split_opt as split_opt,
76-
)
77-
78-
ParamTypeValue = TypeVar("ParamTypeValue")
57+
"""
7958

80-
class EnumChoice(Choice): # type: ignore[no-redef, type-arg, unused-ignore]
81-
def __init__(
82-
self, choices: Iterable[ParamTypeValue], case_sensitive: bool = False
83-
) -> None:
84-
super().__init__(choices=choices, case_sensitive=case_sensitive) # type: ignore[arg-type, unused-ignore]
59+
def __init__(self, enum_type: type[Enum], case_sensitive: bool = True) -> None:
60+
super().__init__(
61+
choices=[element.value for element in enum_type],
62+
case_sensitive=case_sensitive,
63+
)
64+
self.enum_type = enum_type
65+
66+
def convert(self, value: Any, param: Parameter | None, ctx: Context | None) -> Any:
67+
if isinstance(value, Enum):
68+
value = value.value
69+
value = super().convert(value=value, param=param, ctx=ctx)
70+
if value is None:
71+
return None
72+
return self.enum_type(value)
8573

8674

8775
class _OptionHighlighter(RegexHighlighter):

0 commit comments

Comments
 (0)