Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
------------------

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


0.1.4 - 2022-01-04
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import click
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.enums import ExitCode
from _pytask.exceptions import CollectionError
from _pytask.exceptions import ConfigurationError
from _pytask.exceptions import ExecutionError
from _pytask.exceptions import ResolvingDependenciesError
from _pytask.outcomes import ExitCode
from _pytask.pluginmanager import get_plugin_manager
from _pytask.session import Session

Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from _pytask.config import hookimpl
from _pytask.config import IGNORED_TEMPORARY_FILES_AND_FOLDERS
from _pytask.console import console
from _pytask.enums import ExitCode
from _pytask.exceptions import CollectionError
from _pytask.nodes import MetaTask
from _pytask.outcomes import ExitCode
from _pytask.path import find_common_ancestor
from _pytask.path import relative_to
from _pytask.pluginmanager import get_plugin_manager
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/collect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from _pytask.console import format_task_id
from _pytask.console import PYTHON_ICON
from _pytask.console import TASK_ICON
from _pytask.enums import ExitCode
from _pytask.exceptions import CollectionError
from _pytask.exceptions import ConfigurationError
from _pytask.exceptions import ResolvingDependenciesError
from _pytask.mark import select_by_keyword
from _pytask.mark import select_by_mark
from _pytask.outcomes import ExitCode
from _pytask.path import find_common_ancestor
from _pytask.path import relative_to
from _pytask.pluginmanager import get_plugin_manager
Expand Down
20 changes: 0 additions & 20 deletions src/_pytask/enums.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/_pytask/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.dag import descending_tasks
from _pytask.enums import ExitCode
from _pytask.exceptions import CollectionError
from _pytask.exceptions import ConfigurationError
from _pytask.exceptions import ResolvingDependenciesError
from _pytask.outcomes import ExitCode
from _pytask.pluginmanager import get_plugin_manager
from _pytask.session import Session
from _pytask.shared import get_first_non_none_value
Expand Down
6 changes: 6 additions & 0 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,24 @@ class LiveCollection:

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

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

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

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

def _update_status(self) -> None:
"""Update the status."""
status = self._generate_status()
self._live_manager.update(status)

def _generate_status(self) -> Status:
"""Generate the status."""
msg = f"Collected {self._n_collected_tasks} tasks."
if self._n_errors > 0:
msg += f" {self._n_errors} errors."
Expand Down
2 changes: 2 additions & 0 deletions src/_pytask/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def pytask_parse_config(
config_from_file: Dict[str, Any],
config_from_cli: Dict[str, Any],
) -> None:
"""Parse configuration."""
config["show_locals"] = get_first_non_none_value(
config_from_cli,
config_from_file,
Expand Down Expand Up @@ -138,6 +139,7 @@ def pytask_log_session_footer(


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

# Remove seconds if the execution lasted days or hours.
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/mark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.dag import task_and_preceding_tasks
from _pytask.enums import ExitCode
from _pytask.exceptions import ConfigurationError
from _pytask.mark.expression import Expression
from _pytask.mark.expression import ParseError
Expand All @@ -20,6 +19,7 @@
from _pytask.mark.structures import MarkDecorator
from _pytask.mark.structures import MarkGenerator
from _pytask.nodes import MetaTask
from _pytask.outcomes import ExitCode
from _pytask.pluginmanager import get_plugin_manager
from _pytask.session import Session
from _pytask.shared import convert_truthy_or_falsy_to_bool
Expand Down
23 changes: 23 additions & 0 deletions src/_pytask/outcomes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module contains code related to outcomes."""
from enum import auto
from enum import Enum
from enum import IntEnum
from typing import Dict
from typing import Optional
from typing import Sequence
Expand Down Expand Up @@ -99,6 +100,7 @@ class TaskOutcome(Enum):

@property
def symbol(self) -> str:
"""The symbol of an outcome."""
symbols = {
TaskOutcome.SUCCESS: ".",
TaskOutcome.PERSISTENCE: "p",
Expand All @@ -112,6 +114,7 @@ def symbol(self) -> str:

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

@property
def style(self) -> str:
"""Return the style of an outcome."""
styles = {
TaskOutcome.SUCCESS: "success",
TaskOutcome.PERSISTENCE: "success",
Expand All @@ -138,6 +142,7 @@ def style(self) -> str:

@property
def style_textonly(self) -> str:
"""Return the style of an outcome when only the text is colored."""
styles_textonly = {
TaskOutcome.SUCCESS: "success.textonly",
TaskOutcome.PERSISTENCE: "success.textonly",
Expand Down Expand Up @@ -169,6 +174,24 @@ def count_outcomes(
}


class ExitCode(IntEnum):
"""Exit codes for pytask."""

OK = 0
"""Tasks were executed successfully."""

FAILED = 1
"""Failed while executing tasks."""

CONFIGURATION_FAILED = 2

COLLECTION_FAILED = 3
"""Failed while collecting tasks."""

RESOLVING_DEPENDENCIES_FAILED = 4
"""Failed while resolving dependencies."""


class PytaskOutcome(Exception):
"""Base outcome of a task."""

Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from _pytask.console import console
from _pytask.console import format_task_id
from _pytask.database import db
from _pytask.enums import ExitCode
from _pytask.exceptions import CollectionError
from _pytask.exceptions import ConfigurationError
from _pytask.nodes import FilePathNode
from _pytask.nodes import MetaTask
from _pytask.outcomes import ExitCode
from _pytask.outcomes import TaskOutcome
from _pytask.pluginmanager import get_plugin_manager
from _pytask.report import ExecutionReport
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import attr
import networkx as nx
from _pytask.enums import ExitCode
from _pytask.outcomes import ExitCode


# Location was moved from pluggy v0.13.1 to v1.0.0.
Expand Down
1 change: 1 addition & 0 deletions src/pytask/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contains the main namespace for pytask."""
from _pytask import __version__
from _pytask.build import main
from _pytask.cli import cli
Expand Down
9 changes: 5 additions & 4 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import textwrap

import pytest
from _pytask.outcomes import ExitCode
from pytask import cli


Expand All @@ -13,13 +14,13 @@ def task_raises():
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == 1
assert result.exit_code == ExitCode.FAILED


@pytest.mark.end_to_end
def test_configuration_failed(runner, tmp_path):
result = runner.invoke(cli, [tmp_path.joinpath("non_existent_path").as_posix()])
assert result.exit_code == 2
assert result.exit_code == ExitCode.CONFIGURATION_FAILED


@pytest.mark.end_to_end
Expand All @@ -30,7 +31,7 @@ def test_collection_failed(runner, tmp_path):
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == 3
assert result.exit_code == ExitCode.COLLECTION_FAILED


@pytest.mark.end_to_end
Expand All @@ -51,4 +52,4 @@ def task_passes_2():
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == 4
assert result.exit_code == ExitCode.RESOLVING_DEPENDENCIES_FAILED
9 changes: 5 additions & 4 deletions tests/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from _pytask.capture import CaptureManager
from _pytask.capture import CaptureResult
from _pytask.capture import MultiCapture
from _pytask.outcomes import ExitCode
from pytask import cli


Expand Down Expand Up @@ -78,7 +79,7 @@ def task_show_capture():
cmd_arg = "-s" if show_capture == "s" else f"--show-capture={show_capture}"
result = runner.invoke(cli, [tmp_path.as_posix(), cmd_arg])

assert result.exit_code == 1
assert result.exit_code == ExitCode.FAILED

if show_capture in ["no", "s"]:
assert "Captured" not in result.output
Expand Down Expand Up @@ -197,7 +198,7 @@ def task_unicode():
result = runner.invoke(cli, [tmp_path.as_posix(), f"--capture={method}"])

assert "1 Succeeded" in result.output
assert result.exit_code == 0
assert result.exit_code == ExitCode.OK


@pytest.mark.end_to_end
Expand All @@ -214,7 +215,7 @@ def task_unicode():
result = runner.invoke(cli, [tmp_path.as_posix(), f"--capture={method}"])

assert "1 Succeeded" in result.output
assert result.exit_code == 0
assert result.exit_code == ExitCode.OK


@pytest.mark.end_to_end
Expand Down Expand Up @@ -739,7 +740,7 @@ def task_stdin():
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix(), "--capture=fd"])
assert result.exit_code == 0
assert result.exit_code == ExitCode.OK
assert "3 Succeeded" in result.output

def test_fdcapture_invalid_fd_with_fd_reuse(self, tmp_path):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_clean.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import textwrap

import pytest
from _pytask.outcomes import ExitCode
from pytask import cli


Expand Down Expand Up @@ -153,7 +154,7 @@ def test_configuration_failed(runner, tmp_path):
result = runner.invoke(
cli, ["clean", tmp_path.joinpath("non_existent_path").as_posix()]
)
assert result.exit_code == 2
assert result.exit_code == ExitCode.CONFIGURATION_FAILED


@pytest.mark.end_to_end
Expand All @@ -164,4 +165,4 @@ def test_collection_failed(runner, tmp_path):
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, ["clean", tmp_path.as_posix()])
assert result.exit_code == 3
assert result.exit_code == ExitCode.COLLECTION_FAILED
3 changes: 2 additions & 1 deletion tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from _pytask.nodes import create_task_name
from _pytask.nodes import PythonFunctionTask
from _pytask.outcomes import CollectionOutcome
from _pytask.outcomes import ExitCode
from _pytask.session import Session
from pytask import cli
from pytask import main
Expand Down Expand Up @@ -78,7 +79,7 @@ def task_1(depends_on, produces):

result = runner.invoke(cli, [tmp_path.as_posix()])

assert result.exit_code == 0
assert result.exit_code == ExitCode.OK
assert tmp_path.joinpath("out_0.txt").read_text() == "in root"
assert tmp_path.joinpath("out_1.txt").read_text() == "in sub"

Expand Down
3 changes: 2 additions & 1 deletion tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from _pytask.database import create_database
from _pytask.database import State
from _pytask.outcomes import ExitCode
from pony import orm
from pytask import cli

Expand All @@ -27,7 +28,7 @@ def task_write(produces):
os.chdir(tmp_path)
result = runner.invoke(cli)

assert result.exit_code == 0
assert result.exit_code == ExitCode.OK

with orm.db_session:

Expand Down
3 changes: 2 additions & 1 deletion tests/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest
from _pytask.debugging import _pdbcls_callback
from _pytask.outcomes import ExitCode
from pytask import cli

try:
Expand Down Expand Up @@ -442,7 +443,7 @@ def helper():
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix(), "--show-locals"])
assert result.exit_code == 1
assert result.exit_code == ExitCode.FAILED

captured = result.output
assert " locals " in captured
Expand Down
Loading