Skip to content

Commit af6e0cf

Browse files
committed
Controller: split action_build()
Refactor action_build() function in Controller module by moving part of its code in new function build_pkgs(). The purpose is to reduce complexity of action_build() and avoid reaching Pylint branching limit.
1 parent 027f05b commit af6e0cf

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

lib/rift/Controller.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,38 @@ def action_vm(args, config):
742742
ret = vm_build(vm, args, config)
743743
return ret
744744

745+
def build_pkgs(config, args, pkgs, arch, results):
746+
"""Build a list of packages on a given architecture and report results."""
747+
for pkg in pkgs:
748+
case = TestCase('build', pkg.name, arch)
749+
now = time.time()
750+
try:
751+
spec = Spec(pkg.specfile, config=config)
752+
except RiftError as ex:
753+
logging.error("Unable to load spec file: %s", str(ex))
754+
results.add_failure(case, time.time() - now, err=str(ex))
755+
continue # skip current package
756+
757+
if not spec.supports_arch(arch):
758+
logging.info(
759+
"Skipping build on architecture %s not supported by "
760+
"package %s",
761+
arch,
762+
pkg.name
763+
)
764+
continue
765+
766+
banner(f"Building package '{pkg.name}' for architecture {arch}")
767+
now = time.time()
768+
try:
769+
pkg.load()
770+
build_pkg(config, args, pkg, arch)
771+
except RiftError as ex:
772+
logging.error("Build failure: %s", str(ex))
773+
results.add_failure(case, time.time() - now, err=str(ex))
774+
else:
775+
results.add_success(case, time.time() - now)
776+
745777
def action_build(args, config):
746778
"""Action for 'build' command."""
747779

@@ -761,36 +793,8 @@ def action_build(args, config):
761793
# Build all packages for all project supported architectures
762794
for arch in config.get('arch'):
763795

764-
for pkg in Package.list(config, staff, modules, args.packages):
765-
766-
case = TestCase('build', pkg.name, arch)
767-
now = time.time()
768-
try:
769-
spec = Spec(pkg.specfile, config=config)
770-
except RiftError as ex:
771-
logging.error("Unable to load spec file: %s", str(ex))
772-
results.add_failure(case, time.time() - now, err=str(ex))
773-
continue # skip current package
774-
775-
if not spec.supports_arch(arch):
776-
logging.info(
777-
"Skipping build on architecture %s not supported by "
778-
"package %s",
779-
arch,
780-
pkg.name
781-
)
782-
continue
783-
784-
banner(f"Building package '{pkg.name}' for architecture {arch}")
785-
now = time.time()
786-
try:
787-
pkg.load()
788-
build_pkg(config, args, pkg, arch)
789-
except RiftError as ex:
790-
logging.error("Build failure: %s", str(ex))
791-
results.add_failure(case, time.time() - now, err=str(ex))
792-
else:
793-
results.add_success(case, time.time() - now)
796+
pkgs = Package.list(config, staff, modules, args.packages)
797+
build_pkgs(config, args, pkgs, arch, results)
794798

795799
if getattr(args, 'junit', False):
796800
logging.info('Writing test results in %s', args.junit)

0 commit comments

Comments
 (0)