Commit 2f347271 authored by Hejing Li's avatar Hejing Li
Browse files

turn some imports only for typechecking

parent 8583746a
......@@ -23,19 +23,20 @@
import typing as tp
import abc
import io
from simbricks.orchestration.system.host import base
from simbricks.orchestration.experiment import experiment_environment as expenv
if tp.TYPE_CHECKING:
from simbricks.orchestration.system.host import base
class Application(abc.ABC):
def __init__(self, h: base.Host) -> None:
def __init__(self, h: 'Host') -> None:
self.host = h
# Note AK: Maybe we can factor most of the duplicate calls with the host out
# into a separate module.
class BaseLinuxApplication(abc.ABC):
def __init__(self, h: base.LinuxHost) -> None:
def __init__(self, h: 'LinuxHost') -> None:
self.host = h
self.start_delay: float | None = None
self.end_delay: float | None = None
......
......@@ -24,19 +24,18 @@ import typing as tp
import io
from os import path
from simbricks.orchestration.experiment import experiment_environment as expenv
from simbricks.orchestration.system import base
from simbricks.orchestration.system import eth
from simbricks.orchestration.system import mem
from simbricks.orchestration.system import pcie
from simbricks.orchestration.system.host import disk_images
from simbricks.orchestration.system.host import app
from simbricks.orchestration.system import base as base
if tp.TYPE_CHECKING:
from simbricks.orchestration.system import (eth, mem, pcie)
from simbricks.orchestration.system.host import disk_images
from simbricks.orchestration.system.host import app
class Host(base.Component):
def __init__(self, s: base.System):
super().__init__(s)
self.ifs: list[base.Interface] = []
self.applications: list[app.Application]
self.applications: list['Application']
def interfaces(self) -> list[base.Interface]:
return self.pcie_ifs + self.eth_ifs + self.mem_ifs
......@@ -44,7 +43,7 @@ class Host(base.Component):
def add_if(self, i: base.Interface) -> None:
self.ifs.append(i)
def add_app(self, a: app.Application) -> None:
def add_app(self, a: 'Application') -> None:
self.applications.append(a)
......@@ -54,26 +53,26 @@ class FullSystemHost(Host):
self.memory = 512
self.cores = 1
self.cpu_freq = '3GHz'
self.disks: list[disk_images.DiskImage] = []
self.disks: list['DiskImage'] = []
def add_disk(self, disk: disk_images.DiskImage) -> None:
def add_disk(self, disk: 'DiskImage') -> None:
self.disks.append(disk)
class BaseLinuxHost(FullSystemHost):
def __init__(self, s: base.System) -> None:
super().__init__(s)
self.applications: list[app.BaseLinuxApplication] = []
self.applications: list['BaseLinuxApplication'] = []
self.load_modules = []
self.kcmd_append = ''
def add_app(self, a: app.BaseLinuxApplication) -> None:
def add_app(self, a: 'BaseLinuxApplication') -> None:
self.applications.append(a)
def _concat_app_cmds(
self,
env: expenv.ExpEnv,
mapper: tp.Callable[[app.BaseLinuxApplication, expenv.ExpEnv],
mapper: tp.Callable[['BaseLinuxApplication', expenv.ExpEnv],
list[str]]
) -> list[str]:
"""
......
......@@ -24,12 +24,14 @@ import abc
import io
import os.path
import tarfile
from simbricks.orchestration.system.host import base
import typing as tp
from simbricks.orchestration.experiment import experiment_environment as expenv
if tp.TYPE_CHECKING:
from simbricks.orchestration.system.host import base
class DiskImage(abc.ABC):
def __init__(self, h: base.Host) -> None:
def __init__(self, h: 'Host') -> None:
self.host = h
@abc.abstractmethod
......@@ -43,7 +45,7 @@ class DiskImage(abc.ABC):
# Disk image where user just provides a path
class ExternalDiskImage(DiskImage):
def __init__(self, h: base.FullSystemHost, path: str) -> None:
def __init__(self, h: 'FullSystemHost', path: str) -> None:
super().__init__(h)
self.path = path
self.formats = ["raw", "qcow2"]
......@@ -58,7 +60,7 @@ class ExternalDiskImage(DiskImage):
# Disk images shipped with simbricks
class DistroDiskImage(DiskImage):
def __init__(self, h: base.FullSystemHost, name: str) -> None:
def __init__(self, h: 'FullSystemHost', name: str) -> None:
super().__init__(h)
self.name = name
self.formats = ["raw", "qcow2"]
......@@ -80,7 +82,7 @@ class DistroDiskImage(DiskImage):
# Builds the Tar with the commands to run etc.
class LinuxConfigDiskImage(DiskImage):
def __init__(self, h: base.LinuxHost) -> None:
def __init__(self, h: 'LinuxHost') -> None:
super().__init__(h)
self.host: base.LinuxHost
......@@ -117,7 +119,7 @@ class LinuxConfigDiskImage(DiskImage):
# Could of course also have a version that generates the packer config from
# python
class PackerDiskImage(DiskImage):
def __init__(self, h: base.FullSystemHost, packer_config_path: str) -> None:
def __init__(self, h: 'FullSystemHost', packer_config_path: str) -> None:
super().__init__(h)
self.config_path = packer_config_path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment