|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import asyncio |
| 4 | +import importlib |
4 | 5 | import inspect |
5 | 6 | import io |
6 | 7 | import os |
|
47 | 48 | from rich.segment import Segment, Segments |
48 | 49 | from rich.traceback import Traceback |
49 | 50 |
|
50 | | -from . import Logger, LogGroup, LogVerbosity, actions, events, log, messages |
| 51 | +from . import Logger, LogGroup, LogVerbosity, actions, constants, events, log, messages |
51 | 52 | from ._animator import DEFAULT_EASING, Animatable, Animator, EasingFunction |
52 | 53 | from ._ansi_sequences import SYNC_END, SYNC_START |
53 | 54 | from ._asyncio import create_task |
@@ -590,7 +591,24 @@ def get_driver_class(self) -> Type[Driver]: |
590 | 591 | Returns: |
591 | 592 | A Driver class which manages input and display. |
592 | 593 | """ |
| 594 | + |
593 | 595 | driver_class: Type[Driver] |
| 596 | + |
| 597 | + driver_import = constants.DRIVER |
| 598 | + if driver_import is not None: |
| 599 | + # The driver class is set from the environment |
| 600 | + # Syntax should be foo.bar.baz:MyDriver |
| 601 | + module_import, colon, driver_symbol = driver_import.partition(":") |
| 602 | + driver_module = importlib.import_module(module_import) |
| 603 | + driver_class = getattr(driver_module, driver_symbol) |
| 604 | + if not inspect.isclass(driver_class) or not issubclass( |
| 605 | + driver_class, Driver |
| 606 | + ): |
| 607 | + raise RuntimeError( |
| 608 | + f"Unable to import {driver_import!r}; {driver_class!r} is not a Driver class " |
| 609 | + ) |
| 610 | + return driver_class |
| 611 | + |
594 | 612 | if WINDOWS: |
595 | 613 | from .drivers.windows_driver import WindowsDriver |
596 | 614 |
|
|
0 commit comments