Skip to content

Commit 5adf1a9

Browse files
committed
feat: Add Yore tool
1 parent ff429ff commit 5adf1a9

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/duty/tools/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from duty.tools._safety import safety
2323
from duty.tools._ssort import ssort
2424
from duty.tools._twine import twine
25+
from duty.tools._yore import yore
2526

2627
__all__ = [
2728
"LazyStderr",
@@ -45,4 +46,5 @@
4546
"safety",
4647
"ssort",
4748
"twine",
49+
"yore",
4850
]

src/duty/tools/_yore.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"""Callable for [Yore](https://github.com/pawamoy/yore)."""
2+
3+
from __future__ import annotations
4+
5+
from duty.tools._base import Tool
6+
7+
8+
class yore(Tool): # noqa: N801
9+
"""Call [Yore](https://github.com/pawamoy/yore)."""
10+
11+
cli_name = "yore"
12+
13+
@classmethod
14+
def check(
15+
cls,
16+
*paths: str,
17+
bump: str | None = None,
18+
eol_within: str | None = None,
19+
bol_within: str | None = None,
20+
) -> yore:
21+
"""Check Yore comments against Python EOL dates or the provided next version of your project.
22+
23+
Parameters:
24+
paths: Path to files or directories to check.
25+
bump: The next version of your project.
26+
eol_within: The time delta to start checking before the End of Life of a Python version.
27+
It is provided in a human-readable format, like `2 weeks` or `1 month`.
28+
Spaces are optional, and the unit can be shortened to a single letter:
29+
`d` for days, `w` for weeks, `m` for months, and `y` for years.
30+
bol_within: The time delta to start checking before the Beginning of Life of a Python version.
31+
It is provided in a human-readable format, like `2 weeks` or `1 month`.
32+
Spaces are optional, and the unit can be shortened to a single letter:
33+
`d` for days, `w` for weeks, `m` for months, and `y` for years.
34+
"""
35+
cli_args = ["check", *paths]
36+
37+
if bump:
38+
cli_args.append("--bump")
39+
cli_args.append(bump)
40+
41+
if eol_within:
42+
cli_args.append("--eol-within")
43+
cli_args.append(eol_within)
44+
45+
if bol_within:
46+
cli_args.append("--bol-within")
47+
cli_args.append(bol_within)
48+
49+
return cls(cli_args)
50+
51+
@classmethod
52+
def fix(
53+
cls,
54+
*paths: str,
55+
bump: str | None = None,
56+
eol_within: str | None = None,
57+
bol_within: str | None = None,
58+
) -> yore:
59+
"""Fix your code by transforming it according to the Yore comments.
60+
61+
Parameters:
62+
paths: Path to files or directories to fix.
63+
bump: The next version of your project.
64+
eol_within: The time delta to start fixing before the End of Life of a Python version.
65+
It is provided in a human-readable format, like `2 weeks` or `1 month`.
66+
Spaces are optional, and the unit can be shortened to a single letter:
67+
`d` for days, `w` for weeks, `m` for months, and `y` for years.
68+
bol_within: The time delta to start fixing before the Beginning of Life of a Python version.
69+
It is provided in a human-readable format, like `2 weeks` or `1 month`.
70+
Spaces are optional, and the unit can be shortened to a single letter:
71+
`d` for days, `w` for weeks, `m` for months, and `y` for years.
72+
"""
73+
cli_args = ["fix", *paths]
74+
75+
if bump:
76+
cli_args.append("--bump")
77+
cli_args.append(bump)
78+
79+
if eol_within:
80+
cli_args.append("--eol-within")
81+
cli_args.append(eol_within)
82+
83+
if bol_within:
84+
cli_args.append("--bol-within")
85+
cli_args.append(bol_within)
86+
87+
return cls(cli_args)
88+
89+
def __call__(self) -> int:
90+
from yore import main as run_yore
91+
92+
return run_yore(self.cli_args)

0 commit comments

Comments
 (0)