2025-11-25 18:09:46 +03:00
|
|
|
import json
|
|
|
|
|
from warnings import warn
|
2025-03-21 17:47:09 +03:00
|
|
|
from dynamix_sdk import config
|
2025-11-25 18:09:46 +03:00
|
|
|
from dynamix_sdk.exceptions import IncompatibleAPIError
|
|
|
|
|
from dynamix_sdk.utils import F_DECORATOR
|
2025-03-21 17:47:09 +03:00
|
|
|
from .api import API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Dynamix:
|
|
|
|
|
_config: config.ConfigWithAuth
|
2026-02-11 12:20:55 +03:00
|
|
|
_COMPATIBLE_DX_MINOR_VERSION: str = '4.5'
|
|
|
|
|
_COMPATIBLE_DX_BUILD: int = 1269
|
|
|
|
|
_COMPATIBILITY_WITH_NEWER_DX_BUILDS: bool = True
|
|
|
|
|
_dx_version: str
|
2025-11-25 18:09:46 +03:00
|
|
|
_dx_build: int
|
2025-03-21 17:47:09 +03:00
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
*,
|
|
|
|
|
url: str,
|
|
|
|
|
auth: str | config.AuthenticatorProtocol,
|
|
|
|
|
verify_ssl: bool = True,
|
|
|
|
|
http503_attempts: int = 10,
|
|
|
|
|
http503_attempts_interval: int = 5,
|
|
|
|
|
result_extra_allow: bool = False,
|
2025-11-25 18:09:46 +03:00
|
|
|
ignore_api_compatibility: bool = False,
|
|
|
|
|
wrap_request_exceptions: bool = False,
|
|
|
|
|
f_decorators: list[F_DECORATOR] | None = None,
|
2025-03-21 17:47:09 +03:00
|
|
|
):
|
|
|
|
|
self._config = config.ConfigWithAuth(
|
|
|
|
|
base_api_path='/restmachine',
|
|
|
|
|
url=url,
|
|
|
|
|
auth=auth,
|
|
|
|
|
verify_ssl=verify_ssl,
|
|
|
|
|
http503_attempts=http503_attempts,
|
|
|
|
|
http503_attempts_interval=http503_attempts_interval,
|
|
|
|
|
result_extra_allow=result_extra_allow,
|
2025-11-25 18:09:46 +03:00
|
|
|
wrap_request_exceptions=wrap_request_exceptions,
|
|
|
|
|
f_decorators=f_decorators,
|
2025-03-21 17:47:09 +03:00
|
|
|
)
|
2026-02-11 12:20:55 +03:00
|
|
|
|
|
|
|
|
self._dx_version, self._dx_build = self._get_dx_version_and_build()
|
|
|
|
|
|
2025-11-25 18:09:46 +03:00
|
|
|
self._check_dx_compatibility(ignore_api_compatibility)
|
2025-03-21 17:47:09 +03:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def api(self):
|
|
|
|
|
return API(config=self._config)
|
2025-11-25 18:09:46 +03:00
|
|
|
|
2026-02-11 12:20:55 +03:00
|
|
|
@property
|
|
|
|
|
def compatible_dx_minor_version(self) -> str:
|
|
|
|
|
return self._COMPATIBLE_DX_MINOR_VERSION
|
|
|
|
|
|
2025-11-25 18:09:46 +03:00
|
|
|
@property
|
|
|
|
|
def compatible_dx_build(self) -> int:
|
|
|
|
|
return self._COMPATIBLE_DX_BUILD
|
|
|
|
|
|
2026-02-11 12:20:55 +03:00
|
|
|
@property
|
|
|
|
|
def compatibility_with_newer_dx_builds(self) -> bool:
|
|
|
|
|
return self._COMPATIBILITY_WITH_NEWER_DX_BUILDS
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def dx_version(self) -> str:
|
|
|
|
|
return self._dx_version
|
|
|
|
|
|
2025-11-25 18:09:46 +03:00
|
|
|
@property
|
|
|
|
|
def dx_build(self) -> int:
|
|
|
|
|
return self._dx_build
|
|
|
|
|
|
2026-02-11 12:20:55 +03:00
|
|
|
def _get_dx_version_and_build(self) -> tuple[str, int]:
|
2025-11-25 18:09:46 +03:00
|
|
|
result = self.api.system.info.version()
|
2026-02-11 12:20:55 +03:00
|
|
|
|
|
|
|
|
decoded_data = json.loads(result.replace("'", '"'))
|
|
|
|
|
|
|
|
|
|
dx_version = decoded_data['version']
|
|
|
|
|
if not isinstance(dx_version, str):
|
|
|
|
|
raise TypeError(f'DX version must be an str, got {type(dx_version)}') # noqa: E501
|
|
|
|
|
|
|
|
|
|
dx_build = decoded_data['build']
|
2025-11-25 18:09:46 +03:00
|
|
|
if not isinstance(dx_build, int):
|
|
|
|
|
raise TypeError(f'DX build must be an int, got {type(dx_build)}')
|
2026-02-11 12:20:55 +03:00
|
|
|
|
|
|
|
|
return dx_version, dx_build
|
2025-11-25 18:09:46 +03:00
|
|
|
|
|
|
|
|
def _check_dx_compatibility(self, ignore_api_compatibility: bool):
|
2026-02-11 12:20:55 +03:00
|
|
|
if (
|
|
|
|
|
self.dx_version.rsplit('.', 1)[0]
|
|
|
|
|
!= self.compatible_dx_minor_version
|
|
|
|
|
):
|
|
|
|
|
message = (
|
|
|
|
|
f'Incompatible minor Dynamix version. '
|
|
|
|
|
f'Dynamix version: {self.dx_version}. '
|
|
|
|
|
f'Compatible minor version: '
|
|
|
|
|
f'{self.compatible_dx_minor_version}.'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if ignore_api_compatibility:
|
|
|
|
|
warn(message=message)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
raise IncompatibleAPIError(message=message)
|
|
|
|
|
|
|
|
|
|
build_is_compatible = (
|
|
|
|
|
(
|
|
|
|
|
self.compatibility_with_newer_dx_builds
|
|
|
|
|
and self.dx_build >= self.compatible_dx_build
|
|
|
|
|
)
|
|
|
|
|
or (
|
|
|
|
|
not self.compatibility_with_newer_dx_builds
|
|
|
|
|
and self.dx_build == self.compatible_dx_build
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not build_is_compatible:
|
|
|
|
|
compatible_build_str = f'{self.compatible_dx_build}'
|
|
|
|
|
if self.compatibility_with_newer_dx_builds:
|
|
|
|
|
compatible_build_str = f'>={compatible_build_str}'
|
|
|
|
|
|
2025-11-25 18:09:46 +03:00
|
|
|
message = (
|
|
|
|
|
f'Incompatible Dynamix build. '
|
|
|
|
|
f'Dynamix build: {self.dx_build}. '
|
2026-02-11 12:20:55 +03:00
|
|
|
f'Compatible build: {compatible_build_str}.'
|
2025-11-25 18:09:46 +03:00
|
|
|
)
|
2026-02-11 12:20:55 +03:00
|
|
|
|
2025-11-25 18:09:46 +03:00
|
|
|
if ignore_api_compatibility:
|
|
|
|
|
warn(message=message)
|
|
|
|
|
else:
|
|
|
|
|
raise IncompatibleAPIError(message=message)
|