Skip to content

Commit

Permalink
ruff: normalize quote type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreinking committed Jan 7, 2025
1 parent 44f9b0e commit 5d2dcd1
Show file tree
Hide file tree
Showing 5 changed files with 542 additions and 545 deletions.
4 changes: 2 additions & 2 deletions master/buildbot.tac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from twisted.python.logfile import LogFile
basedir = str(Path(__file__).parent.resolve())
rotateLength = 10000000
maxRotatedFiles = 10
configfile = 'master.cfg'
configfile = "master.cfg"

# Default umask for server
umask = None
Expand All @@ -20,7 +20,7 @@ logfile = LogFile.fromFullPath(

# note: this line is matched against to check that this is a buildmaster
# directory; do not edit it.
application = service.Application('buildmaster')
application = service.Application("buildmaster")
application.setComponent(ILogObserver, FileLogObserver(logfile).emit)

m = BuildMaster(basedir, configfile, umask)
Expand Down
106 changes: 53 additions & 53 deletions master/custom_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
from buildbot.steps.worker import CompositeStepMixin
from twisted.internet import defer

__all__ = ['CleanOldFiles', 'CTest', 'FileUploadIfNotExist', 'SetPropertiesFromCMakeCache']
__all__ = ["CleanOldFiles", "CTest", "FileUploadIfNotExist", "SetPropertiesFromCMakeCache"]


class SetPropertiesFromCMakeCache(CompositeStepMixin, BuildStep):
name = 'set-properties-from-cmake-cache'
name = "set-properties-from-cmake-cache"

renderables = ['props']
renderables = ["props"]

# Parsing with regex is safe because the CMakeCache.txt format
# hasn't changed since 2006, according to `git blame`. Caveat:
# they have backwards compatibility code for parsing entries with
# quoted names and missing types. We don't bother with that here.
_cache_re = re.compile(
r'''
r"""
^(?!//|\#) # Ignore comment lines.
([^:=]+?) # Get the variable name,
(-ADVANCED)? # which might be marked as advanced,
:([^=]*) # and will have a type.
=(.*)$ # The value extends through the end of the line.
''',
""",
re.VERBOSE,
)

Expand All @@ -45,22 +45,22 @@ def run(self):
if not self.props:
return SUCCESS

log = yield self.addLog('props')
log = yield self.addLog("props")

cache = yield self.getFileContentFromWorker(f'{self.workdir}/CMakeCache.txt', abandonOnFailure=True)
cache = yield self.getFileContentFromWorker(f"{self.workdir}/CMakeCache.txt", abandonOnFailure=True)
cache = self._parse_cache(cache)

to_find = set(self.props)
found = to_find & cache.keys()
not_found = to_find - cache.keys()

for key in found:
log.addStdout(f'{key}={cache[key]}\n')
self.setProperty(key, cache[key], 'CMakeCache')
log.addStdout(f"{key}={cache[key]}\n")
self.setProperty(key, cache[key], "CMakeCache")

for key in not_found:
log.addStderr(f'Cache entry not found: {key}\n')
self.setProperty(key, '', 'CMakeCache')
log.addStderr(f"Cache entry not found: {key}\n")
self.setProperty(key, "", "CMakeCache")

yield log.finish()
return WARNINGS if not_found else SUCCESS
Expand All @@ -71,7 +71,7 @@ def _parse_cache(self, cache: str):
match = self._cache_re.match(entry)
if match:
key, is_advanced, ty, value = match.groups()
if ty == 'BOOL' and self.normalize_bools:
if ty == "BOOL" and self.normalize_bools:
value = self._normalize_bools(value)
if self.expand_lists:
value = self._expand_lists(value)
Expand All @@ -80,24 +80,24 @@ def _parse_cache(self, cache: str):

@staticmethod
def _expand_lists(value: str):
if ';' in value:
return value.split(';')
if ";" in value:
return value.split(";")
return value

@staticmethod
def _normalize_bools(value: str):
value = value.upper().strip()
if value.endswith('-NOTFOUND'):
return '0'
if value in {'1', 'ON', 'YES', 'TRUE', 'Y'}:
return '1'
if value in {'0', 'OFF', 'NO', 'FALSE', 'N', 'IGNORE', 'NOTFOUND'}:
return '0'
if value.endswith("-NOTFOUND"):
return "0"
if value in {"1", "ON", "YES", "TRUE", "Y"}:
return "1"
if value in {"0", "OFF", "NO", "FALSE", "N", "IGNORE", "NOTFOUND"}:
return "0"
raise ValueError(f'Invalid CMake bool "{value}"')


class CleanOldFiles(BuildStep):
name = 'clean-old'
name = "clean-old"

def __init__(self, *, groupfn, workdir, keep=1, **kwargs):
super().__init__(**kwargs)
Expand All @@ -107,7 +107,7 @@ def __init__(self, *, groupfn, workdir, keep=1, **kwargs):

@defer.inlineCallbacks
def run(self):
stdio = yield self.addLog('stdio')
stdio = yield self.addLog("stdio")
status = SUCCESS

# Group files in workdir together using the supplied function.
Expand All @@ -123,9 +123,9 @@ def run(self):
for file in group[self.keep :]:
try:
file.unlink()
stdio.addStdout(f'Removed: {file.resolve()}\n')
stdio.addStdout(f"Removed: {file.resolve()}\n")
except (FileNotFoundError, OSError) as e:
stdio.addStderr(f'Could not delete {file.resolve()}: {e}\n')
stdio.addStderr(f"Could not delete {file.resolve()}: {e}\n")
status = FAILURE

yield stdio.finish()
Expand All @@ -137,13 +137,13 @@ def run(self):
# filename contains (eg) a git commit or SHA that uniquely
# identifies the file version.
class FileUploadIfNotExist(FileUpload):
name = 'file-upload-if-not-exist'
name = "file-upload-if-not-exist"

@defer.inlineCallbacks
def run(self):
masterdest = os.path.expanduser(self.masterdest)
if os.path.isfile(masterdest) and os.path.getsize(masterdest) > 0:
stdio = yield self.addLog('stdio')
stdio = yield self.addLog("stdio")
stdio.addStdout(f"File {repr(masterdest)} already exists on dest, skipping upload!")
yield stdio.finish()
return SUCCESS
Expand All @@ -153,7 +153,7 @@ def run(self):


class CTest(ShellMixin, CompositeStepMixin, BuildStep):
name = 'ctest'
name = "ctest"

def __init__(
self,
Expand All @@ -168,52 +168,52 @@ def __init__(
test_dir=None,
**kwargs,
):
kwargs['command'] = [
'ctest',
kwargs["command"] = [
"ctest",
# Note, jobs may be a renderable, don't explicitly convert to str
*(['--parallel', jobs] if jobs else []),
*(['--tests-regex', '|'.join(tests)] if tests else []),
*(['--exclude-regex', '|'.join(exclude_tests)] if exclude_tests else []),
*(['--label-regex', '|'.join(labels)] if labels else []),
*(['--label-exclude', '|'.join(exclude_labels)] if exclude_labels else []),
*(['--test-dir', test_dir] if test_dir else []),
*(["--parallel", jobs] if jobs else []),
*(["--tests-regex", "|".join(tests)] if tests else []),
*(["--exclude-regex", "|".join(exclude_tests)] if exclude_tests else []),
*(["--label-regex", "|".join(labels)] if labels else []),
*(["--label-exclude", "|".join(exclude_labels)] if exclude_labels else []),
*(["--test-dir", test_dir] if test_dir else []),
# We always want output from performance tests
*(['--verbose'] if labels and 'performance' in labels else []),
'--output-on-failure',
'--test-action',
'Test',
'--no-compress-output',
*(["--verbose"] if labels and "performance" in labels else []),
"--output-on-failure",
"--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:
kwargs['command'] += ['--build-config', build_config]
kwargs["command"] += ["--build-config", build_config]
if preset:
kwargs['command'] += ['--preset', preset]
kwargs["command"] += ["--preset", preset]

kwargs = self.setupShellMixin(kwargs)
super().__init__(**kwargs)

@defer.inlineCallbacks
def run(self):
# Remove any leftover log files (if they exist)
yield self.runRmdir(f'{self.workdir}/Testing', abandonOnFailure=False)
yield self.runRmdir(f"{self.workdir}/Testing", abandonOnFailure=False)

# Run CTest
cmd = yield self.makeRemoteShellCommand()
yield self.runCommand(cmd)

# Upload the XML log from the CTest run
xml_results = yield self.runGlob(f'{self.workdir}/Testing/*/*.xml')
xml_results = yield self.runGlob(f"{self.workdir}/Testing/*/*.xml")
if len(xml_results) != 1:
raise BuildStepFailed(f'Expected to find a single XML file. Got: {xml_results}')
raise BuildStepFailed(f"Expected to find a single XML file. Got: {xml_results}")

ctest_log = yield self.getFileContentFromWorker(xml_results[0], abandonOnFailure=True)

# Parse the result, collecting test failures into more convenient logs.
root = Xml.fromstring(ctest_log)

for test in root.findall(".//Test[@Status='failed']"):
log = yield self.addLog(test.findtext('Name'))
log = yield self.addLog(test.findtext("Name"))
self.write_xml(
test,
("./Results/NamedMeasurement[@name='Environment']/Value", log.addHeader),
Expand All @@ -225,7 +225,7 @@ def run(self):

skipped = root.findall(".//Test[@Status='notrun']")
if skipped:
log = yield self.addLog('skipped')
log = yield self.addLog("skipped")
for test in skipped:
log.addStdout(f'{test.findtext("Name")}\n')
self.write_xml(
Expand All @@ -235,7 +235,7 @@ def run(self):
("./Results/Measurement/Value", log.addStdout),
indent=2,
)
log.addStdout('\n')
log.addStdout("\n")
yield log.finish()

return cmd.results()
Expand All @@ -249,10 +249,10 @@ def write_xml(self, test, *sections, indent=0):
@staticmethod
def clean_text(text, *, indent=0):
indent = " " * indent
text = text or ''
if 'Regex=[' in text: # clean up annoying CTest output
text = text.replace('\n]', ']\n')
text = text or ""
if "Regex=[" in text: # clean up annoying CTest output
text = text.replace("\n]", "]\n")
text = text.strip()
text = text.replace('\n', f'\n{indent}')
text = f'{indent}{text}\n'
text = text.replace("\n", f"\n{indent}")
text = f"{indent}{text}\n"
return text
Loading

0 comments on commit 5d2dcd1

Please sign in to comment.