Source code for syside

 1"""
 2Syside Automator for Python.
 3
 4A library for parsing, validating, and analysing SysMLv2 models, optimised for textual notation.
 5"""
 6
 7from typing import TYPE_CHECKING
 8
 9from ._license import is_core_license_refusal as _is_core_license_refusal
10
11_LICENSE_IMPORT_ERROR: ImportError | None = None
12"""Core's license refusal, recorded so the CLI can report it."""
13
14try:
15    from _syside import *  # noqa: F403
16
17    import _syside
18except ImportError as error:
19    # Only a license refusal is recorded; a broken installation propagates.
20    if not _is_core_license_refusal(error):
21        raise
22    _LICENSE_IMPORT_ERROR = error
23else:
24    __version__ = _syside.__version__
25
26    del _syside
27
28# Hidden from type checkers: a visible module `__getattr__` silences every
29# `attr-defined` error on `syside` for users.
30if not TYPE_CHECKING:
31
32    def __getattr__(name: str) -> object:
33        """Raise the recorded license failure on first use of the namespace."""
34        # Dunders are not exempted, or `from syside import *` would silently
35        # bind nothing. Submodules are, so `from syside import _reqif` works.
36        if _LICENSE_IMPORT_ERROR is not None:
37            # Imported here: without `__all__`, a module-scope import would
38            # leak into `from syside import *`.
39            import importlib.util
40
41            if importlib.util.find_spec(f"{__name__}.{name}") is not None:
42                return importlib.import_module(f"{__name__}.{name}")
43            # Clear the traceback: the same object is raised repeatedly.
44            raise _LICENSE_IMPORT_ERROR.with_traceback(None)
45        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
46
47
48# Keep it out of `from syside import *`.
49del TYPE_CHECKING