Skip to content

Commit

Permalink
Use ruff for linting/formatting (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreinking authored Jan 7, 2025
1 parent e0ed8c8 commit 44f9b0e
Show file tree
Hide file tree
Showing 10 changed files with 649 additions and 472 deletions.
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/flake8.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Python Linter
on: push
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

# Check linter rules
- uses: astral-sh/ruff-action@v3

# Check formatting is correct
- uses: astral-sh/ruff-action@v3
with:
args: "format --check"
23 changes: 16 additions & 7 deletions .github/workflows/validations.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
name: Buildbot Validations
on: [ push, pull_request ]
on:
push:
paths:
- "**.py"
- "**.cfg"
- "**.tac"
jobs:
test:
name: Check buildbot config on Python ${{ matrix.python-version }}
# TODO: should be ubuntu-latest, but actions/setup-python doesn't work with ubuntu 22 just yet
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ 3.8, 3.9, "3.10", 3.11 ]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install importlib
python -m pip install importlib.metadata
python -m pip install -U pip setuptools wheel
pip install -r requirements.txt
- name: Check config
run: |
cd master
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot.tac
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ configfile = 'master.cfg'
# Default umask for server
umask = None

logfile = LogFile.fromFullPath(os.path.join(basedir, "twistd.log"),
rotateLength=rotateLength,
maxRotatedFiles=maxRotatedFiles)
logfile = LogFile.fromFullPath(
os.path.join(basedir, "twistd.log"), rotateLength=rotateLength, maxRotatedFiles=maxRotatedFiles
)

# note: this line is matched against to check that this is a buildmaster
# directory; do not edit it.
Expand Down
49 changes: 33 additions & 16 deletions master/custom_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SetPropertiesFromCMakeCache(CompositeStepMixin, BuildStep):
:([^=]*) # and will have a type.
=(.*)$ # The value extends through the end of the line.
''',
re.VERBOSE)
re.VERBOSE,
)

def __init__(self, *, props=None, normalize_bools=False, expand_lists=False, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -119,7 +120,7 @@ def run(self):
# Delete all but the newest self.keep files with the same key.
for group in groups.values():
group.sort(key=os.path.getmtime, reverse=True)
for file in group[self.keep:]:
for file in group[self.keep :]:
try:
file.unlink()
stdio.addStdout(f'Removed: {file.resolve()}\n')
Expand Down Expand Up @@ -154,8 +155,19 @@ def run(self):
class CTest(ShellMixin, CompositeStepMixin, BuildStep):
name = 'ctest'

def __init__(self, *, build_config=None, preset=None, jobs=None, tests=None, exclude_tests=None,
labels=None, exclude_labels=None, test_dir=None, **kwargs):
def __init__(
self,
*,
build_config=None,
preset=None,
jobs=None,
tests=None,
exclude_tests=None,
labels=None,
exclude_labels=None,
test_dir=None,
**kwargs,
):
kwargs['command'] = [
'ctest',
# Note, jobs may be a renderable, don't explicitly convert to str
Expand All @@ -168,8 +180,9 @@ def __init__(self, *, build_config=None, preset=None, jobs=None, tests=None, exc
# We always want output from performance tests
*(['--verbose'] if labels and 'performance' in labels else []),
'--output-on-failure',
'--test-action', 'Test',
'--no-compress-output'
'--test-action',
'Test',
'--no-compress-output',
]
assert (build_config is None) ^ (preset is None), "You must pass either build_config or preset, but not both"
if build_config:
Expand Down Expand Up @@ -201,23 +214,27 @@ def run(self):

for test in root.findall(".//Test[@Status='failed']"):
log = yield self.addLog(test.findtext('Name'))
self.write_xml(test,
("./Results/NamedMeasurement[@name='Environment']/Value", log.addHeader),
("./Results/NamedMeasurement[@name='Command Line']/Value", log.addHeader),
("./Results/Measurement/Value", log.addStdout),
("./Results/NamedMeasurement[@name='Fail Reason']/Value", log.addStderr))
self.write_xml(
test,
("./Results/NamedMeasurement[@name='Environment']/Value", log.addHeader),
("./Results/NamedMeasurement[@name='Command Line']/Value", log.addHeader),
("./Results/Measurement/Value", log.addStdout),
("./Results/NamedMeasurement[@name='Fail Reason']/Value", log.addStderr),
)
yield log.finish()

skipped = root.findall(".//Test[@Status='notrun']")
if skipped:
log = yield self.addLog('skipped')
for test in skipped:
log.addStdout(f'{test.findtext("Name")}\n')
self.write_xml(test,
("./Results/NamedMeasurement[@name='Environment']/Value", log.addHeader),
("./Results/NamedMeasurement[@name='Command Line']/Value", log.addHeader),
("./Results/Measurement/Value", log.addStdout),
indent=2)
self.write_xml(
test,
("./Results/NamedMeasurement[@name='Environment']/Value", log.addHeader),
("./Results/NamedMeasurement[@name='Command Line']/Value", log.addHeader),
("./Results/Measurement/Value", log.addStdout),
indent=2,
)
log.addStdout('\n')
yield log.finish()

Expand Down
Loading

0 comments on commit 44f9b0e

Please sign in to comment.