Skip to content

Commit 5d36932

Browse files
Format source code to PEP8 using Ruff
* added ruff docs * style: Run ruff and black before yapf pass * yapf -r -i (23 fixes) * fixed conf.py and ran ruff format . * fixed conf.py 2 * formatted argparser.py * formatted src/rocprof_compute_analyze * formatted src/rocprof_compute_profile * formatted soc_base.py * formatted rocprof_compute_tui * formatted gui_components * formatted src/utils * formatted tests/ * format extra files * cleanup * fix test_utils.py * fixed typos * Update pyproject.toml * Update README.md * Update test_utils.py [rocm-systems] ROCm/rocm-systems#36 (commit 58d2a01)
1 parent ac195a0 commit 5d36932

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3204
-2327
lines changed

.github/workflows/formatting.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,26 @@ jobs:
2525
- name: Install dependencies
2626
run: |
2727
python -m pip install --upgrade pip
28-
python -m pip install black isort
28+
python -m pip install ruff
2929
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
30-
- name: Run black formatter
31-
uses: psf/black@stable
32-
with:
33-
use_pyproject: true
34-
- name: Run isort formatter
35-
uses: isort/isort-action@master
30+
- name: Run Ruff Linter and Import Sorter
31+
run: |
32+
ruff check . --fix --exit-zero
33+
- name: Run Ruff Formatter
34+
run: |
35+
ruff format .
36+
- name: Check for formatting/linting changes
37+
run: |
38+
git config --global user.name 'github-actions'
39+
git config --global user.email 'github-actions@github.com'
40+
git add -A .
41+
if ! git diff --cached --quiet; then
42+
echo "::error::Files were modified by ruff. Please run 'ruff check . --fix && ruff format .' locally and commit the changes."
43+
git diff --cached --patch # Show the diff in the logs
44+
exit 1
45+
else
46+
echo "Ruff found no issues or all issues were fixed and files are clean."
47+
fi
3648
3749
cmake:
3850
runs-on: ubuntu-22.04

.pre-commit-config.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ repos:
77
- id: check-yaml
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
10-
# Python import sorting
11-
- repo: https://github.com/pycqa/isort
12-
rev: 6.0.1
10+
# Python import sorting and formatting
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
# Ruff version. Check https://github.com/astral-sh/ruff-pre-commit#version-compatibility,
13+
# for the latest ruff version supported by the hook.
14+
rev: v0.12.7
1315
hooks:
14-
- id: isort
15-
# Python formatting (Using this mirror lets us use mypyc-compiled black, which is about 2x faster)
16-
- repo: https://github.com/psf/black-pre-commit-mirror
17-
rev: 25.1.0
18-
hooks:
19-
- id: black
16+
- id: ruff-check
17+
args: [--fix, --exit-non-zero-on-fix]
18+
- id: ruff-format

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,42 @@ style reference is provided below for convenience:
104104
url = {https://doi.org/10.5281/zenodo.7314631}
105105
}
106106
```
107+
108+
### Contribution Guidelines
109+
110+
To ensure code quality and consistency, we use **Ruff**, a fast Python linter and formatter. Before submitting a pull request, please ensure your code is formatted and linted correctly.
111+
112+
-----
113+
114+
### Installing and Running Ruff
115+
116+
Ruff is available on PyPI and can be installed using `pip`:
117+
118+
```bash
119+
pip install ruff
120+
```
121+
122+
Once installed, you can run Ruff from the command line. To check for linting errors and formatting issues, navigate to the project root and run:
123+
124+
```bash
125+
ruff check .
126+
ruff format --check .
127+
```
128+
129+
To automatically fix most of the issues detected, you can use the `--fix` flag with the `check` command and run the `format` command without the `--check` flag:
130+
131+
```bash
132+
ruff check --fix .
133+
ruff format .
134+
```
135+
136+
-----
137+
138+
### Disabling Formatting for Specific Sections
139+
140+
There may be instances where you need to disable Ruff's formatting on a specific block of code. You can do this using special comments:
141+
142+
* **`# fmt: off`** and **`# fmt: on`**: These comments can be used to disable and re-enable formatting for a block of code.
143+
* **`# fmt: skip`**: This comment, placed at the end of a line, will prevent Ruff from formatting that specific statement.
144+
145+
You can also disable specific linting rules for a line by using `# noqa: <rule_code>`.

docs/archive/docs-1.x/conf.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
# If extensions (or modules to document with autodoc) are in another directory,
1515
# add these directories to sys.path here. If the directory is relative to the
16-
# documentation root, use str(Path(<rel_path>).absolute().resolve()) to make it absolute, like shown here.
17-
#
16+
# documentation root, use str(Path(<rel_path>).absolute().resolve())
17+
# to make it absolute, like shown here.
1818
from pathlib import Path
1919

20+
from pygments.styles import get_all_styles
21+
from recommonmark.parser import CommonMarkParser
22+
from recommonmark.transform import AutoStructify
23+
2024
sys.path.insert(0, str(Path("..").absolute().resolve()))
2125

2226
repo_version = "unknown"
@@ -68,7 +72,6 @@ def install(package):
6872
".md": "markdown",
6973
}
7074

71-
from recommonmark.parser import CommonMarkParser
7275

7376
source_parsers = {".md": CommonMarkParser}
7477

@@ -94,7 +97,6 @@ def install(package):
9497
latex_engine = "lualatex"
9598
latex_show_urls = "footnote"
9699

97-
98100
# -- Options for HTML output -------------------------------------------------
99101

100102
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -113,7 +115,6 @@ def install(package):
113115
# so a file named "default.css" will overwrite the builtin "default.css".
114116
html_static_path = ["_static"]
115117

116-
117118
# -- Options for HTMLHelp output ---------------------------------------------
118119

119120
# Output file base name for HTML help builder.
@@ -136,8 +137,6 @@ def install(package):
136137
"titles_only": False,
137138
}
138139

139-
from pygments.styles import get_all_styles
140-
141140
# The name of the Pygments (syntax highlighting) style to use.
142141
styles = list(get_all_styles())
143142
preferences = ("emacs", "pastie", "colorful")
@@ -146,8 +145,6 @@ def install(package):
146145
pygments_style = pref
147146
break
148147

149-
from recommonmark.transform import AutoStructify
150-
151148

152149
# app setup hook
153150
def setup(app):

docs/archive/docs-2.x/conf.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
# If extensions (or modules to document with autodoc) are in another directory,
1515
# add these directories to sys.path here. If the directory is relative to the
16-
# documentation root, use str(Path(<rel_path>).absolute().resolve()) to make it absolute, like shown here.
17-
#
16+
# documentation root, use str(Path(<rel_path>).absolute().resolve()
17+
# to make it absolute, like shown here.
1818
from pathlib import Path
1919

20+
from pygments.styles import get_all_styles
21+
from recommonmark.parser import CommonMarkParser
22+
from recommonmark.transform import AutoStructify
23+
2024
sys.path.insert(0, str(Path("..").absolute().resolve()))
2125

2226
repo_version = "unknown"
@@ -56,12 +60,10 @@ def install(package):
5660

5761
show_authors = True
5862

59-
6063
myst_heading_anchors = 4
6164
# enable replacement of (tm) & friends
6265
myst_enable_extensions = ["replacements", "dollarmath"]
6366

64-
6567
# Add any paths that contain templates here, relative to this directory.
6668
templates_path = ["_templates"]
6769

@@ -84,8 +86,6 @@ def install(package):
8486
# sphinxmark_text_spacing = 800
8587
# sphinxmark_text_opacity = 30
8688

87-
from recommonmark.parser import CommonMarkParser
88-
8989
source_parsers = {".md": CommonMarkParser}
9090

9191
# The master toctree document.
@@ -110,7 +110,6 @@ def install(package):
110110
latex_engine = "lualatex"
111111
latex_show_urls = "footnote"
112112

113-
114113
# -- Options for HTML output -------------------------------------------------
115114

116115
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -133,7 +132,6 @@ def install(package):
133132
"sphinxsetup": "verbatimwrapslines=true, verbatimforcewraps=true",
134133
}
135134

136-
137135
# -- Options for HTMLHelp output ---------------------------------------------
138136

139137
# Output file base name for HTML help builder.
@@ -157,8 +155,6 @@ def install(package):
157155
"titles_only": False,
158156
}
159157

160-
from pygments.styles import get_all_styles
161-
162158
# The name of the Pygments (syntax highlighting) style to use.
163159
styles = list(get_all_styles())
164160
preferences = ("emacs", "pastie", "colorful")
@@ -167,8 +163,6 @@ def install(package):
167163
pygments_style = pref
168164
break
169165

170-
from recommonmark.transform import AutoStructify
171-
172166

173167
# app setup hook
174168
def setup(app):

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
##############################################################################
2525

26-
2726
# Configuration file for the Sphinx documentation builder.
2827
#
2928
# This file only contains a selection of the most common options. For a full

pyproject.toml

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,50 @@ requires-python = ">=3.8"
44

55
[project.optional-dependencies]
66
developer = [
7-
"black>=22.6.0",
8-
"isort>=5.12.0",
7+
"ruff>=0.12.7",
98
"pre-commit",
109
]
1110

12-
[tool.black]
13-
line-length = 90
14-
include = '\.py$'
15-
exclude = '''
16-
(
17-
/(
18-
\.eggs
19-
| \.git
20-
| \.github
21-
| \.tox
22-
| \.venv
23-
| \.misc
24-
| \.vscode
25-
| \.pyc
26-
| dist
27-
| external
28-
| .pytest_cache
29-
| build
30-
| build-rocprof_compute
31-
)/
32-
)
33-
'''
11+
[tool.ruff]
12+
line-length = 88
13+
14+
# Ruff's default excludes cover: .bzr, .direnv, .eggs, .git, .git-rewrite, .hg, .ipynb_checkpoints,
15+
# .mypy_cache, .nox, .pants.d, .pyenv, .pytest_cache, .pytype, .ruff_cache, .svn,
16+
# .tox, .venv, .vscode, __pypackages__, _build, buck-out, build, dist, node_modules,
17+
# site-packages, venv
18+
19+
extend-exclude = [
20+
".github",
21+
".misc",
22+
"external",
23+
"build-rocprof_compute",
24+
]
25+
26+
[tool.ruff.lint]
27+
# Enable Pyflakes (F), pycodestyle (E, W for PEP8), and isort (I) rules.
28+
select = ["E", "W", "F", "I"]
29+
ignore = ["E713", "E711"]
30+
fixable = ["ALL"]
31+
unfixable = []
32+
33+
[tool.ruff.format]
34+
preview = true
35+
36+
# Like Black, use double quotes for strings.
37+
quote-style = "double"
38+
39+
# Like Black, indent with spaces, rather than tabs.
40+
indent-style = "space"
41+
42+
# Like Black, respect magic trailing commas.
43+
skip-magic-trailing-comma = false
44+
45+
# Like Black, automatically detect the appropriate line ending.
46+
line-ending = "auto"
47+
48+
docstring-code-format = true
49+
docstring-code-line-length = "dynamic"
3450

35-
[tool.isort]
36-
profile = "black"
3751

3852
[tool.pytest.ini_options]
3953
addopts = [

0 commit comments

Comments
 (0)