Skip to content

Commit ed7b1ba

Browse files
committed
fix: ambignous slint.slint now slint.core via workable maturin configuration
1 parent 6b0dab9 commit ed7b1ba

File tree

16 files changed

+82
-81
lines changed

16 files changed

+82
-81
lines changed

api/python/slint/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,3 @@ css-color-parser2 = { workspace = true }
5454
pyo3-stub-gen = { version = "0.9.0", default-features = false }
5555
smol = { version = "2.0.0" }
5656
smol_str = { workspace = true }
57-
58-
[package.metadata.maturin]
59-
python-source = "slint"

api/python/slint/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Translator for PyGettextTranslator {
158158

159159
use pyo3::prelude::*;
160160

161-
#[pymodule]
161+
#[pymodule(name = "core")]
162162
fn slint(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
163163
i_slint_backend_selector::with_platform(|_b| {
164164
// Nothing to do, just make sure a backend was created

api/python/slint/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ dev = [
5151
"aiohttp>=3.12.15",
5252
]
5353

54+
[tool.maturin]
55+
module-name = "slint.core"
56+
python-packages = ["slint"]
57+
5458
[tool.uv]
5559
# Rebuild package when any rust files change
5660
cache-keys = [{ file = "pyproject.toml" }, { file = "Cargo.toml" }, { file = "**/*.rs" }]

api/python/slint/slint/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77

88
import os
99
import sys
10-
from . import slint as native
10+
from . import core
1111
import types
1212
import logging
1313
import copy
1414
import typing
1515
from typing import Any, Callable, TypeVar, overload
1616
import pathlib
1717
from .models import ListModel, Model
18-
from .slint import Image, Color, Brush, Timer, TimerMode
18+
from .core import Image, Color, Brush, Timer, TimerMode
1919
from .loop import SlintEventLoop
2020
from pathlib import Path
2121
from collections.abc import Coroutine
2222
import asyncio
2323
import gettext
2424

25-
Struct = native.PyStruct
25+
Struct = core.PyStruct
2626

2727

2828
class CompileError(Exception):
2929
message: str
3030
"""The error message that produced this compile error."""
3131

32-
diagnostics: list[native.PyDiagnostic]
32+
diagnostics: list[core.PyDiagnostic]
3333
"""A list of detailed diagnostics that were produced as part of the compilation."""
3434

35-
def __init__(self, message: str, diagnostics: list[native.PyDiagnostic]):
35+
def __init__(self, message: str, diagnostics: list[core.PyDiagnostic]):
3636
"""@private"""
3737
super().__init__(message)
3838
self.message = message
@@ -45,7 +45,7 @@ class Component:
4545
"""Component is the base class for all instances of Slint components. Use the member functions to show or hide the
4646
window, or spin the event loop."""
4747

48-
__instance__: native.ComponentInstance
48+
__instance__: core.ComponentInstance
4949

5050
def show(self) -> None:
5151
"""Shows the window on the screen."""
@@ -68,7 +68,7 @@ def _normalize_prop(name: str) -> str:
6868
return name.replace("-", "_")
6969

7070

71-
def _build_global_class(compdef: native.ComponentDefinition, global_name: str) -> Any:
71+
def _build_global_class(compdef: core.ComponentDefinition, global_name: str) -> Any:
7272
properties_and_callbacks = {}
7373

7474
for prop_name in compdef.global_properties(global_name).keys():
@@ -139,7 +139,7 @@ def call(*args: Any) -> Any:
139139

140140

141141
def _build_class(
142-
compdef: native.ComponentDefinition,
142+
compdef: core.ComponentDefinition,
143143
) -> typing.Callable[..., Component]:
144144
def cls_init(self: Component, **kwargs: Any) -> Any:
145145
self.__instance__ = compdef.create()
@@ -252,8 +252,8 @@ def global_getter(self: Component) -> Any:
252252
return type("SlintClassWrapper", (Component,), properties_and_callbacks)
253253

254254

255-
def _build_struct(name: str, struct_prototype: native.PyStruct) -> type:
256-
def new_struct(cls: Any, *args: Any, **kwargs: Any) -> native.PyStruct:
255+
def _build_struct(name: str, struct_prototype: core.PyStruct) -> type:
256+
def new_struct(cls: Any, *args: Any, **kwargs: Any) -> core.PyStruct:
257257
inst = copy.copy(struct_prototype)
258258

259259
for prop, val in kwargs.items():
@@ -291,7 +291,7 @@ def load_file(
291291
292292
"""
293293

294-
compiler = native.Compiler()
294+
compiler = core.Compiler()
295295

296296
if style is not None:
297297
compiler.style = style
@@ -308,11 +308,11 @@ def load_file(
308308
if diagnostics:
309309
if not quiet:
310310
for diag in diagnostics:
311-
if diag.level == native.DiagnosticLevel.Warning:
311+
if diag.level == core.DiagnosticLevel.Warning:
312312
logging.warning(diag)
313313

314314
errors = [
315-
diag for diag in diagnostics if diag.level == native.DiagnosticLevel.Error
315+
diag for diag in diagnostics if diag.level == core.DiagnosticLevel.Error
316316
]
317317
if errors:
318318
raise CompileError(f"Could not compile {path}", diagnostics)
@@ -492,7 +492,7 @@ def set_xdg_app_id(app_id: str) -> None:
492492
"""Sets the application id for use on Wayland or X11 with [xdg](https://specifications.freedesktop.org/desktop-entry-spec/latest/)
493493
compliant window managers. This id must be set before the window is shown; it only applies to Wayland or X11."""
494494

495-
native.set_xdg_app_id(app_id)
495+
core.set_xdg_app_id(app_id)
496496

497497

498498
quit_event = asyncio.Event()
@@ -573,7 +573,7 @@ def init_translations(translations: typing.Optional[gettext.GNUTranslations]) ->
573573
pass
574574
```
575575
"""
576-
native.init_translations(translations)
576+
core.init_translations(translations)
577577

578578

579579
__all__ = [

api/python/slint/slint/codegen/generator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Iterable
99

10-
from .. import slint as native
10+
from .. import core
1111
from .. import _normalize_prop
1212

1313
from .emitters import write_python_module, write_stub_module
@@ -25,7 +25,7 @@
2525
)
2626

2727
if TYPE_CHECKING:
28-
from slint.slint import CallbackInfo, FunctionInfo, PyDiagnostic
28+
from slint.core import CallbackInfo, FunctionInfo, PyDiagnostic
2929

3030

3131
def generate_project(
@@ -42,7 +42,7 @@ def generate_project(
4242
if output_dir is not None:
4343
output_dir.mkdir(parents=True, exist_ok=True)
4444

45-
compiler = native.Compiler()
45+
compiler = core.Compiler()
4646
if config.style:
4747
compiler.style = config.style
4848
if config.include_paths:
@@ -102,14 +102,14 @@ def _discover_slint_files(inputs: Iterable[Path]) -> Iterable[tuple[Path, Path]]
102102

103103

104104
def _compile_slint(
105-
compiler: native.Compiler,
105+
compiler: core.Compiler,
106106
source_path: Path,
107107
config: GenerationConfig,
108-
) -> native.CompilationResult | None:
108+
) -> core.CompilationResult | None:
109109
result = compiler.build_from_path(source_path)
110110

111111
diagnostics = result.diagnostics
112-
diagnostic_error = getattr(native, "DiagnosticLevel", None)
112+
diagnostic_error = getattr(core, "DiagnosticLevel", None)
113113
error_enum = getattr(diagnostic_error, "Error", None)
114114

115115
def is_error(diag: PyDiagnostic) -> bool:
@@ -133,7 +133,7 @@ def is_error(diag: PyDiagnostic) -> bool:
133133
return result
134134

135135

136-
def _collect_metadata(result: native.CompilationResult) -> ModuleArtifacts:
136+
def _collect_metadata(result: core.CompilationResult) -> ModuleArtifacts:
137137
components: list[ComponentMeta] = []
138138
for name in result.component_names:
139139
comp = result.component(name)
@@ -275,9 +275,9 @@ def _python_value_hint(value: object) -> str:
275275
return "float"
276276
if isinstance(value, str):
277277
return "str"
278-
if isinstance(value, native.Image):
278+
if isinstance(value, core.Image):
279279
return "slint.Image"
280-
if isinstance(value, native.Brush):
280+
if isinstance(value, core.Brush):
281281
return "slint.Brush"
282282
return "Any"
283283

File renamed without changes.

api/python/slint/slint/loop.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright © SixtyFPS GmbH <[email protected]>
22
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
from . import slint as native
4+
from . import core
55
import asyncio.selector_events
66
import asyncio
77
import asyncio.events
@@ -44,7 +44,7 @@ class _SlintSelector(selectors.BaseSelector):
4444
def __init__(self) -> None:
4545
self.fd_to_selector_key: typing.Dict[typing.Any, selectors.SelectorKey] = {}
4646
self.mapping = _SlintSelectorMapping(self)
47-
self.adapters: typing.Dict[int, native.AsyncAdapter] = {}
47+
self.adapters: typing.Dict[int, core.AsyncAdapter] = {}
4848

4949
def register(
5050
self, fileobj: typing.Any, events: typing.Any, data: typing.Any = None
@@ -53,7 +53,7 @@ def register(
5353
key = selectors.SelectorKey(fileobj, fd, events, data)
5454
self.fd_to_selector_key[fd] = key
5555

56-
adapter = native.AsyncAdapter(fd)
56+
adapter = core.AsyncAdapter(fd)
5757
self.adapters[fd] = adapter
5858

5959
if events & selectors.EVENT_READ:
@@ -114,22 +114,22 @@ def write_notify(self, fd: int) -> None:
114114
class SlintEventLoop(asyncio.SelectorEventLoop):
115115
def __init__(self) -> None:
116116
self._is_running = False
117-
self._timers: typing.Set[native.Timer] = set()
117+
self._timers: typing.Set[core.Timer] = set()
118118
self.stop_run_forever_event = asyncio.Event()
119119
self._soon_tasks: typing.List[asyncio.TimerHandle] = []
120120
super().__init__(_SlintSelector())
121121

122122
def run_forever(self) -> None:
123123
async def loop_stopper(event: asyncio.Event) -> None:
124124
await event.wait()
125-
native.quit_event_loop()
125+
core.quit_event_loop()
126126

127127
asyncio.events._set_running_loop(self)
128128
self._is_running = True
129129
try:
130130
self.stop_run_forever_event = asyncio.Event()
131131
self.create_task(loop_stopper(self.stop_run_forever_event))
132-
native.run_event_loop()
132+
core.run_event_loop()
133133
finally:
134134
self._is_running = False
135135
asyncio.events._set_running_loop(None)
@@ -178,7 +178,7 @@ def is_closed(self) -> bool:
178178
return False
179179

180180
def call_later(self, delay, callback, *args, context=None) -> asyncio.TimerHandle: # type: ignore
181-
timer = native.Timer()
181+
timer = core.Timer()
182182

183183
handle = asyncio.TimerHandle(
184184
when=self.time() + delay,
@@ -196,7 +196,7 @@ def timer_done_cb() -> None:
196196
handle._run()
197197

198198
timer.start(
199-
native.TimerMode.SingleShot,
199+
core.TimerMode.SingleShot,
200200
interval=datetime.timedelta(seconds=delay),
201201
callback=timer_done_cb,
202202
)
@@ -237,7 +237,7 @@ def run_handle_cb() -> None:
237237
if not handle._cancelled:
238238
handle._run()
239239

240-
native.invoke_from_event_loop(run_handle_cb)
240+
core.invoke_from_event_loop(run_handle_cb)
241241
return handle
242242

243243
def _write_to_self(self) -> None:

api/python/slint/slint/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright © SixtyFPS GmbH <[email protected]>
22
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
from . import slint as native
4+
from . import core
55
from collections.abc import Iterable
66
from abc import abstractmethod
77
import typing
88
from typing import Any, cast, Iterator
99

1010

11-
class Model[T](native.PyModelBase, Iterable[T]):
11+
class Model[T](core.PyModelBase, Iterable[T]):
1212
"""Model is the base class for feeding dynamic data into Slint views.
1313
1414
Subclass Model to implement your own models, or use `ListModel` to wrap a list.

api/python/slint/tests/test_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

44
import slint
5-
from slint import slint as native
5+
from slint import core
66
import asyncio
77
import typing
88
import aiohttp
@@ -166,11 +166,11 @@ async def run_server_and_client(exception_check: typing.List[Exception]) -> None
166166

167167
def test_loop_close_while_main_future_runs() -> None:
168168
def q() -> None:
169-
native.quit_event_loop()
169+
core.quit_event_loop()
170170

171171
async def never_quit() -> None:
172172
loop = asyncio.get_running_loop()
173-
# Call native.quit_event_loop() directly as if the user closed the last window. We should gracefully
173+
# Call core.quit_event_loop() directly as if the user closed the last window. We should gracefully
174174
# handle that the future that this function represents isn't terminated.
175175
loop.call_later(0.1, q)
176176
while True:

api/python/slint/tests/test_compiler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Copyright © SixtyFPS GmbH <[email protected]>
22
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
from slint import slint as native
5-
from slint.slint import ValueType
4+
from slint import core
5+
from slint.core import ValueType
66
from pathlib import Path
77

88

99
def test_basic_compiler() -> None:
10-
compiler = native.Compiler()
10+
compiler = core.Compiler()
1111

1212
assert compiler.include_paths == []
1313
compiler.include_paths = [Path("testing")]
@@ -79,13 +79,13 @@ def test_basic_compiler() -> None:
7979

8080

8181
def test_compiler_build_from_path() -> None:
82-
compiler = native.Compiler()
82+
compiler = core.Compiler()
8383

8484
result = compiler.build_from_path(Path("Nonexistent.slint"))
8585
assert len(result.component_names) == 0
8686

8787
diags = result.diagnostics
8888
assert len(diags) == 1
8989

90-
assert diags[0].level == native.DiagnosticLevel.Error
90+
assert diags[0].level == core.DiagnosticLevel.Error
9191
assert diags[0].message.startswith("Could not load Nonexistent.slint:")

0 commit comments

Comments
 (0)