Skip to content

Commit 095cbbb

Browse files
committed
Migrate most resource logic to our package.
1 parent 48f8b9e commit 095cbbb

4 files changed

Lines changed: 453 additions & 4 deletions

File tree

breezestylesheets/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def decode(self, s: 'str') -> 'JSONValue': # type: ignore # noqa
226226
return typing.cast('JSONValue', super().decode('\n'.join(lines)))
227227

228228

229-
def load(path: 'os.PathLike') -> 'Config':
229+
def load(path: 'str | os.PathLike[str]') -> 'Config':
230230
'''
231231
Load the stylesheet configuration settings from file.
232232
@@ -402,7 +402,7 @@ def _transform_nested(v: 'JSONObject') -> 'dict[str, str]':
402402
@contextlib.contextmanager
403403
def _parse_block(
404404
data: 'str | bytes | bytearray | None' = None,
405-
path: 'os.PathLike | None' = None,
405+
path: 'str | os.PathLike[str] | None' = None,
406406
) -> 'typing.Iterator[None]':
407407
'''A helper to parse the config data within a context block.'''
408408
try:

breezestylesheets/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
constants
3+
4+
Constant values and aliases for library definitions.
5+
'''
6+
7+
import typing
8+
9+
Compression: 'typing.TypeAlias' = 'typing.Literal["zlib", "lzma", "gzip", "default"]'
10+
'''The valid compression schemes for a QT resource.'''
11+
12+
Framework: 'typing.TypeAlias' = 'typing.Literal["pyqt5", "pyqt6", "pyside2", "pyside6"]'
13+
'''The valid Qt frameworks (and Python wrappers) used for the stylesheets.'''

breezestylesheets/exception.py

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import typing
99

10+
from .constants import Framework
11+
1012
if typing.TYPE_CHECKING:
1113
import os
1214

@@ -36,7 +38,7 @@ class ConfigParseError(ConfigError):
3638
data: 'str | bytes | bytearray'
3739
'''The input data provided to the parser.'''
3840

39-
path: 'os.PathLike | None'
41+
path: 'str | os.PathLike[str] | None'
4042
'''The path to the input file that caused the error, if parsing from file.'''
4143

4244
inner: 'Exception | None'
@@ -46,7 +48,7 @@ def __init__(
4648
self,
4749
message: 'str',
4850
data: 'str | bytes | bytearray',
49-
path: 'os.PathLike | None' = None,
51+
path: 'str | os.PathLike[str] | None' = None,
5052
inner: 'Exception | None' = None,
5153
) -> None:
5254
'''
@@ -62,3 +64,66 @@ def __init__(
6264
self.data = data
6365
self.path = path
6466
self.inner = inner
67+
68+
69+
class InvalidFrameworkError(BreezeStyleSheetError):
70+
'''An exception that occurs when the provided framework is unknown.'''
71+
72+
# NOTE: This is unknown so it's not a valid `Framework` type.
73+
framework: 'str'
74+
'''The name of the provided Qt framework.'''
75+
76+
def __init__(self, framework: 'str') -> None:
77+
super().__init__(f'Got an unsupported Qt framework of "{framework}".')
78+
self.framework = framework
79+
80+
81+
class ResourceError(BreezeStyleSheetError):
82+
'''The base exception for all Qt resource errors.'''
83+
84+
85+
class RccNotFoundError(ResourceError):
86+
'''An exception that occurs when the Qt resource compiler cannot be found.'''
87+
88+
rcc: 'str | os.PathLike[str]'
89+
'''The name or path to the Qt resource compiler.'''
90+
91+
framework: 'Framework'
92+
'''The name of the provided Qt framework.'''
93+
94+
def __init__(self, rcc: 'str | os.PathLike[str]', framework: 'Framework') -> None:
95+
super().__init__(f'Unable to find a suitable "{rcc}" executable for framework "{framework}".')
96+
self.rcc = rcc
97+
self.framework = framework
98+
99+
100+
class ResourceCompileError(ResourceError):
101+
'''An exception that occurs when there is an external error compiling the Qt resources.'''
102+
103+
rcc: 'str | os.PathLike[str]'
104+
'''The name or path to the Qt resource compiler.'''
105+
106+
qrc: 'str | os.PathLike[str]'
107+
'''The path to the input QRC file.'''
108+
109+
framework: 'Framework'
110+
'''The name of the provided Qt framework.'''
111+
112+
inner: 'Exception'
113+
'''The exception that caused the compilation error.'''
114+
115+
def __init__(
116+
self,
117+
rcc: 'str | os.PathLike[str]',
118+
qrc: 'str | os.PathLike[str]',
119+
framework: 'Framework',
120+
inner: 'Exception',
121+
) -> None:
122+
super().__init__(
123+
f'Unable to find a compile the QRC file "{qrc}" using resource'
124+
f' compiler "{rcc}" for framework "{framework}".'
125+
)
126+
self.rcc = rcc
127+
self.qrc = qrc
128+
self.framework = framework
129+
self.inner = inner

0 commit comments

Comments
 (0)