From 6cfc3912ab6c7508fc4a1b78bf7c9f88f8bee569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Wed, 16 Oct 2024 16:50:19 +0200 Subject: [PATCH] Turn DiskFormat into an ordinary class - it does not need to be an abstract base class - use f-strings where applicable instead of format() - change return type of _custom_args_for_format from list to tuple --- kiwi/storage/subformat/__init__.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/kiwi/storage/subformat/__init__.py b/kiwi/storage/subformat/__init__.py index 3388b511b3b..75ca857c17b 100644 --- a/kiwi/storage/subformat/__init__.py +++ b/kiwi/storage/subformat/__init__.py @@ -16,17 +16,15 @@ # along with kiwi. If not, see # import importlib -from abc import ( - ABCMeta, - abstractmethod -) +from typing import Dict, Optional, Tuple # project +from kiwi.storage.subformat.base import DiskFormatBase from kiwi.xml_state import XMLState from kiwi.exceptions import KiwiDiskFormatSetupError -class DiskFormat(metaclass=ABCMeta): +class DiskFormat: """ **DiskFormat factory** @@ -35,15 +33,11 @@ class DiskFormat(metaclass=ABCMeta): :param string root_dir: root directory path name :param string target_dir: target directory path name """ - @abstractmethod - def __init__(self) -> None: - return None # pragma: no cover @staticmethod - @abstractmethod def new( name: str, xml_state: XMLState, root_dir: str, target_dir: str - ): # noqa: E252 + ) -> DiskFormatBase: name_map = { 'qcow2': 'Qcow2', 'vdi': 'Vdi', @@ -57,25 +51,24 @@ def new( 'vagrant_virtualbox': 'VagrantVirtualBox', 'base': 'Base' } + module_namespace: Optional[str] = None try: - (custom_args, module_namespace) = DiskFormat.\ + custom_args, module_namespace = DiskFormat.\ _custom_args_for_format(name, xml_state) diskformat = importlib.import_module( - 'kiwi.storage.subformat.{0}'.format(module_namespace) + f'kiwi.storage.subformat.{module_namespace}' ) - module_name = 'DiskFormat{0}'.format(name_map[module_namespace]) + module_name = f'DiskFormat{name_map[module_namespace]}' return diskformat.__dict__[module_name]( xml_state, root_dir, target_dir, custom_args ) except Exception as issue: raise KiwiDiskFormatSetupError( - 'No support for {0} disk format: {1}'.format( - module_namespace, issue - ) + f'No support for {module_namespace} disk format: {issue}' ) @staticmethod - def _custom_args_for_format(name: str, xml_state: XMLState): + def _custom_args_for_format(name: str, xml_state: XMLState) -> Tuple[Dict, str]: custom_args = xml_state.get_build_type_format_options() module_namespace = name if name == 'vhd-fixed': @@ -115,4 +108,4 @@ def _custom_args_for_format(name: str, xml_state: XMLState): ) elif name == 'raw': module_namespace = 'base' - return [custom_args, module_namespace] + return custom_args, module_namespace