|
29 | 29 | from enum import Enum, StrEnum, auto |
30 | 30 | from functools import partial |
31 | 31 | from itertools import chain, repeat |
| 32 | +from importlib.resources import as_file, files, as_file |
32 | 33 | from pathlib import Path |
33 | 34 | from textwrap import dedent, indent |
34 | 35 | from typing import ( |
|
87 | 88 |
|
88 | 89 | from . import __version__ |
89 | 90 |
|
| 91 | +CSS_RESOURCE = files(__name__).joinpath("dom.tcss") |
| 92 | + |
| 93 | +with as_file(CSS_RESOURCE) as f: |
| 94 | + _CSS_RESOURCE_PATH = f |
| 95 | + |
| 96 | +if _CSS_RESOURCE_PATH.exists(): |
| 97 | + # package resources are persisted on the file system |
| 98 | + CSS_RESOURCE_PATH = _CSS_RESOURCE_PATH |
| 99 | +else: |
| 100 | + # this means that the resource is dynamically extracted |
| 101 | + # and not read as-is from the unpacked wheel. |
| 102 | + # So extract it again, copy its contents |
| 103 | + _tmp_file = tempfile.NamedTemporaryFile( |
| 104 | + "w", prefix="isd_", suffix=".tcss", delete=False |
| 105 | + ) |
| 106 | + _tmp_file.write(CSS_RESOURCE.read_text()) |
| 107 | + CSS_RESOURCE_PATH = Path(_tmp_file.name) |
| 108 | + del _tmp_file |
| 109 | + |
90 | 110 | ToggleButton.BUTTON_LEFT = "" |
91 | 111 | ToggleButton.BUTTON_INNER = "▐" # "▌" # "█" |
92 | 112 | ToggleButton.BUTTON_RIGHT = "" |
@@ -1552,9 +1572,9 @@ def update_keybindings(self) -> None: |
1552 | 1572 | "toggle_mode", |
1553 | 1573 | ] |
1554 | 1574 | model_fields = MainKeybindings.model_fields |
1555 | | - assert all( |
1556 | | - [show_field in model_fields for show_field in show_fields] |
1557 | | - ), "Forgot to update show_field" |
| 1575 | + assert all([show_field in model_fields for show_field in show_fields]), ( |
| 1576 | + "Forgot to update show_field" |
| 1577 | + ) |
1558 | 1578 | for action, field in model_fields.items(): |
1559 | 1579 | # name of keybinding == action name and |
1560 | 1580 | # description is used for binding description |
@@ -2172,7 +2192,8 @@ class InteractiveSystemd(App, inherit_bindings=False): |
2172 | 2192 | """ |
2173 | 2193 |
|
2174 | 2194 | TITLE = "isd" |
2175 | | - CSS_PATH = "dom.tcss" |
| 2195 | + # CSS_PATH = "dom.tcss" |
| 2196 | + CSS_PATH = CSS_RESOURCE_PATH |
2176 | 2197 | COMMAND_PALETTE_BINDING = ensure_reserved("ctrl+p") |
2177 | 2198 | NOTIFICATION_TIMEOUT = 5 |
2178 | 2199 | # If the modal is dismissed, this App would be focused by default |
|
0 commit comments