Skip to content

Commit

Permalink
feat: Support updated lazy decorator from failprint
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Apr 10, 2023
1 parent fdcd50a commit a0446ac
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 71 deletions.
4 changes: 2 additions & 2 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def changelog(ctx: Context) -> None:
"""
from git_changelog.cli import build_and_render

git_changelog = lazy("git_changelog")(build_and_render)
git_changelog = lazy(build_and_render, name="git_changelog")
ctx.run(
git_changelog(
repository=".",
Expand All @@ -48,7 +48,7 @@ def changelog(ctx: Context) -> None:
template="keepachangelog",
parse_trailers=True,
parse_refs=False,
sections=("build", "deps", "feat", "fix", "refactor"),
sections=["build", "deps", "feat", "fix", "refactor"],
bump_latest=True,
in_place=True,
),
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"failprint>=0.10",
"failprint>=0.11",
"cached-property>=1.5; python_version < '3.8'",
"typing-extensions>=4.5; python_version < '3.8'",
"typing-extensions>=4.1; python_version < '3.8'",
]

[project.urls]
Expand Down
29 changes: 2 additions & 27 deletions src/duty/callables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,6 @@

from __future__ import annotations

from functools import wraps
from typing import Callable
from failprint.lazy import lazy

from failprint.lazy import lazy as failprint_lazy


def lazy(name: str | None = None) -> Callable:
"""Transform a callable into a lazy callable.
Also assign the given name to the callable, for better display.
Parameters:
name: The name to assign to the callable.
Returns:
A lazy callable.
"""

def decorator(func: Callable) -> Callable:
@wraps(func)
def inner(*args, **kwargs): # noqa: ANN002,ANN003,ANN202
return func(*args, **kwargs)

if name:
inner.__name__ = name
return failprint_lazy(inner)

return decorator
__all__ = ["lazy"]
6 changes: 4 additions & 2 deletions src/duty/callables/autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from __future__ import annotations

from duty.callables import _io, lazy
from failprint.lazy import lazy

from duty.callables import _io

@lazy("autoflake")

@lazy(name="autoflake")
def run(
*files: str,
config: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import annotations

from duty.callables import lazy
from failprint.lazy import lazy


@lazy("black")
@lazy(name="black")
def run(
*src: str,
config: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from pathlib import Path
from typing import Pattern, Sequence

from duty.callables import lazy
from failprint.lazy import lazy


@lazy("blacken_docs")
@lazy(name="blacken_docs")
def run(
*paths: str | Path,
exts: Sequence[str] | None = None,
Expand Down
22 changes: 11 additions & 11 deletions src/duty/callables/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
Expand All @@ -19,7 +19,7 @@ def _run(args: list[str]) -> None:
coverage(args)


@lazy("coverage.annotate")
@lazy(name="coverage.annotate")
def annotate(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -78,7 +78,7 @@ def annotate(
_run(cli_args)


@lazy("coverage.combine")
@lazy(name="coverage.combine")
def combine(
*paths: str,
rcfile: str | None = None,
Expand Down Expand Up @@ -132,7 +132,7 @@ def combine(
_run(cli_args)


@lazy("coverage.debug")
@lazy(name="coverage.debug")
def debug(
topic: Literal["data", "sys", "config", "premain", "pybehave"],
*,
Expand Down Expand Up @@ -166,7 +166,7 @@ def debug(
_run(cli_args)


@lazy("coverage.erase")
@lazy(name="coverage.erase")
def erase(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -199,7 +199,7 @@ def erase(
_run(cli_args)


@lazy("coverage.html")
@lazy(name="coverage.html")
def html(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -305,7 +305,7 @@ def html(
_run(cli_args)


@lazy("coverage.json")
@lazy(name="coverage.json")
def json(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -389,7 +389,7 @@ def json(
_run(cli_args)


@lazy("coverage.lcov")
@lazy(name="coverage.lcov")
def lcov(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -456,7 +456,7 @@ def lcov(
_run(cli_args)


@lazy("coverage.report")
@lazy(name="coverage.report")
def report(
*,
rcfile: str | None = None,
Expand Down Expand Up @@ -553,7 +553,7 @@ def report(
_run(cli_args)


@lazy("coverage.run")
@lazy(name="coverage.run")
def run(
pyfile: str,
*,
Expand Down Expand Up @@ -650,7 +650,7 @@ def run(
_run(cli_args)


@lazy("coverage.xml")
@lazy(name="coverage.xml")
def xml(
*,
rcfile: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
Expand All @@ -13,7 +13,7 @@
from typing import Literal


@lazy("flake8")
@lazy(name="flake8")
def run(
*paths: str,
config: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/interrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
Expand All @@ -15,7 +15,7 @@
_BADGE_STYLE = Literal["flat", "flat-square", "flat-square-modified", "for-the-badge", "plastic", "social"]


@lazy("interrogate")
@lazy(name="interrogate")
def run(
*src: str,
verbose: int | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
Expand Down Expand Up @@ -40,7 +40,7 @@
]


@lazy("isort")
@lazy(name="isort")
def run(
*files: str,
settings: str | None = None,
Expand Down
10 changes: 5 additions & 5 deletions src/duty/callables/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from duty.callables import lazy
from failprint.lazy import lazy


def run(*args: str, quiet: bool = False, verbose: bool = False) -> None:
Expand All @@ -26,7 +26,7 @@ def run(*args: str, quiet: bool = False, verbose: bool = False) -> None:
mkdocs(cli_args)


@lazy("mkdocs.build")
@lazy(name="mkdocs.build")
def build(
*,
config_file: str | None = None,
Expand Down Expand Up @@ -80,7 +80,7 @@ def build(
run("build", *cli_args, quiet=quiet, verbose=verbose)


@lazy("mkdocs.gh_deploy")
@lazy(name="mkdocs.gh_deploy")
def gh_deploy(
*,
config_file: str | None = None,
Expand Down Expand Up @@ -173,7 +173,7 @@ def gh_deploy(
run("gh-deploy", *cli_args, quiet=quiet, verbose=verbose)


@lazy("mkdocs.new")
@lazy(name="mkdocs.new")
def new(project_directory: str, *, quiet: bool = False, verbose: bool = False) -> None:
"""Create a new MkDocs project.
Expand All @@ -185,7 +185,7 @@ def new(project_directory: str, *, quiet: bool = False, verbose: bool = False) -
run("new", project_directory, quiet=quiet, verbose=verbose)


@lazy("mkdocs.serve")
@lazy(name="mkdocs.serve")
def serve(
*,
config_file: str | None = None,
Expand Down
5 changes: 3 additions & 2 deletions src/duty/callables/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

from duty.callables._io import _LazyStderr, _LazyStdout

# TODO: remove once support for Python 3.7 is dropped
Expand All @@ -14,7 +15,7 @@
from typing import Literal


@lazy("mypy")
@lazy(name="mypy")
def run(
*paths: str,
config_file: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/duty/callables/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys

from duty.callables import lazy
from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
Expand All @@ -13,7 +13,7 @@
from typing import Literal


@lazy("pytest")
@lazy(name="pytest")
def run(
*paths: str,
config_file: str | None = None,
Expand Down
12 changes: 6 additions & 6 deletions src/duty/callables/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
from functools import lru_cache

from duty.callables import lazy
from failprint.lazy import lazy


@lru_cache(maxsize=None)
Expand Down Expand Up @@ -52,7 +52,7 @@ def _run(
return process.returncode


@lazy("ruff.check")
@lazy(name="ruff.check")
def check(
*files: str,
config: str | None = None,
Expand Down Expand Up @@ -225,7 +225,7 @@ def check(
return _run("check", *cli_args, verbose=verbose, quiet=quiet, silent=silent)


@lazy("ruff.rule")
@lazy(name="ruff.rule")
def rule(
*,
output_format: str | None = None,
Expand All @@ -250,7 +250,7 @@ def rule(
return _run("rule", *cli_args, verbose=verbose, quiet=quiet, silent=silent)


@lazy("ruff.config")
@lazy(name="ruff.config")
def config(
*,
verbose: bool = False,
Expand All @@ -267,7 +267,7 @@ def config(
return _run("config", verbose=verbose, quiet=quiet, silent=silent)


@lazy("ruff.linter")
@lazy(name="ruff.linter")
def linter(
*,
output_format: str | None = None,
Expand All @@ -292,7 +292,7 @@ def linter(
return _run("linter", *cli_args, verbose=verbose, quiet=quiet, silent=silent)


@lazy("ruff.clean")
@lazy(name="ruff.clean")
def clean(
*,
verbose: bool = False,
Expand Down
Loading

0 comments on commit a0446ac

Please sign in to comment.