Skip to content

[pre-commit.ci] pre-commit autoupdate #388

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 4 commits into from
Aug 27, 2023
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
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ repos:
- id: python-no-log-warn
- id: text-unicode-replacement-char
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.9.0
rev: v3.10.0
hooks:
- id: reorder-python-imports
args: [--py38-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.3.0
rev: v2.4.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
rev: v0.0.286
hooks:
- id: ruff
- repo: https://github.com/dosisod/refurb
rev: v1.16.0
rev: v1.20.0
hooks:
- id: refurb
args: [--ignore, FURB126]
Expand All @@ -52,7 +52,7 @@ repos:
args: [-vv, --fail-under=75]
exclude: ^(tests/|docs/|scripts/)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.3.0'
rev: 'v1.5.1'
hooks:
- id: mypy
args: [
Expand All @@ -66,7 +66,7 @@ repos:
]
pass_filenames: false
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [
Expand All @@ -76,7 +76,7 @@ repos:
args: [--wrap, "88"]
files: (README\.md)
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [
Expand All @@ -101,7 +101,7 @@ repos:
docs/source/tutorials/set_up_a_project.md
)$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.5
hooks:
- id: codespell
additional_dependencies: [tomli]
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ markers = [
]
norecursedirs = [".idea", ".tox"]
filterwarnings = ["ignore:'@pytask.mark.*. is deprecated:DeprecationWarning"]


[tool.refurb]
python_version = "3.8"
3 changes: 2 additions & 1 deletion src/_pytask/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspect
from gettext import gettext as _
from typing import Any
from typing import ClassVar

import click
from _pytask import __version__ as version
Expand Down Expand Up @@ -55,7 +56,7 @@ def convert(
class _OptionHighlighter(RegexHighlighter):
"""A highlighter for help texts."""

highlights = [
highlights: ClassVar = [
r"(?P<switch>\-\w)\b",
r"(?P<option>\-\-[\w\-]+)",
r"\-\-[\w\-]+(?P<metavar>[ |=][\w\.:]+)",
Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/collect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def _merge_dictionaries(list_of_dicts: list[dict[Any, Any]]) -> dict[Any, Any]:
"""
merged_dict = _union_of_dictionaries(list_of_dicts)

if len(merged_dict) == 1 and isinstance(list(merged_dict)[0], _Placeholder):
placeholder, value = list(merged_dict.items())[0]
if len(merged_dict) == 1 and isinstance(next(iter(merged_dict)), _Placeholder):
placeholder, value = next(iter(merged_dict.items()))
out = value if placeholder.scalar else {0: value}
else:
counter = itertools.count()
Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def set_defaults_from_config(
context: click.Context, param: click.Parameter, value: Any # noqa: ARG001
) -> Path | None:
"""Set the defaults for the command-line interface from the configuration."""
# Hack: pytask will later walk through all configuration hooks, even the ones not
# related to this command. They might expect the defaults coming from their related
# pytask will later walk through all configuration hooks, even the ones not related
# to this command. They might expect the defaults coming from their related
# command-line options during parsing. Here, we add their defaults to the
# configuration.
command_option_names = [option.name for option in context.command.params]
Expand Down
6 changes: 4 additions & 2 deletions src/_pytask/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ def create_url_style_for_path(path: Path, edtior_url_scheme: str) -> Style:
)


def _get_file(function: Callable[..., Any], skipped_paths: list[Path] = None) -> Path:
def _get_file(
function: Callable[..., Any], skipped_paths: list[Path] | None = None
) -> Path:
"""Get path to module where the function is defined.

When the ``pdb`` or ``trace`` mode is activated, every task function is wrapped with
Expand Down Expand Up @@ -255,7 +257,7 @@ def unify_styles(*styles: str | Style) -> Style:

def create_summary_panel(
counts: dict[Enum, int],
outcome_enum: type[CollectionOutcome] | type[TaskOutcome],
outcome_enum: type[CollectionOutcome | TaskOutcome],
description_total: str,
) -> Panel:
"""Create a summary panel."""
Expand Down
3 changes: 2 additions & 1 deletion src/_pytask/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from types import FrameType
from types import TracebackType
from typing import Any
from typing import ClassVar
from typing import Generator
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -111,7 +112,7 @@ class PytaskPDB:

_pluginmanager: pluggy.PluginManager | None = None
_config: dict[str, Any] | None = None
_saved: list[tuple[Any, ...]] = []
_saved: ClassVar[list[tuple[Any, ...]]] = []
_recursive_debug: int = 0
_wrapped_pdb_cls: tuple[type[pdb.Pdb], type[pdb.Pdb]] | None = None

Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def is_git_installed() -> bool:

def cmd_output(*cmd: str, **kwargs: Any) -> tuple[int, str, str]:
"""Execute a command and capture the output."""
r = subprocess.run(cmd, capture_output=True, **kwargs)
r = subprocess.run(cmd, capture_output=True, check=False, **kwargs)
stdout = r.stdout.decode() if r.stdout is not None else None
stderr = r.stderr.decode() if r.stderr is not None else None
return r.returncode, stdout, stderr


def init_repo(path: Path) -> None:
"""Initialize a git repository."""
subprocess.run(("git", "init"), cwd=path)
subprocess.run(("git", "init"), check=False, cwd=path)


def zsplit(s: str) -> list[str]:
Expand Down
12 changes: 6 additions & 6 deletions src/_pytask/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import TYPE_CHECKING

import click
import networkx
import networkx as nx
import pluggy
from _pytask.models import NodeInfo
from _pytask.node_protocols import MetaNode
Expand Down Expand Up @@ -226,7 +226,7 @@ def pytask_dag(session: Session) -> None:


@hookspec(firstresult=True)
def pytask_dag_create_dag(session: Session, tasks: list[Task]) -> networkx.DiGraph:
def pytask_dag_create_dag(session: Session, tasks: list[Task]) -> nx.DiGraph:
"""Create the DAG.

This hook creates the DAG from tasks, dependencies and products. The DAG can be used
Expand All @@ -236,7 +236,7 @@ def pytask_dag_create_dag(session: Session, tasks: list[Task]) -> networkx.DiGra


@hookspec
def pytask_dag_modify_dag(session: Session, dag: networkx.DiGraph) -> None:
def pytask_dag_modify_dag(session: Session, dag: nx.DiGraph) -> None:
"""Modify the DAG.

This hook allows to make some changes to the DAG before it is validated and tasks
Expand All @@ -246,7 +246,7 @@ def pytask_dag_modify_dag(session: Session, dag: networkx.DiGraph) -> None:


@hookspec(firstresult=True)
def pytask_dag_validate_dag(session: Session, dag: networkx.DiGraph) -> None:
def pytask_dag_validate_dag(session: Session, dag: nx.DiGraph) -> None:
"""Validate the DAG.

This hook validates the DAG. For example, there can be cycles in the DAG if tasks,
Expand All @@ -256,7 +256,7 @@ def pytask_dag_validate_dag(session: Session, dag: networkx.DiGraph) -> None:


@hookspec
def pytask_dag_select_execution_dag(session: Session, dag: networkx.DiGraph) -> None:
def pytask_dag_select_execution_dag(session: Session, dag: nx.DiGraph) -> None:
"""Select the subgraph which needs to be executed.

This hook determines which of the tasks have to be re-run because something has
Expand All @@ -267,7 +267,7 @@ def pytask_dag_select_execution_dag(session: Session, dag: networkx.DiGraph) ->

@hookspec(firstresult=True)
def pytask_dag_has_node_changed(
session: Session, dag: networkx.DiGraph, node: MetaNode, task_name: str
session: Session, dag: nx.DiGraph, node: MetaNode, task_name: str
) -> None:
"""Select the subgraph which needs to be executed.

Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _format_duration(duration: float) -> str:


def _humanize_time( # noqa: C901, PLR0912
amount: int | float, unit: str, short_label: bool = False
amount: float, unit: str, short_label: bool = False
) -> list[tuple[float, str]]:
"""Humanize the time.

Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/mark/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def select_by_mark(session: Session, dag: nx.DiGraph) -> set[str]: ...

class MARK_GEN: # noqa: N801
@deprecated(
"'@pytask.mark.produces' is deprecated starting pytask v0.4.0 and will be removed in v0.5.0. To upgrade your project to the new syntax, read the tutorial on product and dependencies: https://tinyurl.com/yrezszr4.", # noqa: E501
"'@pytask.mark.produces' is deprecated starting pytask v0.4.0 and will be removed in v0.5.0. To upgrade your project to the new syntax, read the tutorial on product and dependencies: https://tinyurl.com/yrezszr4.", # noqa: E501, PYI053
category=DeprecationWarning,
stacklevel=1,
)
@staticmethod
def produces(objects: PyTree[str | Path]) -> None: ...
@deprecated(
"'@pytask.mark.depends_on' is deprecated starting pytask v0.4.0 and will be removed in v0.5.0. To upgrade your project to the new syntax, read the tutorial on product and dependencies: https://tinyurl.com/yrezszr4.", # noqa: E501
"'@pytask.mark.depends_on' is deprecated starting pytask v0.4.0 and will be removed in v0.5.0. To upgrade your project to the new syntax, read the tutorial on product and dependencies: https://tinyurl.com/yrezszr4.", # noqa: E501, PYI053
category=DeprecationWarning,
stacklevel=1,
)
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/mark/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def evaluate(self, matcher: Callable[[str], bool]) -> bool:
Whether the expression matches or not.

"""
ret: bool = eval( # noqa: PGH001
ret: bool = eval( # noqa: PGH001, S307
self.code, {"__builtins__": {}}, MatcherAdapter(matcher)
)
return ret
2 changes: 1 addition & 1 deletion src/_pytask/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def style_textonly(self) -> str:

def count_outcomes(
reports: Sequence[CollectionReport | ExecutionReport],
outcome_enum: type[CollectionOutcome] | type[TaskOutcome],
outcome_enum: type[CollectionOutcome | TaskOutcome],
) -> dict[Enum, int]:
"""Count how often an outcome occurred.

Expand Down
4 changes: 3 additions & 1 deletion src/_pytask/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def parse_paths(x: Any | None) -> list[Path] | None:
if x is not None:
paths = [Path(p) for p in to_list(x)]
paths = [
Path(p).resolve() for path in paths for p in glob.glob(path.as_posix())
Path(p).resolve()
for path in paths
for p in glob.glob(path.as_posix()) # noqa: PTH207
]
out = paths
else:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/task_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse_collected_tasks_with_task_marker(
for unique_name, task in names_to_functions.items():
collected_tasks[unique_name] = task
else:
collected_tasks[name] = [i[1] for i in parsed_tasks if i[0] == name][0]
collected_tasks[name] = next(i[1] for i in parsed_tasks if i[0] == name)

return collected_tasks

Expand Down
2 changes: 1 addition & 1 deletion tests/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_captureresult() -> None:
assert err == "err"
assert cr[0] == "out"
assert cr[1] == "err"
assert cr == cr
assert cr == cr # noqa: PLR0124
assert cr == CaptureResult("out", "err")
assert cr != CaptureResult("wrong", "err")
assert cr == ("out", "err")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def git_project(request, tmp_path):

init_repo(tmp_path)
subprocess.run(
("git", "add", "task_module.py", "in_tracked.txt", "tracked.txt"), cwd=tmp_path
("git", "add", "task_module.py", "in_tracked.txt", "tracked.txt"),
cwd=tmp_path,
check=False,
)
subprocess.run(("git", "commit", "-m", "'COMMIT'"), cwd=tmp_path)
subprocess.run(("git", "commit", "-m", "'COMMIT'"), cwd=tmp_path, check=False)

return tmp_path

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.mark.end_to_end()
def test_version_option():
process = subprocess.run(["pytask", "--version"], capture_output=True)
process = subprocess.run(["pytask", "--version"], capture_output=True, check=False)
assert "pytask, version " + __version__ in process.stdout.decode("utf-8")


Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@pytest.mark.end_to_end()
def test_python_m_pytask(tmp_path):
tmp_path.joinpath("task_module.py").write_text("def task_example(): pass")
subprocess.run(["python", "-m", "pytask", tmp_path.as_posix()], check=True)
subprocess.run(["python", "-m", "pytask", tmp_path.as_posix()], check=False)


@pytest.mark.end_to_end()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ def task_write_text(depends_on, produces):
tmp_path.joinpath("in.txt").touch()

result = subprocess.run(
("pytest", tmp_path.joinpath("task_module.py").as_posix()), capture_output=True
("pytest", tmp_path.joinpath("task_module.py").as_posix()),
capture_output=True,
check=False,
)
assert b"DeprecationWarning: '@pytask.mark.depends_on'" in result.stdout
assert b"DeprecationWarning: '@pytask.mark.produces'" in result.stdout
2 changes: 1 addition & 1 deletion tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def warn_now():
path_to_warn_module.write_text(textwrap.dedent(warn_module))

# Cannot use runner since then warnings are not ignored by default.
result = subprocess.run(("pytask"), cwd=tmp_path, capture_output=True)
result = subprocess.run(("pytask"), cwd=tmp_path, capture_output=True, check=False)

assert result.returncode == ExitCode.OK
assert "Warnings" not in result.stdout.decode()
Expand Down