Skip to content

Commit b5574c3

Browse files
committed
✨ add automated linting and formatting functions using ruff
1 parent bcca819 commit b5574c3

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed

scripts/sync_guild_features/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from github import Auth
77
import re
88

9-
from .utils import get_features_blob, format_path, lint_path, GUILD_FEATURES_GIST_URL
10-
from ..utils import create_update_pr
9+
from .utils import get_features_blob, GUILD_FEATURES_GIST_URL
10+
from ..utils import create_update_pr, format_path, lint_path
1111

1212
CI = os.environ.get("CI", "false").lower() in ("true", "1", "yes")
1313

scripts/sync_guild_features/utils.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import requests
2-
import subprocess
3-
from pathlib import Path
4-
from ruff.__main__ import ( # type: ignore[import-untyped]
5-
find_ruff_bin,
6-
)
72

83
# https://gist.github.com/advaith1/a82065c4049345b38f526146d6ecab96
94
GUILD_FEATURES_GIST_URL = (
@@ -27,42 +22,4 @@ def get_features_blob() -> list[str]:
2722
return response.json()
2823

2924

30-
def format_path(path: Path) -> str:
31-
"""
32-
Formats the given path with ruff.
33-
34-
Parameters
35-
----------
36-
path (Path): The path to format.
37-
"""
38-
result = subprocess.run(
39-
[find_ruff_bin(), "format", str(path.absolute())],
40-
text=True,
41-
capture_output=True,
42-
check=True,
43-
cwd=Path.cwd(),
44-
)
45-
result.check_returncode()
46-
return result.stdout
47-
48-
49-
def lint_path(path: Path) -> str:
50-
"""
51-
Lints the given path with ruff.
52-
53-
Parameters
54-
----------
55-
path (Path): The path to format.
56-
"""
57-
result = subprocess.run(
58-
[find_ruff_bin(), "check", "--fix", str(path.absolute())],
59-
text=True,
60-
capture_output=True,
61-
check=True,
62-
cwd=Path.cwd(),
63-
)
64-
result.check_returncode()
65-
return result.stdout
66-
67-
68-
__all__ = ("get_features_blob", "format_path", "lint_path", "GUILD_FEATURES_GIST_URL")
25+
__all__ = ("get_features_blob", "GUILD_FEATURES_GIST_URL")

scripts/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .pr import create_update_pr
2+
from .automated_ruff import lint_path, format_path
23

3-
__all__ = ("create_update_pr",)
4+
__all__ = ("create_update_pr", "lint_path", "format_path")

scripts/utils/automated_ruff.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import subprocess
2+
from pathlib import Path
3+
from ruff.__main__ import ( # type: ignore[import-untyped]
4+
find_ruff_bin,
5+
)
6+
7+
8+
def format_path(path: Path) -> str:
9+
"""
10+
Formats the given path with ruff.
11+
12+
Parameters
13+
----------
14+
path (Path): The path to format.
15+
"""
16+
result = subprocess.run(
17+
[find_ruff_bin(), "format", str(path.absolute())],
18+
text=True,
19+
capture_output=True,
20+
check=True,
21+
cwd=Path.cwd(),
22+
)
23+
result.check_returncode()
24+
return result.stdout
25+
26+
27+
def lint_path(path: Path) -> str:
28+
"""
29+
Lints the given path with ruff.
30+
31+
Parameters
32+
----------
33+
path (Path): The path to format.
34+
"""
35+
result = subprocess.run(
36+
[find_ruff_bin(), "check", "--fix", str(path.absolute())],
37+
text=True,
38+
capture_output=True,
39+
check=True,
40+
cwd=Path.cwd(),
41+
)
42+
result.check_returncode()
43+
return result.stdout
44+
45+
46+
__all__ = ("format_path", "lint_path")

scripts/utils/pr.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def create_update_pr(commit_message: str, branch_prefix: str, title: str, body:
2626
2727
Parameters
2828
----------
29-
title (str): The title of the pull request.
30-
branch_prefix (str): The prefix for the branch name.
31-
body (str): The body of the pull request.
32-
base_branch (str): The base branch to create the PR against. Defaults to "main".
29+
commit_message (str): The commit message to use.
30+
branch_prefix (str): The prefix for the branch name.
31+
title (str): The title of the pull request.
32+
body (str): The body of the pull request.
33+
path (str | Path): The path or glob to the file to commit.
3334
"""
3435
github = Github(os.environ["GITHUB_TOKEN"])
3536
repo = github.get_repo(os.environ["GITHUB_REPOSITORY"])

0 commit comments

Comments
 (0)