Skip to content

Commit c4fec90

Browse files
Use ruff-check, ruff-format instead of black, flake8 (#1500)
Issue: rapidsai/build-planning#130 Ops-Bot-Merge-Barrier: true Authors: - Kyle Edwards (https://github.com/KyleFromNVIDIA) Approvers: - Gil Forsyth (https://github.com/gforsyth) - Bradley Dice (https://github.com/bdice) - Ben Frederickson (https://github.com/benfred) URL: #1500
1 parent 7a67f67 commit c4fec90

37 files changed

Lines changed: 1395 additions & 844 deletions

.flake8

Lines changed: 0 additions & 25 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@ repos:
1717
# project can specify its own first/third-party packages.
1818
args: ["--config-root=python/", "--resolve-all-configs"]
1919
files: python/.*
20-
types_or: [python, cython, pyi]
21-
- repo: https://github.com/psf/black
22-
rev: 22.3.0
20+
types: [cython]
21+
- repo: https://github.com/astral-sh/ruff-pre-commit
22+
rev: v0.14.3
2323
hooks:
24-
- id: black
25-
files: python/.*
26-
# Explicitly specify the pyproject.toml at the repo root, not per-project.
27-
args: ["--config", "pyproject.toml"]
28-
- repo: https://github.com/PyCQA/flake8
29-
rev: 7.1.1
30-
hooks:
31-
- id: flake8
32-
args: ["--config=.flake8"]
33-
files: python/.*$
34-
types: [file]
35-
types_or: [python, cython]
36-
additional_dependencies: ["flake8-force"]
24+
- id: ruff-check
25+
args: [--fix]
26+
- id: ruff-format
3727
- repo: https://github.com/pre-commit/mirrors-mypy
3828
rev: 'v0.971'
3929
hooks:
@@ -110,7 +100,7 @@ repos:
110100
^CHANGELOG[.]md$|
111101
^cpp/cmake/patches/cutlass/build-export[.]patch$
112102
- repo: https://github.com/rapidsai/pre-commit-hooks
113-
rev: v1.2.0
103+
rev: v1.2.1
114104
hooks:
115105
- id: verify-copyright
116106
name: verify-copyright-cuvs

cpp/scripts/analyze_nvcc_log.py

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python3
2-
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION.
2+
# SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
# SPDX-License-Identifier: Apache-2.0
44

55
import sys
66
import pandas as pd
7-
import numpy as np
87
import matplotlib.pyplot as plt
98
import seaborn as sns
109
from pathlib import Path
1110
from matplotlib import colors
1211

12+
1313
def main(input_path):
1414
input_path = Path(input_path)
1515
print("-- loading data")
@@ -22,40 +22,56 @@ def main(input_path):
2222
df["file"] = df["source file name"]
2323
df["phase"] = df["phase name"].str.strip()
2424

25-
dfp = (df
26-
# Remove nvcc driver entries. They don't contain a source file name
27-
.query("phase!='nvcc (driver)'")
28-
# Make a pivot table containing files as row, phase (preprocessing,
29-
# cicc, etc.) as column and the total times as table entries. NOTE:
30-
# if compiled for multiple archs, the archs will be summed.
31-
.pivot_table(index="file", values="seconds", columns="phase", aggfunc='sum'))
25+
dfp = (
26+
df
27+
# Remove nvcc driver entries. They don't contain a source file name
28+
.query("phase!='nvcc (driver)'")
29+
# Make a pivot table containing files as row, phase (preprocessing,
30+
# cicc, etc.) as column and the total times as table entries. NOTE:
31+
# if compiled for multiple archs, the archs will be summed.
32+
.pivot_table(
33+
index="file", values="seconds", columns="phase", aggfunc="sum"
34+
)
35+
)
3236

3337
dfp_sum = dfp.sum(axis="columns")
3438

3539
df_fraction = dfp.divide(dfp_sum, axis="index")
3640
df_fraction["total time"] = dfp_sum
37-
df_fraction = df_fraction.melt(ignore_index=False, id_vars="total time", var_name="phase", value_name="fraction")
41+
df_fraction = df_fraction.melt(
42+
ignore_index=False,
43+
id_vars="total time",
44+
var_name="phase",
45+
value_name="fraction",
46+
)
3847

3948
dfp["total time"] = dfp_sum
40-
df_absolute = dfp.melt(ignore_index=False, id_vars="total time", var_name="phase", value_name="seconds")
49+
df_absolute = dfp.melt(
50+
ignore_index=False,
51+
id_vars="total time",
52+
var_name="phase",
53+
value_name="seconds",
54+
)
4155

4256
# host: light red to dark red (preprocessing, cudafe, gcc (compiling))
4357
# device: ligt green to dark green (preprocessing, cicc, ptxas)
4458
palette = {
4559
"gcc (preprocessing 4)": colors.hsv_to_rgb((0, 1, 1)),
46-
'cudafe++': colors.hsv_to_rgb((0, 1, .75)),
47-
'gcc (compiling)': colors.hsv_to_rgb((0, 1, .4)),
48-
"gcc (preprocessing 1)": colors.hsv_to_rgb((.33, 1, 1)),
49-
'cicc': colors.hsv_to_rgb((.33, 1, 0.75)),
50-
'ptxas': colors.hsv_to_rgb((.33, 1, 0.4)),
51-
'fatbinary': "grey",
60+
"cudafe++": colors.hsv_to_rgb((0, 1, 0.75)),
61+
"gcc (compiling)": colors.hsv_to_rgb((0, 1, 0.4)),
62+
"gcc (preprocessing 1)": colors.hsv_to_rgb((0.33, 1, 1)),
63+
"cicc": colors.hsv_to_rgb((0.33, 1, 0.75)),
64+
"ptxas": colors.hsv_to_rgb((0.33, 1, 0.4)),
65+
"fatbinary": "grey",
5266
}
5367

5468
print("-- Ten longest translation units:")
55-
colwidth = pd.get_option('display.max_colwidth') - 1
69+
colwidth = pd.get_option("display.max_colwidth") - 1
5670
dfp = dfp.reset_index()
5771
dfp["file"] = dfp["file"].apply(lambda s: s[-colwidth:])
58-
print(dfp.sort_values("total time", ascending=False).reset_index().loc[:10])
72+
print(
73+
dfp.sort_values("total time", ascending=False).reset_index().loc[:10]
74+
)
5975

6076
print("-- Plotting absolute compile times")
6177
abs_out_path = f"{input_path}.absolute.compile_times.png"
@@ -64,43 +80,57 @@ def main(input_path):
6480
y="file",
6581
hue="phase",
6682
hue_order=reversed(
67-
["gcc (preprocessing 4)", 'cudafe++', 'gcc (compiling)',
68-
"gcc (preprocessing 1)", 'cicc', 'ptxas',
69-
'fatbinary',
70-
]),
83+
[
84+
"gcc (preprocessing 4)",
85+
"cudafe++",
86+
"gcc (compiling)",
87+
"gcc (preprocessing 1)",
88+
"cicc",
89+
"ptxas",
90+
"fatbinary",
91+
]
92+
),
7193
palette=palette,
7294
weights="seconds",
7395
multiple="stack",
7496
kind="hist",
7597
height=20,
7698
)
77-
plt.xlabel("seconds");
99+
plt.xlabel("seconds")
78100
plt.savefig(abs_out_path)
79101
print(f"-- Wrote absolute compile time plot to {abs_out_path}")
80102

81103
print("-- Plotting relative compile times")
82104
rel_out_path = f"{input_path}.relative.compile_times.png"
83105
sns.displot(
84-
df_fraction.sort_values('total time').reset_index(),
106+
df_fraction.sort_values("total time").reset_index(),
85107
y="file",
86108
hue="phase",
87-
hue_order=reversed(["gcc (preprocessing 4)", 'cudafe++', 'gcc (compiling)',
88-
"gcc (preprocessing 1)", 'cicc', 'ptxas',
89-
'fatbinary',
90-
]),
109+
hue_order=reversed(
110+
[
111+
"gcc (preprocessing 4)",
112+
"cudafe++",
113+
"gcc (compiling)",
114+
"gcc (preprocessing 1)",
115+
"cicc",
116+
"ptxas",
117+
"fatbinary",
118+
]
119+
),
91120
palette=palette,
92121
weights="fraction",
93122
multiple="stack",
94123
kind="hist",
95124
height=15,
96125
)
97-
plt.xlabel("fraction");
126+
plt.xlabel("fraction")
98127
plt.savefig(rel_out_path)
99128
print(f"-- Wrote relative compile time plot to {rel_out_path}")
100129

130+
101131
if __name__ == "__main__":
102132
if len(sys.argv) != 2:
103-
printf("""NVCC log analyzer
133+
print("""NVCC log analyzer
104134
105135
Analyzes nvcc logs and outputs a figure with highest ranking translation
106136
units.

cpp/scripts/gitutils.py

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,20 @@ def repo_version_major_minor():
5555

5656
full_repo_version = repo_version()
5757

58-
match = re.match(r"^v?(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?",
59-
full_repo_version)
60-
61-
if (match is None):
62-
print(" [DEBUG] Could not determine repo major minor version. "
63-
f"Full repo version: {full_repo_version}.")
58+
match = re.match(
59+
r"^v?(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?", full_repo_version
60+
)
61+
62+
if match is None:
63+
print(
64+
" [DEBUG] Could not determine repo major minor version. "
65+
f"Full repo version: {full_repo_version}."
66+
)
6467
return None
6568

6669
out_version = match.group("major")
6770

68-
if (match.group("minor")):
71+
if match.group("minor"):
6972
out_version += "." + match.group("minor")
7073

7174
return out_version
@@ -91,44 +94,50 @@ def determine_merge_commit(current_branch="HEAD"):
9194

9295
try:
9396
# Try to determine the target branch from the most recent tag
94-
head_branch = __git("describe",
95-
"--all",
96-
"--tags",
97-
"--match='branch-*'",
98-
"--abbrev=0")
97+
head_branch = __git(
98+
"describe", "--all", "--tags", "--match='branch-*'", "--abbrev=0"
99+
)
99100
except subprocess.CalledProcessError:
100-
print(" [DEBUG] Could not determine target branch from most recent "
101-
"tag. Falling back to 'branch-{major}.{minor}.")
101+
print(
102+
" [DEBUG] Could not determine target branch from most recent "
103+
"tag. Falling back to 'branch-{major}.{minor}."
104+
)
102105
head_branch = None
103106

104-
if (head_branch is not None):
107+
if head_branch is not None:
105108
# Convert from head to branch name
106109
head_branch = __git("name-rev", "--name-only", head_branch)
107110
else:
108111
# Try and guess the target branch as "branch-<major>.<minor>"
109112
version = repo_version_major_minor()
110113

111-
if (version is None):
114+
if version is None:
112115
return None
113116

114117
head_branch = "branch-{}".format(version)
115118

116119
try:
117120
# Now get the remote tracking branch
118-
remote_branch = __git("rev-parse",
119-
"--abbrev-ref",
120-
"--symbolic-full-name",
121-
head_branch + "@{upstream}")
121+
remote_branch = __git(
122+
"rev-parse",
123+
"--abbrev-ref",
124+
"--symbolic-full-name",
125+
head_branch + "@{upstream}",
126+
)
122127
except subprocess.CalledProcessError:
123-
print(" [DEBUG] Could not remote tracking reference for "
124-
f"branch {head_branch}.")
128+
print(
129+
" [DEBUG] Could not remote tracking reference for "
130+
f"branch {head_branch}."
131+
)
125132
remote_branch = None
126133

127-
if (remote_branch is None):
134+
if remote_branch is None:
128135
return None
129136

130-
print(f" [DEBUG] Determined TARGET_BRANCH as: '{remote_branch}'. "
131-
"Finding common ancestor.")
137+
print(
138+
f" [DEBUG] Determined TARGET_BRANCH as: '{remote_branch}'. "
139+
"Finding common ancestor."
140+
)
132141

133142
common_commit = __git("merge-base", remote_branch, current_branch)
134143

@@ -166,9 +175,9 @@ def changedFilesBetween(baseName, branchName, commitHash):
166175
# checkout latest commit from branch
167176
__git("checkout", "-fq", commitHash)
168177

169-
files = __gitdiff("--name-only",
170-
"--ignore-submodules",
171-
f"{baseName}..{branchName}")
178+
files = __gitdiff(
179+
"--name-only", "--ignore-submodules", f"{baseName}..{branchName}"
180+
)
172181

173182
# restore the original branch
174183
__git("checkout", "--force", current)
@@ -180,13 +189,15 @@ def changesInFileBetween(file, b1, b2, filter=None):
180189
current = branch()
181190
__git("checkout", "--quiet", b1)
182191
__git("checkout", "--quiet", b2)
183-
diffs = __gitdiff("--ignore-submodules",
184-
"-w",
185-
"--minimal",
186-
"-U0",
187-
"%s...%s" % (b1, b2),
188-
"--",
189-
file)
192+
diffs = __gitdiff(
193+
"--ignore-submodules",
194+
"-w",
195+
"--minimal",
196+
"-U0",
197+
"%s...%s" % (b1, b2),
198+
"--",
199+
file,
200+
)
190201
__git("checkout", "--quiet", current)
191202
lines = []
192203
for line in diffs.splitlines():
@@ -215,25 +226,29 @@ def modifiedFiles(pathFilter=None):
215226
currentBranch = branch()
216227
print(
217228
f" [DEBUG] TARGET_BRANCH={targetBranch}, COMMIT_HASH={commitHash}, "
218-
f"currentBranch={currentBranch}")
229+
f"currentBranch={currentBranch}"
230+
)
219231

220232
if targetBranch and commitHash and (currentBranch == "current-pr-branch"):
221233
print(" [DEBUG] Assuming a CI environment.")
222234
allFiles = changedFilesBetween(targetBranch, currentBranch, commitHash)
223235
else:
224-
print(" [DEBUG] Did not detect CI environment. "
225-
"Determining TARGET_BRANCH locally.")
236+
print(
237+
" [DEBUG] Did not detect CI environment. "
238+
"Determining TARGET_BRANCH locally."
239+
)
226240

227241
common_commit = determine_merge_commit(currentBranch)
228242

229-
if (common_commit is not None):
230-
243+
if common_commit is not None:
231244
# Now get the diff. Use --staged to get both diff between
232245
# common_commit..HEAD and any locally staged files
233-
allFiles = __gitdiff("--name-only",
234-
"--ignore-submodules",
235-
"--staged",
236-
f"{common_commit}").splitlines()
246+
allFiles = __gitdiff(
247+
"--name-only",
248+
"--ignore-submodules",
249+
"--staged",
250+
f"{common_commit}",
251+
).splitlines()
237252
else:
238253
# Fallback to just uncommitted files
239254
allFiles = uncommittedFiles()

0 commit comments

Comments
 (0)