runtime_environment
logger
¶
RuntimeEnvironment (KiaraModel)
pydantic-model
¶
Source code in kiara/models/runtime_environment/__init__.py
class RuntimeEnvironment(KiaraModel):
class Config:
underscore_attrs_are_private = False
allow_mutation = False
@classmethod
def get_environment_type_name(cls) -> str:
env_type = cls.__fields__["environment_type"]
args = get_args(env_type.type_)
assert len(args) == 1
return args[0]
@classmethod
def create_environment_model(cls):
try:
type_name = cls.get_environment_type_name()
data = cls.retrieve_environment_data()
assert (
"environment_type" not in data.keys()
or data["environment_keys"] == type_name
)
data["environment_type"] = type_name
except Exception as e:
raise Exception(f"Can't create environment model for '{cls.__name__}': {e}")
return cls(**data)
def get_category_alias(self) -> str:
return f"{ENVIRONMENT_TYPE_CATEGORY_ID}.{self.environment_type}" # type: ignore
@classmethod
@abstractmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
pass
def _create_renderable_for_field(
self, field_name: str, for_summary: bool = False
) -> Optional[RenderableType]:
return extract_renderable(getattr(self, field_name))
def _retrieve_id(self) -> str:
return self.__class__.get_environment_type_name()
def create_renderable(self, **config: Any) -> RenderableType:
summary = config.get("summary", False)
table = Table(show_header=False, box=box.SIMPLE)
table.add_column("field")
table.add_column("summary")
for field_name, field in self.__fields__.items():
summary_item = self._create_renderable_for_field(
field_name, for_summary=summary
)
if summary_item is not None:
table.add_row(field_name, summary_item)
return table
Config
¶
create_environment_model()
classmethod
¶
Source code in kiara/models/runtime_environment/__init__.py
@classmethod
def create_environment_model(cls):
try:
type_name = cls.get_environment_type_name()
data = cls.retrieve_environment_data()
assert (
"environment_type" not in data.keys()
or data["environment_keys"] == type_name
)
data["environment_type"] = type_name
except Exception as e:
raise Exception(f"Can't create environment model for '{cls.__name__}': {e}")
return cls(**data)
create_renderable(self, **config)
¶
Source code in kiara/models/runtime_environment/__init__.py
def create_renderable(self, **config: Any) -> RenderableType:
summary = config.get("summary", False)
table = Table(show_header=False, box=box.SIMPLE)
table.add_column("field")
table.add_column("summary")
for field_name, field in self.__fields__.items():
summary_item = self._create_renderable_for_field(
field_name, for_summary=summary
)
if summary_item is not None:
table.add_row(field_name, summary_item)
return table
get_category_alias(self)
¶
Source code in kiara/models/runtime_environment/__init__.py
def get_category_alias(self) -> str:
return f"{ENVIRONMENT_TYPE_CATEGORY_ID}.{self.environment_type}" # type: ignore
get_environment_type_name()
classmethod
¶
Source code in kiara/models/runtime_environment/__init__.py
@classmethod
def get_environment_type_name(cls) -> str:
env_type = cls.__fields__["environment_type"]
args = get_args(env_type.type_)
assert len(args) == 1
return args[0]
retrieve_environment_data()
classmethod
¶
Source code in kiara/models/runtime_environment/__init__.py
@classmethod
@abstractmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
pass
Modules¶
kiara
¶
Classes¶
KiaraTypesRuntimeEnvironment (RuntimeEnvironment)
pydantic-model
¶
Source code in kiara/models/runtime_environment/kiara.py
class KiaraTypesRuntimeEnvironment(RuntimeEnvironment):
_kiara_model_id = "info.runtime.kiara_types"
environment_type: Literal["kiara_types"]
archive_types: ArchiveTypeClassesInfo = Field(
description="The available implemented store types."
)
metadata_types: MetadataTypeClassesInfo = Field(
description="The available metadata types."
)
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
result: Dict[str, Any] = {}
result["metadata_types"] = find_metadata_models()
result["archive_types"] = find_archive_types()
return result
Attributes¶
archive_types: ArchiveTypeClassesInfo
pydantic-field
required
¶The available implemented store types.
environment_type: Literal['kiara_types']
pydantic-field
required
¶metadata_types: MetadataTypeClassesInfo
pydantic-field
required
¶The available metadata types.
retrieve_environment_data()
classmethod
¶Source code in kiara/models/runtime_environment/kiara.py
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
result: Dict[str, Any] = {}
result["metadata_types"] = find_metadata_models()
result["archive_types"] = find_archive_types()
return result
find_archive_types(alias=None, only_for_package=None)
¶
Source code in kiara/models/runtime_environment/kiara.py
def find_archive_types(
alias: Optional[str] = None, only_for_package: Optional[str] = None
) -> ArchiveTypeClassesInfo:
archive_types = find_all_archive_types()
group: ArchiveTypeClassesInfo = ArchiveTypeClassesInfo.create_from_type_items( # type: ignore
group_alias=alias, **archive_types
)
if only_for_package:
temp: Dict[str, TypeInfo] = {}
for key, info in group.items():
if info.context.labels.get("package") == only_for_package:
temp[key] = info # type: ignore
group = ArchiveTypeClassesInfo.construct(
group_id=group.group_id, group_alias=group.group_alias, item_infos=temp # type: ignore
)
return group
operating_system
¶
Classes¶
OSRuntimeEnvironment (RuntimeEnvironment)
pydantic-model
¶
Manages information about the OS this kiara instance is running in.
TODO: details for other OS's (mainly BSDs)¶
Source code in kiara/models/runtime_environment/operating_system.py
class OSRuntimeEnvironment(RuntimeEnvironment):
"""Manages information about the OS this kiara instance is running in.
# TODO: details for other OS's (mainly BSDs)
"""
_kiara_model_id = "info.runtime.os"
environment_type: typing.Literal["operating_system"]
operation_system: str = Field(description="The operation system name.")
platform: str = Field(description="The platform name.")
release: str = Field(description="The platform release name.")
version: str = Field(description="The platform version name.")
machine: str = Field(description="The architecture.")
os_specific: typing.Dict[str, typing.Any] = Field(
description="OS specific platform metadata.", default_factory=dict
)
@classmethod
def retrieve_environment_data(self) -> typing.Dict[str, typing.Any]:
os_specific: typing.Dict[str, typing.Any] = {}
platform_system = platform.system()
if platform_system == "Linux":
import distro
os_specific["distribution"] = {
"name": distro.name(),
"version": distro.version(),
"codename": distro.codename(),
}
elif platform_system == "Darwin":
mac_version = platform.mac_ver()
os_specific["mac_ver_release"] = mac_version[0]
os_specific["mac_ver_machine"] = mac_version[2]
result = {
"operation_system": os.name,
"platform": platform_system,
"release": platform.release(),
"version": platform.version(),
"machine": platform.machine(),
"os_specific": os_specific,
}
# if config.include_all_info:
# result["uname"] = platform.uname()._asdict()
return result
Attributes¶
environment_type: Literal['operating_system']
pydantic-field
required
¶machine: str
pydantic-field
required
¶The architecture.
operation_system: str
pydantic-field
required
¶The operation system name.
os_specific: Dict[str, Any]
pydantic-field
¶OS specific platform metadata.
platform: str
pydantic-field
required
¶The platform name.
release: str
pydantic-field
required
¶The platform release name.
version: str
pydantic-field
required
¶The platform version name.
retrieve_environment_data()
classmethod
¶Source code in kiara/models/runtime_environment/operating_system.py
@classmethod
def retrieve_environment_data(self) -> typing.Dict[str, typing.Any]:
os_specific: typing.Dict[str, typing.Any] = {}
platform_system = platform.system()
if platform_system == "Linux":
import distro
os_specific["distribution"] = {
"name": distro.name(),
"version": distro.version(),
"codename": distro.codename(),
}
elif platform_system == "Darwin":
mac_version = platform.mac_ver()
os_specific["mac_ver_release"] = mac_version[0]
os_specific["mac_ver_machine"] = mac_version[2]
result = {
"operation_system": os.name,
"platform": platform_system,
"release": platform.release(),
"version": platform.version(),
"machine": platform.machine(),
"os_specific": os_specific,
}
# if config.include_all_info:
# result["uname"] = platform.uname()._asdict()
return result
python
¶
Classes¶
PythonPackage (BaseModel)
pydantic-model
¶
Source code in kiara/models/runtime_environment/python.py
class PythonPackage(BaseModel):
name: str = Field(description="The name of the Python package.")
version: str = Field(description="The version of the package.")
PythonRuntimeEnvironment (RuntimeEnvironment)
pydantic-model
¶
Source code in kiara/models/runtime_environment/python.py
class PythonRuntimeEnvironment(RuntimeEnvironment):
_kiara_model_id = "info.runtime.python"
environment_type: Literal["python"]
python_version: str = Field(description="The version of Python.")
packages: List[PythonPackage] = Field(
description="The packages installed in the Python (virtual) environment."
)
# python_config: typing.Dict[str, str] = Field(
# description="Configuration details about the Python installation."
# )
def _create_renderable_for_field(
self, field_name: str, for_summary: bool = False
) -> Optional[RenderableType]:
if field_name != "packages":
return extract_renderable(getattr(self, field_name))
if for_summary:
return ", ".join(p.name for p in self.packages)
table = Table(show_header=True, box=box.SIMPLE)
table.add_column("package name")
table.add_column("version")
for package in self.packages:
table.add_row(package.name, package.version)
return table
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
packages = []
all_packages = packages_distributions()
for name, pkgs in all_packages.items():
for pkg in pkgs:
dist = distribution(pkg)
packages.append({"name": name, "version": dist.version})
result: Dict[str, Any] = {
"python_version": sys.version,
"packages": sorted(packages, key=lambda x: x["name"]),
}
# if config.include_all_info:
# import sysconfig
# result["python_config"] = sysconfig.get_config_vars()
return result
Attributes¶
environment_type: Literal['python']
pydantic-field
required
¶packages: List[kiara.models.runtime_environment.python.PythonPackage]
pydantic-field
required
¶The packages installed in the Python (virtual) environment.
python_version: str
pydantic-field
required
¶The version of Python.
retrieve_environment_data()
classmethod
¶Source code in kiara/models/runtime_environment/python.py
@classmethod
def retrieve_environment_data(cls) -> Dict[str, Any]:
packages = []
all_packages = packages_distributions()
for name, pkgs in all_packages.items():
for pkg in pkgs:
dist = distribution(pkg)
packages.append({"name": name, "version": dist.version})
result: Dict[str, Any] = {
"python_version": sys.version,
"packages": sorted(packages, key=lambda x: x["name"]),
}
# if config.include_all_info:
# import sysconfig
# result["python_config"] = sysconfig.get_config_vars()
return result