Skip to content

Commit 96d6df2

Browse files
committed
Add pre-commit
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent c8cb67a commit 96d6df2

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v6.0.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: mixed-line-ending
8+
args: ['--fix', 'lf']
9+
exclude: '.*\.(svg)$'
10+
- id: fix-byte-order-marker
11+
- id: check-executables-have-shebangs
12+
- id: check-merge-conflict
13+
- id: debug-statements
14+
- id: check-yaml
15+
files: .*\.(yaml|yml)$
16+
exclude: '^zuul.d/.*$'
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.15.4
19+
hooks:
20+
- id: ruff-check
21+
args: ['--fix', '--unsafe-fixes']
22+
- id: ruff-format

scripts/all-pythons

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,61 @@ Prints output as a subunit test suite. If anything goes to stderr, that is
66
treated as a test error. If a Python is not available, then it is skipped.
77
"""
88

9-
from datetime import datetime
109
import io
1110
import os
1211
import subprocess
1312
import sys
13+
from datetime import datetime
1414

1515
import subunit
1616
from subunit import (
17-
iso8601,
18-
_make_stream_binary,
1917
TestProtocolClient,
2018
TestProtocolServer,
21-
)
19+
_make_stream_binary,
20+
iso8601,
21+
)
22+
2223
from testtools import (
2324
PlaceHolder,
24-
TestCase,
25-
)
25+
)
2626
from testtools.content import text_content
2727

28-
2928
ROOT = os.path.dirname(os.path.dirname(__file__))
3029

3130

3231
def run_for_python(version, result, tests):
3332
if not tests:
34-
tests = ['tests.test_suite']
33+
tests = ["tests.test_suite"]
3534
# XXX: This could probably be broken up and put into subunit.
36-
python = 'python%s' % (version,)
35+
python = f"python{version}"
3736
# XXX: Correct API, but subunit doesn't support it. :(
3837
# result.tags(set(python), set())
3938
result.time(now())
40-
test = PlaceHolder(''.join(c for c in python if c != '.'))
39+
test = PlaceHolder("".join(c for c in python if c != "."))
4140
process = subprocess.Popen(
42-
'%s -c pass' % (python,), shell=True,
43-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41+
f"{python} -c pass", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
42+
)
4443
process.communicate()
4544

4645
if process.returncode:
4746
result.startTest(test)
48-
result.addSkip(test, reason='%s not available' % (python,))
47+
result.addSkip(test, reason=f"{python} not available")
4948
result.stopTest(test)
5049
return
5150

5251
env = os.environ.copy()
53-
if env.get('PYTHONPATH', None):
54-
env['PYTHONPATH'] = os.pathsep.join([ROOT, env['PYTHONPATH']])
52+
if env.get("PYTHONPATH", None):
53+
env["PYTHONPATH"] = os.pathsep.join([ROOT, env["PYTHONPATH"]])
5554
else:
56-
env['PYTHONPATH'] = ROOT
55+
env["PYTHONPATH"] = ROOT
5756
result.time(now())
5857
protocol = TestProtocolServer(result)
59-
subunit_path = os.path.join(os.path.dirname(subunit.__file__), 'run.py')
60-
cmd = [
61-
python,
62-
'-W', 'ignore:Module testtools was already imported',
63-
subunit_path]
58+
subunit_path = os.path.join(os.path.dirname(subunit.__file__), "run.py")
59+
cmd = [python, "-W", "ignore:Module testtools was already imported", subunit_path]
6460
cmd.extend(tests)
6561
process = subprocess.Popen(
66-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
62+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
63+
)
6764
_make_stream_binary(process.stdout)
6865
_make_stream_binary(process.stderr)
6966
# XXX: This buffers everything. Bad for memory, bad for getting progress
@@ -72,22 +69,24 @@ def run_for_python(version, result, tests):
7269
protocol.readFrom(io.BytesIO(output))
7370
if error:
7471
result.startTest(test)
75-
result.addError(test, details={
76-
'stderr': text_content(error),
77-
})
72+
result.addError(
73+
test,
74+
details={
75+
"stderr": text_content(error),
76+
},
77+
)
7878
result.stopTest(test)
7979
result.time(now())
8080
# XXX: Correct API, but subunit doesn't support it. :(
81-
#result.tags(set(), set(python))
81+
# result.tags(set(), set(python))
8282

8383

8484
def now():
8585
return datetime.now(tz=iso8601.Utc())
8686

8787

88-
89-
if __name__ == '__main__':
88+
if __name__ == "__main__":
9089
sys.path.append(ROOT)
9190
result = TestProtocolClient(sys.stdout)
92-
for version in '3.10 3.11 3.12 3.13 3.14'.split():
91+
for version in "3.10 3.11 3.12 3.13 3.14".split():
9392
run_for_python(version, result, sys.argv[1:])

scripts/update-rtfd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
from urllib2 import urlopen
44

5+
WEB_HOOK = "http://readthedocs.org/build/588"
56

6-
WEB_HOOK = 'http://readthedocs.org/build/588'
77

8-
9-
if __name__ == '__main__':
10-
urlopen(WEB_HOOK, data=' ')
8+
if __name__ == "__main__":
9+
urlopen(WEB_HOOK, data=" ")

testtools/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
# Copyright (c) 2009 testtools developers. See LICENSE for details.
24

35
"""python -m testtools.run testspec [testspec...]

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ commands =
1212

1313
[testenv:ruff]
1414
deps =
15-
ruff
15+
pre-commit
1616
commands =
17-
ruff check --fix .
18-
ruff format .
17+
pre-commit run -a
1918

2019
[testenv:mypy]
2120
deps =

0 commit comments

Comments
 (0)