Skip to content

Commit

Permalink
Import modules in OCI.new() explicitly
Browse files Browse the repository at this point in the history
Also, add a type hint to the return type of OCI.new() so that this can now be
verified with mypy
  • Loading branch information
dcermak committed Jul 24, 2023
1 parent 1eb38c4 commit 2e3c7b4
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions kiwi/oci_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
#
import importlib
from abc import (
ABCMeta,
abstractmethod
)
from kiwi.oci_tools.base import OCIBase

# project
from kiwi.runtime_config import RuntimeConfig
Expand All @@ -37,20 +37,15 @@ def __init__(self) -> None:
return None # pragma: no cover

@staticmethod
def new():
name_map = {
'umoci': 'Umoci',
'buildah': 'Buildah'
}
runtime_config = RuntimeConfig()
tool_name = runtime_config.get_oci_archive_tool()
try:
oci_tool = importlib.import_module(
'kiwi.oci_tools.{}'.format(tool_name)
)
module_name = 'OCI{}'.format(name_map[tool_name])
return oci_tool.__dict__[module_name]()
except Exception:
def new() -> OCIBase:
tool_name = RuntimeConfig().get_oci_archive_tool()
if tool_name == "umoci":
from kiwi.oci_tools.umoci import OCIUmoci
return OCIUmoci()
elif tool_name == "buildah":
from kiwi.oci_tools.buildah import OCIBuildah
return OCIBuildah()
else:
raise KiwiOCIArchiveToolError(
'No support for {0} tool available'.format(tool_name)
)

0 comments on commit 2e3c7b4

Please sign in to comment.