Skip to content

Commit 327a0f6

Browse files
authored
Refactorings related to ExitCode. (#188)
1 parent 13aac48 commit 327a0f6

28 files changed

+98
-70
lines changed

docs/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
1111
------------------
1212

1313
- :gh:`186` enhance live displays by deactivating auto-refresh among other things.
14+
- :gh:`188` refactors some code related to :class:`_pytask.enums.ExitCode`.
1415

1516

1617
0.1.4 - 2022-01-04

src/_pytask/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import click
88
from _pytask.config import hookimpl
99
from _pytask.console import console
10-
from _pytask.enums import ExitCode
1110
from _pytask.exceptions import CollectionError
1211
from _pytask.exceptions import ConfigurationError
1312
from _pytask.exceptions import ExecutionError
1413
from _pytask.exceptions import ResolvingDependenciesError
14+
from _pytask.outcomes import ExitCode
1515
from _pytask.pluginmanager import get_plugin_manager
1616
from _pytask.session import Session
1717

src/_pytask/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from _pytask.config import hookimpl
2121
from _pytask.config import IGNORED_TEMPORARY_FILES_AND_FOLDERS
2222
from _pytask.console import console
23-
from _pytask.enums import ExitCode
2423
from _pytask.exceptions import CollectionError
2524
from _pytask.nodes import MetaTask
25+
from _pytask.outcomes import ExitCode
2626
from _pytask.path import find_common_ancestor
2727
from _pytask.path import relative_to
2828
from _pytask.pluginmanager import get_plugin_manager

src/_pytask/collect_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from _pytask.console import format_task_id
1616
from _pytask.console import PYTHON_ICON
1717
from _pytask.console import TASK_ICON
18-
from _pytask.enums import ExitCode
1918
from _pytask.exceptions import CollectionError
2019
from _pytask.exceptions import ConfigurationError
2120
from _pytask.exceptions import ResolvingDependenciesError
2221
from _pytask.mark import select_by_keyword
2322
from _pytask.mark import select_by_mark
23+
from _pytask.outcomes import ExitCode
2424
from _pytask.path import find_common_ancestor
2525
from _pytask.path import relative_to
2626
from _pytask.pluginmanager import get_plugin_manager

src/_pytask/enums.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/_pytask/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from _pytask.config import hookimpl
1414
from _pytask.console import console
1515
from _pytask.dag import descending_tasks
16-
from _pytask.enums import ExitCode
1716
from _pytask.exceptions import CollectionError
1817
from _pytask.exceptions import ConfigurationError
1918
from _pytask.exceptions import ResolvingDependenciesError
19+
from _pytask.outcomes import ExitCode
2020
from _pytask.pluginmanager import get_plugin_manager
2121
from _pytask.session import Session
2222
from _pytask.shared import get_first_non_none_value

src/_pytask/live.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,24 @@ class LiveCollection:
265265

266266
@hookimpl(hookwrapper=True)
267267
def pytask_collect(self) -> Generator[None, None, None]:
268+
"""Start the status of the cllection."""
268269
self._live_manager.start()
269270
yield
270271

271272
@hookimpl
272273
def pytask_collect_file_log(self, reports: List[CollectionReport]) -> None:
274+
"""Update the status after a file is collected."""
273275
self._update_statistics(reports)
274276
self._update_status()
275277

276278
@hookimpl(hookwrapper=True)
277279
def pytask_collect_log(self) -> Generator[None, None, None]:
280+
"""Stop the live display when all tasks have been collected."""
278281
self._live_manager.stop(transient=True)
279282
yield
280283

281284
def _update_statistics(self, reports: List[CollectionReport]) -> None:
285+
"""Update the statistics on collected tasks and errors."""
282286
if reports is None:
283287
reports = []
284288
for report in reports:
@@ -288,10 +292,12 @@ def _update_statistics(self, reports: List[CollectionReport]) -> None:
288292
self._n_errors += 1
289293

290294
def _update_status(self) -> None:
295+
"""Update the status."""
291296
status = self._generate_status()
292297
self._live_manager.update(status)
293298

294299
def _generate_status(self) -> Status:
300+
"""Generate the status."""
295301
msg = f"Collected {self._n_collected_tasks} tasks."
296302
if self._n_errors > 0:
297303
msg += f" {self._n_errors} errors."

src/_pytask/logging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def pytask_parse_config(
5656
config_from_file: Dict[str, Any],
5757
config_from_cli: Dict[str, Any],
5858
) -> None:
59+
"""Parse configuration."""
5960
config["show_locals"] = get_first_non_none_value(
6061
config_from_cli,
6162
config_from_file,
@@ -138,6 +139,7 @@ def pytask_log_session_footer(
138139

139140

140141
def _format_duration(duration: float) -> str:
142+
"""Format the duration."""
141143
duration_tuples = _humanize_time(duration, "seconds", short_label=False)
142144

143145
# Remove seconds if the execution lasted days or hours.

src/_pytask/mark/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from _pytask.config import hookimpl
1212
from _pytask.console import console
1313
from _pytask.dag import task_and_preceding_tasks
14-
from _pytask.enums import ExitCode
1514
from _pytask.exceptions import ConfigurationError
1615
from _pytask.mark.expression import Expression
1716
from _pytask.mark.expression import ParseError
@@ -20,6 +19,7 @@
2019
from _pytask.mark.structures import MarkDecorator
2120
from _pytask.mark.structures import MarkGenerator
2221
from _pytask.nodes import MetaTask
22+
from _pytask.outcomes import ExitCode
2323
from _pytask.pluginmanager import get_plugin_manager
2424
from _pytask.session import Session
2525
from _pytask.shared import convert_truthy_or_falsy_to_bool

src/_pytask/outcomes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module contains code related to outcomes."""
22
from enum import auto
33
from enum import Enum
4+
from enum import IntEnum
45
from typing import Dict
56
from typing import Optional
67
from typing import Sequence
@@ -99,6 +100,7 @@ class TaskOutcome(Enum):
99100

100101
@property
101102
def symbol(self) -> str:
103+
"""The symbol of an outcome."""
102104
symbols = {
103105
TaskOutcome.SUCCESS: ".",
104106
TaskOutcome.PERSISTENCE: "p",
@@ -112,6 +114,7 @@ def symbol(self) -> str:
112114

113115
@property
114116
def description(self) -> str:
117+
"""A description of an outcome used in the summary panel."""
115118
descriptions = {
116119
TaskOutcome.SUCCESS: "Succeeded",
117120
TaskOutcome.PERSISTENCE: "Persisted",
@@ -125,6 +128,7 @@ def description(self) -> str:
125128

126129
@property
127130
def style(self) -> str:
131+
"""Return the style of an outcome."""
128132
styles = {
129133
TaskOutcome.SUCCESS: "success",
130134
TaskOutcome.PERSISTENCE: "success",
@@ -138,6 +142,7 @@ def style(self) -> str:
138142

139143
@property
140144
def style_textonly(self) -> str:
145+
"""Return the style of an outcome when only the text is colored."""
141146
styles_textonly = {
142147
TaskOutcome.SUCCESS: "success.textonly",
143148
TaskOutcome.PERSISTENCE: "success.textonly",
@@ -169,6 +174,24 @@ def count_outcomes(
169174
}
170175

171176

177+
class ExitCode(IntEnum):
178+
"""Exit codes for pytask."""
179+
180+
OK = 0
181+
"""Tasks were executed successfully."""
182+
183+
FAILED = 1
184+
"""Failed while executing tasks."""
185+
186+
CONFIGURATION_FAILED = 2
187+
188+
COLLECTION_FAILED = 3
189+
"""Failed while collecting tasks."""
190+
191+
RESOLVING_DEPENDENCIES_FAILED = 4
192+
"""Failed while resolving dependencies."""
193+
194+
172195
class PytaskOutcome(Exception):
173196
"""Base outcome of a task."""
174197

0 commit comments

Comments
 (0)