Skip to content

Commit

Permalink
Merge b3c68ed into 5c9c59a
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasraabe committed Sep 4, 2023
2 parents 5c9c59a + b3c68ed commit ae1206e
Show file tree
Hide file tree
Showing 53 changed files with 296 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1
with:
environment-name: gha-testing
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-plugin-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`410` allows to pass functions to `PythonNode(hash=...)`.
- {pull}`412` adds protocols for tasks.
- {pull}`413` removes scripts to generate `.svg`s.
- {pull}`414` allow more ruff rules.

## 0.3.2 - 2023-06-07

Expand Down
4 changes: 3 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from __future__ import annotations

from importlib.metadata import version
from typing import TYPE_CHECKING

import sphinx
if TYPE_CHECKING:
import sphinx


# -- Project information ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- click
- click-default-group
- networkx >=2.4
- pluggy
- pluggy >=1.0.0
- optree >=0.9
- rich
- sqlalchemy >=1.4.36
Expand Down
12 changes: 2 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ target-version = "py38"
select = ["ALL"]
fix = true
extend-ignore = [
"I", # ignore isort
"TRY", # ignore tryceratops.
"TCH", # ignore non-guarded type imports.
# Numpy docstyle
"D107",
"D203",
Expand All @@ -46,25 +46,17 @@ extend-ignore = [
"D416",
"D417",
# Others.
"D404", # Do not start module docstring with "This".
"RET504", # unnecessary variable assignment before return.
"S101", # raise errors for asserts.
"B905", # strict parameter for zip that was implemented in py310.
"I", # ignore isort
"ANN101", # type annotating self
"ANN102", # type annotating cls
"FBT", # flake8-boolean-trap
"EM", # flake8-errmsg
"ANN401", # flake8-annotate typing.Any
"PD", # pandas-vet
"COM812", # trailing comma missing, but black takes care of that
"D401", # imperative mood for first line. too many false-positives.
"SLF001", # access private members.
"S603",
"S607",
# Temporary
"TD002",
"TD003",
]


Expand All @@ -73,7 +65,7 @@ extend-ignore = [
"src/_pytask/hookspecs.py" = ["ARG001"]
"src/_pytask/outcomes.py" = ["N818"]
"tests/test_capture.py" = ["T201", "PT011"]
"tests/*" = ["D", "ANN", "PLR2004"]
"tests/*" = ["D", "ANN", "PLR2004", "S101"]
"scripts/*" = ["D", "INP001"]
"docs/source/conf.py" = ["D401", "INP001"]

Expand Down
3 changes: 1 addition & 2 deletions scripts/update_plugin_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def _escape_rst(text: str) -> str:
.replace(">", "\\>")
.replace("`", "\\`")
)
text = re.sub(r"_\b", "", text)
return text
return re.sub(r"_\b", "", text)


def _iter_plugins() -> Generator[dict[str, str], None, None]: # noqa: C901
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install_requires =
networkx>=2.4
optree>=0.9
packaging
pluggy
pluggy>=1.0.0
rich
sqlalchemy>=1.4.36
tomli>=1.0.0
Expand Down
9 changes: 5 additions & 4 deletions src/_pytask/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915
obj_locals = None
unwrap = obj
else:
raise TypeError(f"{obj!r} is not a module, class, or callable.")
msg = f"{obj!r} is not a module, class, or callable."
raise TypeError(msg)

Check warning on line 103 in src/_pytask/_inspect.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/_inspect.py#L102-L103

Added lines #L102 - L103 were not covered by tests

if ann is None:
return {}

if not isinstance(ann, dict):
raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None")
msg = f"{obj!r}.__annotations__ is neither a dict nor None"
raise ValueError(msg)

Check warning on line 110 in src/_pytask/_inspect.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/_inspect.py#L109-L110

Added lines #L109 - L110 were not covered by tests

if not ann:
return {}
Expand All @@ -131,10 +133,9 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915
locals = obj_locals # noqa: A001

eval_func = eval
return_value = {
return {

Check warning on line 136 in src/_pytask/_inspect.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/_inspect.py#L136

Added line #L136 was not covered by tests
key: value
if not isinstance(value, str)
else eval_func(value, globals, locals)
for key, value in ann.items()
}
return return_value
35 changes: 24 additions & 11 deletions src/_pytask/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
from typing import Generic
from typing import Iterator
from typing import TextIO
from typing import TYPE_CHECKING

import click
from _pytask.click import EnumChoice
from _pytask.config import hookimpl
from _pytask.enums import ShowCapture
from _pytask.node_protocols import PTask

if TYPE_CHECKING:
from _pytask.node_protocols import PTask


class _CaptureMethod(enum.Enum):
Expand Down Expand Up @@ -148,9 +151,10 @@ class DontReadFromInput:
encoding = None

def read(self, *_args: Any) -> None:
raise OSError(
msg = (
"pytask: reading from stdin while output is captured! Consider using `-s`."
)
raise OSError(msg)

readline = read
readlines = read
Expand All @@ -160,10 +164,12 @@ def __iter__(self) -> DontReadFromInput:
return self

def fileno(self) -> int:
raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")
msg = "redirected stdin is pseudofile, has no fileno()"
raise UnsupportedOperation(msg)

Check warning on line 168 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L167-L168

Added lines #L167 - L168 were not covered by tests

def flush(self) -> None:
raise UnsupportedOperation("redirected stdin is pseudofile, has no flush()")
msg = "redirected stdin is pseudofile, has no flush()"
raise UnsupportedOperation(msg)

Check warning on line 172 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L171-L172

Added lines #L171 - L172 were not covered by tests

def isatty(self) -> bool:
return False
Expand All @@ -175,22 +181,27 @@ def readable(self) -> bool:
return False

def seek(self, offset: int) -> int: # noqa: ARG002
raise UnsupportedOperation("Redirected stdin is pseudofile, has no seek(int).")
msg = "Redirected stdin is pseudofile, has no seek(int)."
raise UnsupportedOperation(msg)

Check warning on line 185 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L184-L185

Added lines #L184 - L185 were not covered by tests

def seekable(self) -> bool:
return False

def tell(self) -> int:
raise UnsupportedOperation("Redirected stdin is pseudofile, has no tell().")
msg = "Redirected stdin is pseudofile, has no tell()."
raise UnsupportedOperation(msg)

Check warning on line 192 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L191-L192

Added lines #L191 - L192 were not covered by tests

def truncate(self, size: int) -> None: # noqa: ARG002
raise UnsupportedOperation("Cannot truncate stdin.")
msg = "Cannot truncate stdin."
raise UnsupportedOperation(msg)

Check warning on line 196 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L195-L196

Added lines #L195 - L196 were not covered by tests

def write(self, *args: Any) -> None: # noqa: ARG002
raise UnsupportedOperation("Cannot write to stdin.")
msg = "Cannot write to stdin."
raise UnsupportedOperation(msg)

Check warning on line 200 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L199-L200

Added lines #L199 - L200 were not covered by tests

def writelines(self, *args: Any) -> None: # noqa: ARG002
raise UnsupportedOperation("Cannot write to stdin.")
msg = "Cannot write to stdin."
raise UnsupportedOperation(msg)

Check warning on line 204 in src/_pytask/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/capture.py#L203-L204

Added lines #L203 - L204 were not covered by tests

def writable(self) -> bool:
return False
Expand Down Expand Up @@ -611,7 +622,8 @@ def resume_capturing(self) -> None:
def stop_capturing(self) -> None:
"""Stop capturing and reset capturing streams."""
if self._state == "stopped":
raise ValueError("was already stopped")
msg = "was already stopped"
raise ValueError(msg)
self._state = "stopped"
if self.out:
self.out.done()
Expand Down Expand Up @@ -647,7 +659,8 @@ def _get_multicapture(method: _CaptureMethod) -> MultiCapture[str]:
return MultiCapture(
in_=None, out=SysCapture(1, tee=True), err=SysCapture(2, tee=True)
)
raise ValueError(f"unknown capturing method: {method!r}")
msg = f"unknown capturing method: {method!r}"
raise ValueError(msg)


# Own implementation of the CaptureManager.
Expand Down
5 changes: 2 additions & 3 deletions src/_pytask/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import shutil
import sys
from pathlib import Path
from types import TracebackType
from typing import Any
from typing import Generator
from typing import Iterable
Expand Down Expand Up @@ -36,6 +35,7 @@


if TYPE_CHECKING:
from types import TracebackType
from typing import NoReturn


Expand Down Expand Up @@ -242,15 +242,14 @@ def _find_all_unknown_paths(
_RecursivePathNode.from_path(path, known_paths, exclude)
for path in session.config["paths"]
]
unknown_paths = list(
return list(
itertools.chain.from_iterable(
[
_find_all_unkown_paths_per_recursive_node(node, include_directories)
for node in recursive_nodes
]
)
)
return unknown_paths


@define(repr=False)
Expand Down
5 changes: 4 additions & 1 deletion src/_pytask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

import sys
from typing import Any
from typing import TYPE_CHECKING

import click
import pluggy
from _pytask.click import ColoredGroup
from _pytask.config import hookimpl
from _pytask.pluginmanager import get_plugin_manager
from packaging.version import parse as parse_version

if TYPE_CHECKING:
import pluggy


_CONTEXT_SETTINGS: dict[str, Any] = {
"help_option_names": ("-h", "--help"),
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/click.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module contains code related to click."""
"""Contains code related to click."""
from __future__ import annotations

import enum
Expand Down
10 changes: 6 additions & 4 deletions src/_pytask/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any
from typing import Generator
from typing import Iterable
from typing import TYPE_CHECKING

from _pytask.collect_utils import parse_dependencies_from_task_function
from _pytask.collect_utils import parse_products_from_task_function
Expand All @@ -20,7 +21,6 @@
from _pytask.console import format_task_name
from _pytask.exceptions import CollectionError
from _pytask.mark_utils import has_mark
from _pytask.models import NodeInfo
from _pytask.node_protocols import Node
from _pytask.node_protocols import PTask
from _pytask.nodes import PathNode
Expand All @@ -31,12 +31,15 @@
from _pytask.path import find_case_sensitive_path
from _pytask.path import import_path
from _pytask.report import CollectionReport
from _pytask.session import Session
from _pytask.shared import find_duplicates
from _pytask.shared import reduce_node_name
from _pytask.traceback import render_exc_info
from rich.text import Text

if TYPE_CHECKING:
from _pytask.session import Session
from _pytask.models import NodeInfo


@hookimpl
def pytask_collect(session: Session) -> bool:
Expand Down Expand Up @@ -81,8 +84,7 @@ def _collect_from_paths(session: Session) -> None:
@hookimpl
def pytask_ignore_collect(path: Path, config: dict[str, Any]) -> bool:
"""Ignore a path during the collection."""
is_ignored = any(path.match(pattern) for pattern in config["ignore"])
return is_ignored
return any(path.match(pattern) for pattern in config["ignore"])


@hookimpl
Expand Down
8 changes: 3 additions & 5 deletions src/_pytask/collect_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""This module contains the implementation of ``pytask collect``."""
"""Contains the implementation of ``pytask collect``."""
from __future__ import annotations

import sys
from collections import defaultdict
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -35,6 +34,7 @@


if TYPE_CHECKING:
from pathlib import Path
from typing import NoReturn


Expand Down Expand Up @@ -134,9 +134,7 @@ def _find_common_ancestor_of_all_nodes(
x.path for x in tree_leaves(task.produces) if isinstance(x, PPathNode)
)

common_ancestor = find_common_ancestor(*all_paths, *paths)

return common_ancestor
return find_common_ancestor(*all_paths, *paths)


def _organize_tasks(tasks: list[PTaskWithPath]) -> dict[Path, list[PTaskWithPath]]:
Expand Down

0 comments on commit ae1206e

Please sign in to comment.