Skip to content

Commit 553aa5d

Browse files
maurycyhugovk
andauthored
Add ruff format to pre-commit, run it, except the benchmarks (#410)
Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 15eff0d commit 553aa5d

33 files changed

+1600
-1336
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ permissions: {}
66

77
jobs:
88
lint:
9-
name: Check code with ruff
109
runs-on: ubuntu-latest
1110
steps:
1211
- uses: actions/checkout@v5

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
exclude: ^pyperformance/data-files/
22
repos:
33
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: v0.12.11
4+
rev: v0.13.1
55
hooks:
66
- id: ruff-check
77
name: Run Ruff (lint)
88
args: [--exit-non-zero-on-fix]
9+
- id: ruff-format
10+
name: Run Ruff (format)
11+
args: [--exit-non-zero-on-fix]
912

1013
- repo: https://github.com/tox-dev/pyproject-fmt
1114
rev: v2.6.0

dev.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,67 @@
33
import os.path
44
import sys
55

6-
76
REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
8-
VENVS = os.path.join(REPO_ROOT, '.venvs')
7+
VENVS = os.path.join(REPO_ROOT, ".venvs")
98

109

11-
def resolve_venv_root(kind='dev', venvsdir=VENVS):
10+
def resolve_venv_root(kind="dev", venvsdir=VENVS):
1211
import sysconfig
12+
1313
if sysconfig.is_python_build():
14-
sys.exit('please install your built Python first (or pass it using --python)')
14+
sys.exit("please install your built Python first (or pass it using --python)")
1515
# XXX Handle other implementations too?
16-
base = os.path.join(venvsdir, kind or 'dev')
16+
base = os.path.join(venvsdir, kind or "dev")
1717
major, minor = sys.version_info[:2]
18-
pyloc = ((os.path.abspath(sys.executable)
19-
).partition(os.path.sep)[2].lstrip(os.path.sep)
20-
).replace(os.path.sep, '-')
21-
return f'{base}-{major}.{minor}-{pyloc}'
18+
pyloc = (
19+
(os.path.abspath(sys.executable)).partition(os.path.sep)[2].lstrip(os.path.sep)
20+
).replace(os.path.sep, "-")
21+
return f"{base}-{major}.{minor}-{pyloc}"
2222

2323

24-
def ensure_venv_ready(venvroot=None, kind='dev', venvsdir=VENVS):
24+
def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
2525
if sys.prefix != sys.base_prefix:
26-
assert os.path.exists(os.path.join(sys.prefix, 'pyvenv.cfg'))
26+
assert os.path.exists(os.path.join(sys.prefix, "pyvenv.cfg"))
2727
venvroot = sys.prefix
2828
python = sys.executable
29-
readyfile = os.path.join(sys.prefix, 'READY')
29+
readyfile = os.path.join(sys.prefix, "READY")
3030
isready = os.path.exists(readyfile)
3131
else:
3232
import venv
33+
3334
if not venvroot:
3435
venvroot = resolve_venv_root(kind, venvsdir)
3536
# Make sure the venv exists.
36-
readyfile = os.path.join(venvroot, 'READY')
37+
readyfile = os.path.join(venvroot, "READY")
3738
isready = os.path.exists(readyfile)
3839
if not isready:
3940
relroot = os.path.relpath(venvroot)
4041
if not os.path.exists(venvroot):
41-
print(f'creating venv at {relroot}...')
42+
print(f"creating venv at {relroot}...")
4243
else:
43-
print(f'venv {relroot} not ready, re-creating...')
44+
print(f"venv {relroot} not ready, re-creating...")
4445
venv.create(venvroot, with_pip=True, clear=True)
4546
else:
46-
assert os.path.exists(os.path.join(venvroot, 'pyvenv.cfg'))
47+
assert os.path.exists(os.path.join(venvroot, "pyvenv.cfg"))
4748
# Return the venv's Python executable.
48-
binname = 'Scripts' if os.name == 'nt' else 'bin'
49+
binname = "Scripts" if os.name == "nt" else "bin"
4950
exename = os.path.basename(sys.executable)
5051
python = os.path.join(venvroot, binname, exename)
5152

5253
# Now make sure the venv has pyperformance installed.
5354
if not isready:
5455
import subprocess
56+
5557
relroot = os.path.relpath(venvroot)
56-
print(f'venv {relroot} not ready, installing dependencies...')
58+
print(f"venv {relroot} not ready, installing dependencies...")
5759
proc = subprocess.run(
58-
[python, '-m', 'pip', 'install',
59-
'--upgrade',
60-
'--editable', REPO_ROOT],
60+
[python, "-m", "pip", "install", "--upgrade", "--editable", REPO_ROOT],
6161
)
6262
if proc.returncode != 0:
63-
sys.exit('ERROR: install failed')
64-
with open(readyfile, 'w'):
63+
sys.exit("ERROR: install failed")
64+
with open(readyfile, "w"):
6565
pass
66-
print('...venv {relroot} ready!')
66+
print("...venv {relroot} ready!")
6767

6868
return venvroot, python
6969

@@ -77,8 +77,9 @@ def main(venvroot=None):
7777

7878
# Now run pyperformance.
7979
import pyperformance.cli
80+
8081
pyperformance.cli.main()
8182

8283

83-
if __name__ == '__main__':
84+
if __name__ == "__main__":
8485
main()

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changelog
22
=========
33

4+
* Run ruff format and check under pre-commit and GitHub Actions
45
* Bump dask[distributed] to 2024.10.1 for Windows compatibility
56
* Bump greenlet to 3.1.0 for compatibility with 3.13
67
* Bump tornado to 6.2.0

doc/conf.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@
3434
extensions = []
3535

3636
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
37+
templates_path = ["_templates"]
3838

3939
# The suffix(es) of source filenames.
4040
# You can specify multiple suffix as a list of string:
4141
#
4242
# source_suffix = ['.rst', '.md']
43-
source_suffix = '.rst'
43+
source_suffix = ".rst"
4444

4545
# The master toctree document.
46-
master_doc = 'index'
46+
master_doc = "index"
4747

4848
# General information about the project.
49-
project = 'Python Performance Benchmark Suite'
50-
copyright = '2017, Victor Stinner'
51-
author = 'Victor Stinner'
49+
project = "Python Performance Benchmark Suite"
50+
copyright = "2017, Victor Stinner"
51+
author = "Victor Stinner"
5252

5353
# The version info for the project you're documenting, acts as replacement for
5454
# |version| and |release|, also used in various other places throughout the
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = release = '1.0.6'
58+
version = release = "1.0.6"
5959

6060
# The language for content autogenerated by Sphinx. Refer to documentation
6161
# for a list of supported languages.
@@ -67,10 +67,10 @@
6767
# List of patterns, relative to source directory, that match files and
6868
# directories to ignore when looking for source files.
6969
# This patterns also effect to html_static_path and html_extra_path
70-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
70+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7171

7272
# The name of the Pygments (syntax highlighting) style to use.
73-
pygments_style = 'sphinx'
73+
pygments_style = "sphinx"
7474

7575
# If true, `todo` and `todoList` produce output, else they produce nothing.
7676
todo_include_todos = False
@@ -81,7 +81,7 @@
8181
# The theme to use for HTML and HTML Help pages. See the documentation for
8282
# a list of builtin themes.
8383
#
84-
html_theme = 'alabaster'
84+
html_theme = "alabaster"
8585

8686
# Theme options are theme-specific and customize the look and feel of a theme
8787
# further. For a list of options available for each theme, see the
@@ -92,13 +92,13 @@
9292
# Add any paths that contain custom static files (such as style sheets) here,
9393
# relative to this directory. They are copied after the builtin static files,
9494
# so a file named "default.css" will overwrite the builtin "default.css".
95-
html_static_path = ['_static']
95+
html_static_path = ["_static"]
9696

9797

9898
# -- Options for HTMLHelp output ------------------------------------------
9999

100100
# Output file base name for HTML help builder.
101-
htmlhelp_basename = 'PythonPerformanceBenchmarkSuitedoc'
101+
htmlhelp_basename = "PythonPerformanceBenchmarkSuitedoc"
102102

103103

104104
# -- Options for LaTeX output ---------------------------------------------
@@ -107,15 +107,12 @@
107107
# The paper size ('letterpaper' or 'a4paper').
108108
#
109109
# 'papersize': 'letterpaper',
110-
111110
# The font size ('10pt', '11pt' or '12pt').
112111
#
113112
# 'pointsize': '10pt',
114-
115113
# Additional stuff for the LaTeX preamble.
116114
#
117115
# 'preamble': '',
118-
119116
# Latex figure (float) alignment
120117
#
121118
# 'figure_align': 'htbp',
@@ -125,8 +122,13 @@
125122
# (source start file, target name, title,
126123
# author, documentclass [howto, manual, or own class]).
127124
latex_documents = [
128-
(master_doc, 'PythonPerformanceBenchmarkSuite.tex', 'Python Performance Benchmark Suite Documentation',
129-
'Victor Stinner', 'manual'),
125+
(
126+
master_doc,
127+
"PythonPerformanceBenchmarkSuite.tex",
128+
"Python Performance Benchmark Suite Documentation",
129+
"Victor Stinner",
130+
"manual",
131+
),
130132
]
131133

132134

@@ -135,8 +137,13 @@
135137
# One entry per manual page. List of tuples
136138
# (source start file, name, description, authors, manual section).
137139
man_pages = [
138-
(master_doc, 'pythonperformancebenchmarksuite', 'Python Performance Benchmark Suite Documentation',
139-
[author], 1)
140+
(
141+
master_doc,
142+
"pythonperformancebenchmarksuite",
143+
"Python Performance Benchmark Suite Documentation",
144+
[author],
145+
1,
146+
)
140147
]
141148

142149

@@ -146,10 +153,13 @@
146153
# (source start file, target name, title, author,
147154
# dir menu entry, description, category)
148155
texinfo_documents = [
149-
(master_doc, 'PythonPerformanceBenchmarkSuite', 'Python Performance Benchmark Suite Documentation',
150-
author, 'PythonPerformanceBenchmarkSuite', 'One line description of project.',
151-
'Miscellaneous'),
156+
(
157+
master_doc,
158+
"PythonPerformanceBenchmarkSuite",
159+
"Python Performance Benchmark Suite Documentation",
160+
author,
161+
"PythonPerformanceBenchmarkSuite",
162+
"One line description of project.",
163+
"Miscellaneous",
164+
),
152165
]
153-
154-
155-

pyperformance/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import sys
44
from importlib.metadata import distribution
55

6-
76
VERSION = (1, 11, 0)
8-
__version__ = '.'.join(map(str, VERSION))
7+
__version__ = ".".join(map(str, VERSION))
98

109

1110
PKG_ROOT = os.path.dirname(__file__)
12-
DATA_DIR = os.path.join(PKG_ROOT, 'data-files')
11+
DATA_DIR = os.path.join(PKG_ROOT, "data-files")
1312

1413

1514
def is_installed():
@@ -22,7 +21,7 @@ def is_installed():
2221

2322
def is_dev():
2423
parent = os.path.dirname(PKG_ROOT)
25-
return os.path.exists(os.path.join(parent, 'pyproject.toml'))
24+
return os.path.exists(os.path.join(parent, "pyproject.toml"))
2625

2726

2827
def _is_venv():

pyperformance/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import pyperformance.cli
2+
23
pyperformance.cli.main()

0 commit comments

Comments
 (0)