Skip to content

Commit cdf1222

Browse files
authored
Formalize more choice options to enums. (#321)
1 parent bd743cf commit cdf1222

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

docs/source/changes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ 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.2.6 - 2022-xx-xx
8+
## 0.2.7 - 2022-xx-xx
9+
10+
- {pull}`308` replaces pydot with pygraphviz.
11+
- {pull}`318` Clarifies an example on nested dependencies and products.
12+
- {pull}`321` converts more choice options to enums.
13+
14+
## 0.2.6 - 2022-10-27
915

1016
- {pull}`297` moves non-hook functions from `warnings.py` to `warnings_utils.py` and
1117
publishes them so that pytask-parallel can import them.

src/_pytask/capture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def final(f):
5555
return f
5656

5757

58-
class _CaptureMethod(Enum):
58+
class _CaptureMethod(str, Enum):
5959
FD = "fd"
6060
NO = "no"
6161
SYS = "sys"
@@ -68,7 +68,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
6868
additional_parameters = [
6969
click.Option(
7070
["--capture"],
71-
type=click.Choice([x.value for x in _CaptureMethod]),
71+
type=click.Choice(_CaptureMethod), # type: ignore[arg-type]
7272
help="Per task capturing method. [dim]\\[default: fd][/]",
7373
),
7474
click.Option(
@@ -78,7 +78,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
7878
),
7979
click.Option(
8080
["--show-capture"],
81-
type=click.Choice([x.value for x in ShowCapture]),
81+
type=click.Choice(ShowCapture), # type: ignore[arg-type]
8282
help=(
8383
"Choose which captured output should be shown for failed tasks. "
8484
"[dim]\\[default: all][/]"

src/_pytask/clean.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import shutil
66
import sys
7+
from enum import Enum
78
from pathlib import Path
89
from types import TracebackType
910
from typing import Any
@@ -39,6 +40,12 @@
3940
from typing import NoReturn
4041

4142

43+
class _CleanMode(str, Enum):
44+
DRY_RUN = "dry-run"
45+
FORCE = "force"
46+
INTERACTIVE = "interactive"
47+
48+
4249
_DEFAULT_EXCLUDE: list[str] = [".git/*", ".hg/*", ".svn/*"]
4350

4451

@@ -68,7 +75,7 @@ def pytask_parse_config(
6875
config["exclude"] = (
6976
to_list(cli_excludes or []) + to_list(file_excludes or []) + _DEFAULT_EXCLUDE
7077
)
71-
config["mode"] = config_from_cli.get("mode", "dry-run")
78+
config["mode"] = config_from_cli.get("mode", _CleanMode.DRY_RUN)
7279
config["quiet"] = get_first_non_none_value(
7380
config_from_cli, key="quiet", default=False
7481
)
@@ -92,8 +99,8 @@ def pytask_parse_config(
9299
)
93100
@click.option(
94101
"--mode",
95-
default="dry-run",
96-
type=click.Choice(["dry-run", "interactive", "force"]),
102+
default=_CleanMode.DRY_RUN,
103+
type=click.Choice(_CleanMode), # type: ignore[arg-type]
97104
help=_HELP_TEXT_MODE,
98105
)
99106
@click.option(
@@ -147,12 +154,12 @@ def clean(**config_from_cli: Any) -> NoReturn:
147154
console.print(f"\n{targets} which can be removed:\n")
148155
for path in unknown_paths:
149156
short_path = relative_to(path, common_ancestor)
150-
if session.config["mode"] == "dry-run":
157+
if session.config["mode"] == _CleanMode.DRY_RUN:
151158
console.print(f"Would remove {short_path}")
152159
else:
153160
should_be_deleted = session.config[
154161
"mode"
155-
] == "force" or click.confirm(
162+
] == _CleanMode.FORCE or click.confirm(
156163
f"Would you like to remove {short_path}?"
157164
)
158165
if should_be_deleted:

src/_pytask/config_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _parse(x: Enum | str | None) -> Enum | None:
2929
return _parse
3030

3131

32-
class ShowCapture(Enum):
32+
class ShowCapture(str, Enum):
3333
NO = "no"
3434
STDOUT = "stdout"
3535
STDERR = "stderr"

src/_pytask/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pony import orm
1616

1717

18-
class _DatabaseProviders(Enum):
18+
class _DatabaseProviders(str, Enum):
1919
SQLITE = "sqlite"
2020
POSTGRES = "postgres"
2121
MYSQL = "mysql"
@@ -71,7 +71,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
7171
additional_parameters = [
7272
click.Option(
7373
["--database-provider"],
74-
type=click.Choice([x.value for x in _DatabaseProviders]),
74+
type=click.Choice(_DatabaseProviders), # type: ignore[arg-type]
7575
help=(
7676
"Database provider. All providers except sqlite are considered "
7777
"experimental. [dim]\\[default: sqlite][/]"

src/_pytask/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from typing import NoReturn
3333

3434

35-
class _RankDirection(Enum):
35+
class _RankDirection(str, Enum):
3636
TB = "TB"
3737
LR = "LR"
3838
BT = "BT"
@@ -99,7 +99,7 @@ def pytask_parse_config(
9999
@click.option(
100100
"-r",
101101
"--rank-direction",
102-
type=click.Choice([x.value for x in _RankDirection]),
102+
type=click.Choice(_RankDirection), # type: ignore[arg-type]
103103
help=_HELP_TEXT_RANK_DIRECTION,
104104
)
105105
def dag(**config_from_cli: Any) -> NoReturn:

src/_pytask/profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from typing import NoReturn
4040

4141

42-
class _ExportFormats(Enum):
42+
class _ExportFormats(str, Enum):
4343
NO = "no"
4444
JSON = "json"
4545
CSV = "csv"
@@ -113,7 +113,7 @@ def _create_or_update_runtime(task_name: str, start: float, end: float) -> None:
113113
@click.command(cls=ColoredCommand)
114114
@click.option(
115115
"--export",
116-
type=click.Choice([x.value for x in _ExportFormats]),
116+
type=click.Choice(_ExportFormats), # type: ignore[arg-type]
117117
default=None,
118118
help="Export the profile in the specified format. [dim]\\[default: no][/]",
119119
)

0 commit comments

Comments
 (0)