Skip to content

Publish types, classes, and functions. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 20, 2022
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
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ repos:
rev: 1.5.0
hooks:
- id: interrogate
args: [-v, --fail-under=40, src, tests]
args: [-v, --fail-under=75]
exclude: ^(tests/|docs/)
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
Expand All @@ -90,6 +91,8 @@ repos:
rev: "0.47"
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools-scm, toml]
- repo: https://github.com/guilatrova/tryceratops
rev: v1.0.1
hooks:
Expand All @@ -108,7 +111,6 @@ repos:
types-setuptools
]
pass_filenames: false
language_version: "3.9"
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include CITATION
include LICENSE

recursive-include src py.typed

exclude .coveragerc
exclude *.yaml
exclude *.yml
Expand Down
1 change: 1 addition & 0 deletions docs/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies:
- pony >=0.7.15
- pexpect
- rich
- typing-extensions

- pip:
- ../
1 change: 1 addition & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
0.1.9 - 2022-xx-xx
------------------

- :gh:`197` publishes types, and adds classes and functions to the main namespace.
- :gh:`217` enhances the tutorial on how to set up a project.
- :gh:`218` removes ``depends_on`` and ``produces`` from the task function when parsed.
- :gh:`219` removes some leftovers from pytest in :class:`~_pytask.mark.Mark`.
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- pluggy
- pony >=0.7.15
- rich
- typing-extensions

# Misc
- black
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
build-backend = "setuptools.build_meta"


[tool.setuptools_scm]
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ install_requires =
pluggy
pony>=0.7.15
rich
typing-extensions
python_requires = >=3.7
include_package_data = True
package_dir =
Expand Down
7 changes: 0 additions & 7 deletions setup.py

This file was deleted.

8 changes: 8 additions & 0 deletions src/_pytask/click.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contains code related to click."""
from __future__ import annotations

from typing import Any
Expand All @@ -18,11 +19,16 @@


class OptionHighlighter(RegexHighlighter):
"""A highlighter for help texts."""

highlights = [_SWITCH_REGEX, _OPTION_REGEX, _METAVAR_REGEX]


class ColoredGroup(DefaultGroup):
"""A subclass which colors groups with default commands."""

def format_help(self: DefaultGroup, ctx: Any, formatter: Any) -> None: # noqa: U100
"""Format the help text."""
highlighter = OptionHighlighter()

console.print(
Expand Down Expand Up @@ -71,6 +77,7 @@ class ColoredCommand(click.Command):
def format_help(
self: click.Command, ctx: Any, formatter: Any # noqa: U100
) -> None:
"""Format the help text."""
console.print(
f"[b]pytask[/b] [dim]v{version}[/]\n", justify="center", highlight=False
)
Expand All @@ -91,6 +98,7 @@ def format_help(


def print_options(group_or_command: click.Command | DefaultGroup, ctx: Any) -> None:
"""Print options formatted with a table in a panel."""
highlighter = OptionHighlighter()

options_table = Table(highlight=True, box=None, show_header=False)
Expand Down
3 changes: 3 additions & 0 deletions src/_pytask/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from packaging.version import parse as parse_version


__all__ = ["check_for_optional_program", "import_optional_dependency"]


_MINIMUM_VERSIONS: dict[str, str] = {}
"""Dict[str, str]: A mapping from packages to their minimum versions."""

Expand Down
18 changes: 18 additions & 0 deletions src/_pytask/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
from _pytask.report import ExecutionReport


__all__ = [
"count_outcomes",
"CollectionOutcome",
"Exit",
"ExitCode",
"Persisted",
"PytaskOutcome",
"Skipped",
"SkippedUnchanged",
"SkippedAncestorFailed",
"TaskOutcome",
]


class CollectionOutcome(Enum):
"""Outcomes of collected files or tasks.

Expand All @@ -30,6 +44,7 @@ class CollectionOutcome(Enum):

@property
def symbol(self) -> str:
"""The symbol of an outcome."""
symbols = {
CollectionOutcome.SUCCESS: ".",
CollectionOutcome.FAIL: "F",
Expand All @@ -39,6 +54,7 @@ def symbol(self) -> str:

@property
def description(self) -> str:
"""A description of an outcome used in the summary panel."""
descriptions = {
CollectionOutcome.SUCCESS: "Succeeded",
CollectionOutcome.FAIL: "Failed",
Expand All @@ -48,6 +64,7 @@ def description(self) -> str:

@property
def style(self) -> str:
"""Return the style of an outcome."""
styles = {
CollectionOutcome.SUCCESS: "success",
CollectionOutcome.FAIL: "failed",
Expand All @@ -57,6 +74,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 = {
CollectionOutcome.SUCCESS: "success.textonly",
CollectionOutcome.FAIL: "failed.textonly",
Expand Down
Empty file added src/_pytask/py.typed
Empty file.
1 change: 1 addition & 0 deletions src/_pytask/resolve_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contains code related to resolving dependencies."""
from __future__ import annotations

import itertools
Expand Down
5 changes: 3 additions & 2 deletions src/_pytask/session.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contains code related to the session object."""
from __future__ import annotations

from typing import Any
Expand All @@ -13,9 +14,9 @@

# Location was moved from pluggy v0.13.1 to v1.0.0.
try:
from pluggy.hooks import _HookRelay
except ImportError:
from pluggy._hooks import _HookRelay
except ImportError:
from pluggy.hooks import _HookRelay


if TYPE_CHECKING:
Expand Down
2 changes: 2 additions & 0 deletions src/_pytask/task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contain hooks related to the ``@pytask.mark.task`` decorator."""
from __future__ import annotations

from pathlib import Path
Expand All @@ -12,6 +13,7 @@

@hookimpl
def pytask_parse_config(config: dict[str, Any]) -> None:
"""Parse the configuration."""
config["markers"]["task"] = "Mark a function as a task regardless of its name."


Expand Down
3 changes: 3 additions & 0 deletions src/_pytask/task_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This module contains utilities related to the ``@pytask.mark.task`` decorator."""
from __future__ import annotations

from typing import Any
Expand All @@ -8,10 +9,12 @@


def task(name: str | None = None) -> str:
"""Parse inputs of the ``@pytask.mark.task`` decorator."""
return name


def parse_task_marker(obj: Callable[..., Any]) -> str:
"""Parse the ``@pytask.mark.task`` decorator."""
obj, task_markers = remove_markers_from_func(obj, "task")

if len(task_markers) != 1:
Expand Down
57 changes: 56 additions & 1 deletion src/pytask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,64 @@
from _pytask import __version__
from _pytask.build import main
from _pytask.cli import cli
from _pytask.compat import check_for_optional_program
from _pytask.compat import import_optional_dependency
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.graph import build_dag
from _pytask.mark import Mark
from _pytask.mark import MARK_GEN as mark # noqa: N811
from _pytask.mark import MarkDecorator
from _pytask.mark import MarkGenerator
from _pytask.mark_utils import get_marks_from_obj
from _pytask.mark_utils import get_specific_markers_from_task
from _pytask.mark_utils import has_marker
from _pytask.mark_utils import remove_markers_from_func
from _pytask.nodes import FilePathNode
from _pytask.nodes import MetaNode
from _pytask.nodes import MetaTask
from _pytask.nodes import PythonFunctionTask
from _pytask.outcomes import CollectionOutcome
from _pytask.outcomes import count_outcomes
from _pytask.outcomes import Exit
from _pytask.outcomes import ExitCode
from _pytask.outcomes import Persisted
from _pytask.outcomes import Skipped
from _pytask.outcomes import SkippedAncestorFailed
from _pytask.outcomes import SkippedUnchanged
from _pytask.outcomes import TaskOutcome
from _pytask.session import Session


__all__ = ["__version__", "build_dag", "cli", "hookimpl", "main", "mark"]
__all__ = [
"__version__",
"build_dag",
"check_for_optional_program",
"cli",
"console",
"count_outcomes",
"get_marks_from_obj",
"get_specific_markers_from_task",
"has_marker",
"hookimpl",
"import_optional_dependency",
"main",
"mark",
"remove_markers_from_func",
"CollectionOutcome",
"Exit",
"ExitCode",
"FilePathNode",
"Mark",
"MarkDecorator",
"MarkGenerator",
"MetaNode",
"MetaTask",
"Persisted",
"PythonFunctionTask",
"Session",
"Skipped",
"SkippedAncestorFailed",
"SkippedUnchanged",
"TaskOutcome",
]
Empty file added src/pytask/py.typed
Empty file.
2 changes: 1 addition & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import textwrap

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


@pytest.mark.end_to_end
Expand Down
2 changes: 1 addition & 1 deletion tests/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from _pytask.capture import CaptureManager
from _pytask.capture import CaptureResult
from _pytask.capture import MultiCapture
from _pytask.outcomes import ExitCode
from pytask import cli
from pytask import ExitCode


@pytest.mark.unit
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import textwrap

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


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import subprocess

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


@pytest.mark.end_to_end
Expand Down
13 changes: 7 additions & 6 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
import textwrap
import warnings
from contextlib import ExitStack as does_not_raise # noqa: N813
from pathlib import Path

Expand All @@ -10,12 +11,12 @@
from _pytask.collect import pytask_collect_node
from _pytask.exceptions import NodeNotCollectedError
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 CollectionOutcome
from pytask import ExitCode
from pytask import main
from pytask import PythonFunctionTask
from pytask import Session


@pytest.mark.end_to_end
Expand Down Expand Up @@ -176,11 +177,11 @@ def test_pytask_collect_node_does_not_raise_error_if_path_is_not_normalized(
if is_absolute:
collected_node = tmp_path / collected_node

with pytest.warns(None) as record:
with warnings.catch_warnings() as record:
result = pytask_collect_node(session, task_path, collected_node)
assert not record

assert str(result.path) == str(real_node)
assert not record


@pytest.mark.unit
Expand Down
4 changes: 2 additions & 2 deletions tests/test_collect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import pytest
from _pytask.collect_command import _find_common_ancestor_of_all_nodes
from _pytask.collect_command import _print_collected_tasks
from _pytask.nodes import MetaNode
from _pytask.nodes import MetaTask
from pytask import cli
from pytask import MetaNode
from pytask import MetaTask


@pytest.mark.end_to_end
Expand Down
Loading