Skip to content

Commit

Permalink
Clean-up common_factories.py
Browse files Browse the repository at this point in the history
1. Eliminate star imports. Import what you use.
2. Eliminate redundant f-strings without placeholders.
3. Fix wrong escape \ character in Windows-like paths.
4. Eliminate (some) long lines over 80 characters.
  • Loading branch information
cvicentiu committed Nov 25, 2024
1 parent 4be5d7c commit c6caa3e
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions common_factories.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
import os
import re

from twisted.internet import defer

from buildbot.plugins import *
from buildbot.plugins import steps, util
from buildbot.process import results
from buildbot.process.factory import BuildFactory
from buildbot.process.properties import Properties, Property
from buildbot.process.remotecommand import RemoteCommand
from buildbot.steps.mtrlogobserver import MTR, MtrLogObserver
from buildbot.steps.package.rpm.rpmlint import RpmLint
from buildbot.steps.shell import Compile, SetPropertyFromCommand, ShellCommand, Test
from buildbot.steps.source.github import GitHub
from constants import *
from utils import *
from buildbot.process.properties import Property
from buildbot.steps.mtrlogobserver import MTR

# Local
from constants import MTR_ENV, test_type_to_mtr_arg
from utils import (
createVar,
dockerfile,
getArch,
getHTMLLogString,
getSourceTarball,
hasAutobake,
hasBigtest,
hasCompat,
hasDockerLibrary,
hasEco,
hasFailed,
hasFiles,
hasGalera,
hasInstall,
hasRpmLint,
hasUpgrade,
ls2string,
moveMTRLogs,
mtrEnv,
mtrJobsMultiplier,
printEnv,
saveLogs,
savePackage,
)


# TODO for FetchTestData/getLastNFailedBuildsFactory
Expand Down Expand Up @@ -80,7 +105,7 @@ def run(self):
def addPostTests(factory):
factory.addStep(saveLogs())

## trigger packages
# trigger packages
factory.addStep(
steps.Trigger(
schedulerNames=["s_packages"],
Expand All @@ -96,7 +121,7 @@ def addPostTests(factory):
doStepIf=hasAutobake,
)
)
## trigger bigtest
# trigger bigtest
factory.addStep(
steps.Trigger(
schedulerNames=["s_bigtest"],
Expand Down Expand Up @@ -142,7 +167,6 @@ def addPostTests(factory):
waitForFinish=False,
updateSourceStamp=False,
set_properties={
"parentbuildername": Property("buildername"),
"tarbuildnum": Property("tarbuildnum"),
"mariadb_binary": Property("mariadb_binary"),
"mariadb_version": Property("mariadb_version"),
Expand All @@ -154,7 +178,9 @@ def addPostTests(factory):
)
factory.addStep(
steps.ShellCommand(
name="cleanup", command="rm -r * .* 2> /dev/null || true", alwaysRun=True
name="cleanup",
command="rm -r * .* 2> /dev/null || true",
alwaysRun=True
)
)
return factory
Expand All @@ -179,7 +205,8 @@ def getBuildFactoryPreTest(build_type="RelWithDebInfo", additional_args=""):
"-c",
util.Interpolate(
getHTMLLogString(),
jobs=util.Property("jobs", default="$(getconf _NPROCESSORS_ONLN)"),
jobs=util.Property(
"jobs", default="$(getconf _NPROCESSORS_ONLN)"),
),
],
)
Expand Down Expand Up @@ -219,7 +246,8 @@ def getBuildFactoryPreTest(build_type="RelWithDebInfo", additional_args=""):
return f_quick_build


# TODO single function or class object to handle adding tests for different platforms
# TODO single function or class object to handle adding tests for different
# platforms
def addWinTests(
factory: BuildFactory,
mtr_test_type: str,
Expand All @@ -229,9 +257,8 @@ def addWinTests(
mtr_suites: list[str],
create_scripts: bool = False,
) -> BuildFactory:

if "default" in mtr_suites:
cmd = f"..\\mysql-test\\collections\\buildbot_suites.bat && cd .."
cmd = "..\\mysql-test\\collections\\buildbot_suites.bat && cd .."
else:
suites = ",".join(mtr_suites)
cmd = (
Expand Down Expand Up @@ -274,7 +301,7 @@ def addWinTests(
"dojob",
'"',
util.Interpolate(
f'"C:\Program Files (x86)\Microsoft Visual Studio\\2022\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=%(kw:arch)s && cd mysql-test && {cmd}',
f'"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat" -arch=%(kw:arch)s && cd mysql-test && {cmd}',
mtr_additional_args=mtr_additional_args,
jobs=util.Property("jobs", default=4),
arch=util.Property("arch", default="x64"),
Expand Down Expand Up @@ -505,7 +532,6 @@ def getTests(props):


def getRpmAutobakeFactory(mtrDbPool):
## f_rpm_autobake
f_rpm_autobake = util.BuildFactory()
f_rpm_autobake.addStep(printEnv())
f_rpm_autobake.addStep(
Expand Down Expand Up @@ -694,7 +720,9 @@ def getRpmAutobakeFactory(mtrDbPool):
)
f_rpm_autobake.addStep(
steps.ShellCommand(
name="cleanup", command="rm -r * .* 2> /dev/null || true", alwaysRun=True
name="cleanup",
command="rm -r * .* 2> /dev/null || true",
alwaysRun=True
)
)
return f_rpm_autobake

0 comments on commit c6caa3e

Please sign in to comment.