Skip to content

Commit 6736cf7

Browse files
committed
chore: specifiy ruff version
1 parent b93d322 commit 6736cf7

5 files changed

Lines changed: 46 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
if: matrix.os == 'ubuntu-latest' && matrix.type == 'debug'
2828
run: |
2929
sudo apt-get install -y clang-format-16
30-
pip install black ruff colorama
30+
pip install black ruff==0.15.20 colorama
3131
if [ "${{ github.event_name }}" = "pull_request" ]; then
3232
python3 scripts/format.py --ref "${{ github.event.pull_request.base.sha }}" --path src --check
3333
elif [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then

.github/workflows/ruff.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ jobs:
88
- uses: chartboost/ruff-action@v1
99
with:
1010
src: './python/'
11+
version: "0.15.20"
1112
- uses: chartboost/ruff-action@v1
1213
with:
1314
src: './python/'
1415
args: format --check
16+
version: "0.15.20"

python/infinicore/nn/functional/layer_norm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def layer_norm(
1515
) -> Tensor:
1616
r"""Apply Layer Normalization."""
1717

18-
assert (
19-
normalized_shape == weight.shape
20-
), "normalized_shape does not match weight.shape."
18+
assert normalized_shape == weight.shape, (
19+
"normalized_shape does not match weight.shape."
20+
)
2121

2222
if out is None:
2323
return Tensor(

python/infinicore/nn/functional/rms_norm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def rms_norm(
1414
) -> Tensor:
1515
r"""Apply Root Mean Square Layer Normalization."""
1616

17-
assert (
18-
normalized_shape == weight.shape
19-
), "normalized_shape does not match weight.shape."
17+
assert normalized_shape == weight.shape, (
18+
"normalized_shape does not match weight.shape."
19+
)
2020

2121
if out is None:
2222
return Tensor(_infinicore.rms_norm(input._underlying, weight._underlying, eps))

scripts/format.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def format_file(file: Path, check: bool, formatter) -> bool:
7878
check=True,
7979
)
8080
print(f"{Fore.CYAN}Formatted: {file}{Style.RESET_ALL}")
81-
81+
elif formatter == "ruff":
8282
ruff_cmd = ["ruff", "check", file]
83+
ruff_format_cmd = ["ruff", "format", file]
8384
try:
8485
if check:
8586
process = subprocess.run(
@@ -94,6 +95,22 @@ def format_file(file: Path, check: bool, formatter) -> bool:
9495
f"Use {Fore.CYAN}ruff check --fix {file}{Style.RESET_ALL} to fix it."
9596
)
9697
formatted = False
98+
99+
ruff_format_cmd.insert(2, "--check")
100+
process = subprocess.run(
101+
ruff_format_cmd,
102+
capture_output=True,
103+
text=True,
104+
check=False,
105+
)
106+
if process.returncode != 0:
107+
print(
108+
f"{Fore.YELLOW}{file} is not ruff-formatted.{Style.RESET_ALL}"
109+
)
110+
print(
111+
f"Use {Fore.CYAN}ruff format {file}{Style.RESET_ALL} to format it."
112+
)
113+
formatted = False
97114
else:
98115
ruff_cmd.insert(2, "--fix")
99116
process = subprocess.run(
@@ -111,6 +128,24 @@ def format_file(file: Path, check: bool, formatter) -> bool:
111128
formatted = False
112129
else:
113130
print(f"{Fore.CYAN}Ruff fixed: {file}{Style.RESET_ALL}")
131+
132+
process = subprocess.run(
133+
ruff_format_cmd,
134+
capture_output=True,
135+
text=True,
136+
check=False,
137+
)
138+
if process.returncode != 0:
139+
print(
140+
f"{Fore.RED}Ruff format failed for {file}.{Style.RESET_ALL}"
141+
)
142+
if process.stdout:
143+
print(process.stdout, end="")
144+
if process.stderr:
145+
print(process.stderr, end="")
146+
formatted = False
147+
else:
148+
print(f"{Fore.CYAN}Ruff formatted: {file}{Style.RESET_ALL}")
114149
except FileNotFoundError:
115150
print(
116151
f"{Fore.RED}Formatter ruff not found, {file} skipped.{Style.RESET_ALL}"
@@ -217,9 +252,7 @@ def main():
217252
parser.add_argument(
218253
"--c", default="clang-format-16", help="C formatter (default: clang-format-16)"
219254
)
220-
parser.add_argument(
221-
"--py", default="black", help="Python formatter (default: black)"
222-
)
255+
parser.add_argument("--py", default="ruff", help="Python formatter (default: ruff)")
223256
args = parser.parse_args()
224257

225258
if args.ref is None and args.path is None:

0 commit comments

Comments
 (0)