amulet-core 2.0a8__cp311-cp311-win_amd64.whl → 2.0.1a2.post250529084738__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of amulet-core might be problematic. Click here for more details.

Files changed (271) hide show
  1. amulet/core/__init__.py +36 -0
  2. amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
  3. amulet/core/_amulet_core.cp311-win_amd64.pyd +0 -0
  4. amulet/core/_amulet_core.pyi +7 -0
  5. amulet/{_version.py → core/_version.py} +3 -3
  6. amulet/core/amulet_core.dll +0 -0
  7. amulet/core/amulet_core.lib +0 -0
  8. amulet/core/amulet_coreConfig.cmake +18 -0
  9. amulet/{biome.pyi → core/biome/__init__.pyi} +3 -3
  10. amulet/core/biome/biome.hpp +53 -0
  11. amulet/{block.pyi → core/block/__init__.pyi} +25 -26
  12. amulet/core/block/block.hpp +156 -0
  13. amulet/{block_entity.pyi → core/block_entity/__init__.pyi} +7 -7
  14. amulet/core/block_entity/block_entity.hpp +84 -0
  15. amulet/{errors.py → core/chunk/__init__.pyi} +37 -33
  16. amulet/core/chunk/chunk.hpp +126 -0
  17. amulet/core/chunk/component/__init__.pyi +18 -0
  18. amulet/core/chunk/component/biome_3d_component.hpp +96 -0
  19. amulet/core/chunk/component/block_component.hpp +101 -0
  20. amulet/core/chunk/component/block_component.pyi +28 -0
  21. amulet/core/chunk/component/block_entity_component.hpp +119 -0
  22. amulet/core/chunk/component/section_array_map.hpp +129 -0
  23. amulet/{chunk_components.pyi → core/chunk/component/section_array_map.pyi} +4 -24
  24. amulet/core/dll.hpp +21 -0
  25. amulet/core/entity/__init__.pyi +105 -0
  26. amulet/core/entity/entity.hpp +100 -0
  27. amulet/{palette → core/palette}/__init__.pyi +2 -2
  28. amulet/core/palette/biome_palette.hpp +65 -0
  29. amulet/{palette → core/palette}/biome_palette.pyi +8 -8
  30. amulet/core/palette/block_palette.hpp +71 -0
  31. amulet/{palette → core/palette}/block_palette.pyi +12 -10
  32. amulet/core/selection/__init__.pyi +8 -0
  33. amulet/core/selection/box.hpp +86 -0
  34. amulet/core/selection/box.pyi +215 -0
  35. amulet/core/selection/group.hpp +80 -0
  36. amulet/core/selection/group.pyi +213 -0
  37. amulet/{version.pyi → core/version/__init__.pyi} +58 -10
  38. amulet/core/version/version.hpp +204 -0
  39. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/METADATA +25 -20
  40. amulet_core-2.0.1a2.post250529084738.dist-info/RECORD +45 -0
  41. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/WHEEL +1 -1
  42. amulet_core-2.0.1a2.post250529084738.dist-info/entry_points.txt +2 -0
  43. amulet/__init__.cp311-win_amd64.pyd +0 -0
  44. amulet/__init__.py.cpp +0 -45
  45. amulet/__init__.pyi +0 -30
  46. amulet/__pyinstaller/hook-amulet.py +0 -4
  47. amulet/_init.py +0 -26
  48. amulet/biome.cpp +0 -36
  49. amulet/biome.hpp +0 -43
  50. amulet/biome.py.cpp +0 -122
  51. amulet/block.cpp +0 -435
  52. amulet/block.hpp +0 -119
  53. amulet/block.py.cpp +0 -377
  54. amulet/block_entity.cpp +0 -12
  55. amulet/block_entity.hpp +0 -56
  56. amulet/block_entity.py.cpp +0 -115
  57. amulet/chunk.cpp +0 -16
  58. amulet/chunk.hpp +0 -100
  59. amulet/chunk.py.cpp +0 -80
  60. amulet/chunk.pyi +0 -28
  61. amulet/chunk_components/biome_3d_component.cpp +0 -5
  62. amulet/chunk_components/biome_3d_component.hpp +0 -79
  63. amulet/chunk_components/block_component.cpp +0 -41
  64. amulet/chunk_components/block_component.hpp +0 -88
  65. amulet/chunk_components/block_entity_component.cpp +0 -5
  66. amulet/chunk_components/block_entity_component.hpp +0 -147
  67. amulet/chunk_components/section_array_map.cpp +0 -129
  68. amulet/chunk_components/section_array_map.hpp +0 -147
  69. amulet/collections/eq.py.hpp +0 -37
  70. amulet/collections/hash.py.hpp +0 -27
  71. amulet/collections/holder.py.hpp +0 -37
  72. amulet/collections/iterator.py.hpp +0 -80
  73. amulet/collections/mapping.py.hpp +0 -199
  74. amulet/collections/mutable_mapping.py.hpp +0 -226
  75. amulet/collections/sequence.py.hpp +0 -163
  76. amulet/collections.pyi +0 -40
  77. amulet/data_types.py +0 -29
  78. amulet/entity.py +0 -182
  79. amulet/game/__init__.py +0 -7
  80. amulet/game/_game.py +0 -152
  81. amulet/game/_universal/__init__.py +0 -1
  82. amulet/game/_universal/_biome.py +0 -17
  83. amulet/game/_universal/_block.py +0 -47
  84. amulet/game/_universal/_version.py +0 -68
  85. amulet/game/abc/__init__.py +0 -22
  86. amulet/game/abc/_block_specification.py +0 -150
  87. amulet/game/abc/biome.py +0 -213
  88. amulet/game/abc/block.py +0 -331
  89. amulet/game/abc/game_version_container.py +0 -25
  90. amulet/game/abc/json_interface.py +0 -27
  91. amulet/game/abc/version.py +0 -44
  92. amulet/game/bedrock/__init__.py +0 -1
  93. amulet/game/bedrock/_biome.py +0 -35
  94. amulet/game/bedrock/_block.py +0 -42
  95. amulet/game/bedrock/_version.py +0 -165
  96. amulet/game/java/__init__.py +0 -2
  97. amulet/game/java/_biome.py +0 -35
  98. amulet/game/java/_block.py +0 -60
  99. amulet/game/java/_version.py +0 -176
  100. amulet/game/translate/__init__.py +0 -12
  101. amulet/game/translate/_functions/__init__.py +0 -15
  102. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  103. amulet/game/translate/_functions/_code_functions/_text.py +0 -553
  104. amulet/game/translate/_functions/_code_functions/banner_pattern.py +0 -67
  105. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +0 -152
  106. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +0 -88
  107. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +0 -152
  108. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +0 -16
  109. amulet/game/translate/_functions/_code_functions/custom_name.py +0 -146
  110. amulet/game/translate/_functions/_frozen.py +0 -66
  111. amulet/game/translate/_functions/_state.py +0 -54
  112. amulet/game/translate/_functions/_typing.py +0 -98
  113. amulet/game/translate/_functions/abc.py +0 -123
  114. amulet/game/translate/_functions/carry_nbt.py +0 -160
  115. amulet/game/translate/_functions/carry_properties.py +0 -80
  116. amulet/game/translate/_functions/code.py +0 -143
  117. amulet/game/translate/_functions/map_block_name.py +0 -66
  118. amulet/game/translate/_functions/map_nbt.py +0 -111
  119. amulet/game/translate/_functions/map_properties.py +0 -93
  120. amulet/game/translate/_functions/multiblock.py +0 -112
  121. amulet/game/translate/_functions/new_block.py +0 -42
  122. amulet/game/translate/_functions/new_entity.py +0 -43
  123. amulet/game/translate/_functions/new_nbt.py +0 -206
  124. amulet/game/translate/_functions/new_properties.py +0 -64
  125. amulet/game/translate/_functions/sequence.py +0 -51
  126. amulet/game/translate/_functions/walk_input_nbt.py +0 -331
  127. amulet/game/translate/_translator.py +0 -433
  128. amulet/img/__init__.py +0 -10
  129. amulet/img/missing_no.png +0 -0
  130. amulet/img/missing_pack.png +0 -0
  131. amulet/img/missing_world.png +0 -0
  132. amulet/io/binary_reader.hpp +0 -45
  133. amulet/io/binary_writer.hpp +0 -30
  134. amulet/item.py +0 -75
  135. amulet/level/__init__.pyi +0 -23
  136. amulet/level/_load.py +0 -100
  137. amulet/level/abc/__init__.py +0 -12
  138. amulet/level/abc/_chunk_handle.py +0 -358
  139. amulet/level/abc/_dimension.py +0 -86
  140. amulet/level/abc/_history/__init__.py +0 -1
  141. amulet/level/abc/_history/_cache.py +0 -224
  142. amulet/level/abc/_history/_history_manager.py +0 -291
  143. amulet/level/abc/_level/__init__.py +0 -5
  144. amulet/level/abc/_level/_compactable_level.py +0 -10
  145. amulet/level/abc/_level/_creatable_level.py +0 -28
  146. amulet/level/abc/_level/_disk_level.py +0 -17
  147. amulet/level/abc/_level/_level.py +0 -449
  148. amulet/level/abc/_level/_loadable_level.py +0 -42
  149. amulet/level/abc/_player_storage.py +0 -7
  150. amulet/level/abc/_raw_level.py +0 -187
  151. amulet/level/abc/_registry.py +0 -40
  152. amulet/level/java/__init__.pyi +0 -16
  153. amulet/level/java/_chunk_handle.py +0 -17
  154. amulet/level/java/_dimension.py +0 -20
  155. amulet/level/java/_level.py +0 -184
  156. amulet/level/java/_raw/__init__.pyi +0 -15
  157. amulet/level/java/_raw/_chunk.pyi +0 -23
  158. amulet/level/java/_raw/_constant.py +0 -9
  159. amulet/level/java/_raw/_data_pack/__init__.py +0 -2
  160. amulet/level/java/_raw/_data_pack/data_pack.py +0 -241
  161. amulet/level/java/_raw/_data_pack/data_pack_manager.py +0 -77
  162. amulet/level/java/_raw/_dimension.py +0 -86
  163. amulet/level/java/_raw/_level.py +0 -507
  164. amulet/level/java/_raw/_typing.py +0 -3
  165. amulet/level/java/_raw/java_chunk_decode.cpp +0 -531
  166. amulet/level/java/_raw/java_chunk_decode.hpp +0 -23
  167. amulet/level/java/_raw/java_chunk_encode.cpp +0 -25
  168. amulet/level/java/_raw/java_chunk_encode.hpp +0 -23
  169. amulet/level/java/anvil/__init__.py +0 -2
  170. amulet/level/java/anvil/_dimension.py +0 -170
  171. amulet/level/java/anvil/_region.py +0 -421
  172. amulet/level/java/anvil/_sector_manager.py +0 -223
  173. amulet/level/java/chunk.pyi +0 -81
  174. amulet/level/java/chunk_/_chunk.py +0 -260
  175. amulet/level/java/chunk_/components/inhabited_time.py +0 -12
  176. amulet/level/java/chunk_/components/last_update.py +0 -12
  177. amulet/level/java/chunk_/components/legacy_version.py +0 -12
  178. amulet/level/java/chunk_/components/light_populated.py +0 -12
  179. amulet/level/java/chunk_/components/named_height_2d.py +0 -37
  180. amulet/level/java/chunk_/components/status.py +0 -11
  181. amulet/level/java/chunk_/components/terrain_populated.py +0 -12
  182. amulet/level/java/chunk_components/data_version_component.cpp +0 -32
  183. amulet/level/java/chunk_components/data_version_component.hpp +0 -31
  184. amulet/level/java/chunk_components/java_raw_chunk_component.cpp +0 -56
  185. amulet/level/java/chunk_components/java_raw_chunk_component.hpp +0 -45
  186. amulet/level/java/chunk_components.pyi +0 -22
  187. amulet/level/java/java_chunk.cpp +0 -170
  188. amulet/level/java/java_chunk.hpp +0 -141
  189. amulet/level/java/long_array.hpp +0 -175
  190. amulet/level/java/long_array.pyi +0 -39
  191. amulet/level/temporary_level/__init__.py +0 -1
  192. amulet/level/temporary_level/_level.py +0 -16
  193. amulet/mesh/__init__.py +0 -0
  194. amulet/mesh/block/__init__.pyi +0 -301
  195. amulet/mesh/block/_cube.py +0 -198
  196. amulet/mesh/block/_missing_block.py +0 -20
  197. amulet/mesh/block/block_mesh.cpp +0 -107
  198. amulet/mesh/block/block_mesh.hpp +0 -207
  199. amulet/mesh/util.py +0 -17
  200. amulet/palette/biome_palette.hpp +0 -85
  201. amulet/palette/block_palette.cpp +0 -32
  202. amulet/palette/block_palette.hpp +0 -93
  203. amulet/player.py +0 -62
  204. amulet/pybind11/collections.hpp +0 -118
  205. amulet/pybind11/numpy.hpp +0 -26
  206. amulet/pybind11/py_module.hpp +0 -34
  207. amulet/pybind11/type_hints.hpp +0 -51
  208. amulet/pybind11/types.hpp +0 -25
  209. amulet/pybind11/typing.hpp +0 -7
  210. amulet/resource_pack/__init__.py +0 -63
  211. amulet/resource_pack/abc/__init__.py +0 -2
  212. amulet/resource_pack/abc/resource_pack.py +0 -38
  213. amulet/resource_pack/abc/resource_pack_manager.py +0 -85
  214. amulet/resource_pack/java/__init__.py +0 -2
  215. amulet/resource_pack/java/download_resources.py +0 -212
  216. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  217. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  218. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  219. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  220. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  221. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  222. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  223. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  224. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  225. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  226. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  227. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  228. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  229. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  230. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  231. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  232. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  233. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  234. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  235. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  236. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  237. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  238. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  239. amulet/resource_pack/java/resource_pack.py +0 -44
  240. amulet/resource_pack/java/resource_pack_manager.py +0 -563
  241. amulet/resource_pack/unknown_resource_pack.py +0 -10
  242. amulet/selection/__init__.py +0 -2
  243. amulet/selection/abstract_selection.py +0 -342
  244. amulet/selection/box.py +0 -852
  245. amulet/selection/group.py +0 -481
  246. amulet/utils/__init__.pyi +0 -23
  247. amulet/utils/call_spec/__init__.py +0 -24
  248. amulet/utils/call_spec/_call_spec.py +0 -257
  249. amulet/utils/cast.py +0 -10
  250. amulet/utils/comment_json.py +0 -188
  251. amulet/utils/format_utils.py +0 -41
  252. amulet/utils/generator.py +0 -18
  253. amulet/utils/matrix.py +0 -243
  254. amulet/utils/numpy.hpp +0 -36
  255. amulet/utils/numpy.pyi +0 -11
  256. amulet/utils/numpy_helpers.py +0 -19
  257. amulet/utils/shareable_lock.py +0 -335
  258. amulet/utils/signal/__init__.py +0 -10
  259. amulet/utils/signal/_signal.py +0 -228
  260. amulet/utils/task_manager.py +0 -235
  261. amulet/utils/typed_property.py +0 -111
  262. amulet/utils/weakref.py +0 -70
  263. amulet/utils/world_utils.py +0 -102
  264. amulet/version.cpp +0 -136
  265. amulet/version.hpp +0 -142
  266. amulet/version.py.cpp +0 -281
  267. amulet_core-2.0a8.dist-info/RECORD +0 -241
  268. amulet_core-2.0a8.dist-info/entry_points.txt +0 -2
  269. /amulet/{__pyinstaller → core/__pyinstaller}/__init__.py +0 -0
  270. /amulet/{py.typed → core/py.typed} +0 -0
  271. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a2.post250529084738.dist-info}/top_level.txt +0 -0
@@ -1,228 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import logging
4
- from typing import (
5
- Callable,
6
- Any,
7
- overload,
8
- Protocol,
9
- TYPE_CHECKING,
10
- TypeVarTuple,
11
- Generic,
12
- )
13
- from collections.abc import Sequence
14
- from weakref import WeakMethod
15
- from inspect import ismethod
16
-
17
-
18
- if TYPE_CHECKING:
19
- import PySide6.QtCore # type: ignore # noqa
20
-
21
-
22
- CallArgs = TypeVarTuple("CallArgs")
23
-
24
-
25
- class SignalInstance(Protocol[*CallArgs]):
26
- def connect(
27
- self,
28
- slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None,
29
- type: PySide6.QtCore.Qt.ConnectionType | None = ...,
30
- ) -> None: ...
31
-
32
- def disconnect(
33
- self,
34
- slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None = None,
35
- ) -> None: ...
36
-
37
- def emit(self, *args: *CallArgs) -> None: ...
38
-
39
-
40
- _signal_instance_constructor: SignalInstanceConstructor | None = None
41
-
42
-
43
- # TODO: https://github.com/python/typing/issues/1216
44
-
45
-
46
- def create_signal_instance(
47
- *types: type, instance: Any, name: str = "", arguments: Sequence[str] = ()
48
- ) -> SignalInstance[*CallArgs]:
49
- """Create a new signal instance"""
50
- if _signal_instance_constructor is None:
51
- set_signal_instance_constructor(get_fallback_signal_instance_constructor())
52
- assert _signal_instance_constructor is not None
53
- return _signal_instance_constructor(
54
- types=types,
55
- name=name,
56
- arguments=arguments,
57
- instance=instance,
58
- )
59
-
60
-
61
- SignalInstanceCacheName = "_SignalCache"
62
-
63
-
64
- def _get_signal_instances(instance: Any) -> dict[Signal, SignalInstance]:
65
- signal_instances: dict[Any, SignalInstance]
66
- try:
67
- signal_instances = getattr(instance, SignalInstanceCacheName)
68
- except AttributeError:
69
- signal_instances = {}
70
- setattr(instance, SignalInstanceCacheName, signal_instances)
71
- return signal_instances
72
-
73
-
74
- class Signal(Generic[*CallArgs]):
75
- def __init__(self, *types: type, name: str = "", arguments: Sequence[str] = ()):
76
- self._types = types
77
- self._name = name
78
- self._arguments = arguments
79
-
80
- @overload
81
- def __get__(self, instance: None, owner: Any | None) -> Signal[*CallArgs]: ...
82
-
83
- @overload
84
- def __get__(
85
- self, instance: Any, owner: Any | None
86
- ) -> SignalInstance[*CallArgs]: ...
87
-
88
- def __get__(self, instance: Any, owner: Any) -> Any:
89
- if instance is None:
90
- return self
91
- signal_instances = _get_signal_instances(instance)
92
- if self not in signal_instances:
93
- signal_instances[self] = create_signal_instance(
94
- *self._types,
95
- name=self._name,
96
- arguments=self._arguments,
97
- instance=instance,
98
- )
99
- return signal_instances[self]
100
-
101
-
102
- class SignalInstanceConstructor(Protocol[*CallArgs]):
103
- def __call__(
104
- self,
105
- *,
106
- types: tuple[type, ...],
107
- name: str,
108
- arguments: Sequence[str],
109
- instance: Any,
110
- ) -> SignalInstance[*CallArgs]: ...
111
-
112
-
113
- def set_signal_instance_constructor(constructor: SignalInstanceConstructor) -> None:
114
- global _signal_instance_constructor
115
- if _signal_instance_constructor is not None:
116
- raise RuntimeError("Signal instance constructor has already been set.")
117
- _signal_instance_constructor = constructor
118
-
119
-
120
- def get_fallback_signal_instance_constructor() -> SignalInstanceConstructor:
121
- class FallbackSignalInstance(SignalInstance[*CallArgs]):
122
- _callbacks: set[
123
- Callable[[*CallArgs], None]
124
- | WeakMethod[Callable[[*CallArgs], None]]
125
- | FallbackSignalInstance[*CallArgs]
126
- ]
127
-
128
- def __init__(self, *types: type):
129
- self._types = types
130
- self._callbacks = set()
131
-
132
- @staticmethod
133
- def _wrap_slot(
134
- slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None
135
- ) -> (
136
- Callable[[*CallArgs], None]
137
- | WeakMethod[Callable[[*CallArgs], None]]
138
- | FallbackSignalInstance[*CallArgs]
139
- ):
140
- if ismethod(slot):
141
- return WeakMethod(slot) # type: ignore
142
- elif isinstance(slot, FallbackSignalInstance) or callable(slot):
143
- return slot # type: ignore
144
- else:
145
- raise RuntimeError(f"{slot} is not a supported slot type.")
146
-
147
- def connect(
148
- self,
149
- slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None,
150
- type: PySide6.QtCore.Qt.ConnectionType | None = None,
151
- ) -> None:
152
- if type is not None:
153
- logging.warning(
154
- "FallbackSignalInstance does not support custom connection types. Using DirectConnection"
155
- )
156
- self._callbacks.add(self._wrap_slot(slot))
157
-
158
- def disconnect(
159
- self,
160
- slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None = None,
161
- ) -> None:
162
- self._callbacks.remove(self._wrap_slot(slot))
163
-
164
- def emit(self, *args: *CallArgs) -> None:
165
- if len(args) != len(self._types):
166
- raise TypeError(
167
- f"SignalInstance{self._types}.emit expected {len(self._types)} argument(s), {len(args)} given."
168
- )
169
- for slot in self._callbacks:
170
- try:
171
- if isinstance(slot, FallbackSignalInstance):
172
- slot.emit(*args) # type: ignore
173
- elif isinstance(slot, WeakMethod):
174
- method = slot()
175
- if method is not None:
176
- method(*args)
177
- else:
178
- slot(*args)
179
- except Exception as e:
180
- logging.error(e)
181
-
182
- def fallback_signal_instance_constructor(
183
- *,
184
- types: tuple[type, ...],
185
- name: str,
186
- arguments: Sequence[str],
187
- instance: Any,
188
- ) -> FallbackSignalInstance[*CallArgs]:
189
- return FallbackSignalInstance(*types)
190
-
191
- return fallback_signal_instance_constructor
192
-
193
-
194
- def get_pyside6_signal_instance_constructor() -> SignalInstanceConstructor:
195
- try:
196
- from PySide6.QtCore import (
197
- QObject,
198
- Signal as PySide6_Signal,
199
- SignalInstance as PySide6_SignalInstance,
200
- )
201
- except ImportError as e:
202
- raise ImportError("Could not import PySide6") from e
203
-
204
- QObjectCacheName = "_QObjectCache"
205
-
206
- def pyside6_signal_instance_constructor(
207
- *,
208
- types: tuple[type, ...],
209
- name: str,
210
- arguments: Sequence[str],
211
- instance: Any,
212
- ) -> PySide6_SignalInstance:
213
- if isinstance(instance, QObject):
214
- return PySide6_Signal(
215
- *types, name=name, arguments=list(arguments) if arguments else None
216
- ).__get__(instance, QObject)
217
- else:
218
- signal_instances = _get_signal_instances(instance)
219
- if QObjectCacheName not in signal_instances:
220
- signal_instances[QObjectCacheName] = QObject() # type: ignore
221
- obj = signal_instances[QObjectCacheName] # type: ignore
222
- if not isinstance(obj, QObject):
223
- raise RuntimeError
224
- return PySide6_Signal(*types, name=name, arguments=arguments).__get__(
225
- obj, QObject
226
- )
227
-
228
- return pyside6_signal_instance_constructor # type: ignore
@@ -1,235 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import Generic, TypeVar, Callable
4
- from abc import ABC, abstractmethod
5
-
6
- from .signal import Signal, SignalInstance
7
-
8
-
9
- T = TypeVar("T")
10
-
11
-
12
- class TaskCancelled(Exception):
13
- """Exception to be raised by the callee when a task is cancelled.
14
-
15
- The callee may define a custom return instead of using this.
16
- """
17
-
18
-
19
- class AbstractCancelManager(ABC):
20
- @abstractmethod
21
- def cancel(self) -> None:
22
- """Request the operation be canceled.
23
-
24
- It is down to the operation to implement support for this.
25
- """
26
- raise NotImplementedError
27
-
28
- @abstractmethod
29
- def is_cancel_requested(self) -> bool:
30
- """Has cancel been called to signal that the operation should be canceled."""
31
- raise NotImplementedError
32
-
33
- @abstractmethod
34
- def register_on_cancel(self, callback: Callable[[], None]) -> None:
35
- """Register a function to get called when :meth:`cancel` is called."""
36
- raise NotImplementedError
37
-
38
- @abstractmethod
39
- def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
40
- """Unregister a registered function from being called when :meth:`cancel` is called."""
41
- raise NotImplementedError
42
-
43
-
44
- class VoidCancelManager(AbstractCancelManager):
45
- def cancel(self) -> None:
46
- pass
47
-
48
- def is_cancel_requested(self) -> bool:
49
- return False
50
-
51
- def register_on_cancel(self, callback: Callable[[], None]) -> None:
52
- pass
53
-
54
- def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
55
- pass
56
-
57
-
58
- class Pointer(Generic[T]):
59
- value: T
60
-
61
- def __init__(self, value: T) -> None:
62
- self.value = value
63
-
64
-
65
- class _CancelManager(AbstractCancelManager):
66
- def __init__(
67
- self,
68
- cancelled: Pointer[bool],
69
- cancel_signal: SignalInstance[()],
70
- ) -> None:
71
- self._cancelled = cancelled
72
- self._on_cancel = cancel_signal
73
-
74
- def cancel(self) -> None:
75
- self._cancelled.value = True
76
- self._on_cancel.emit()
77
-
78
- def is_cancel_requested(self) -> bool:
79
- return self._cancelled.value
80
-
81
- def register_on_cancel(self, callback: Callable[[], None]) -> None:
82
- self._on_cancel.connect(callback)
83
-
84
- def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
85
- self._on_cancel.disconnect(callback)
86
-
87
-
88
- class CancelManager(_CancelManager):
89
- _cancel_signal = Signal[()]()
90
-
91
- def __init__(self) -> None:
92
- super().__init__(
93
- Pointer[bool](False),
94
- self._cancel_signal,
95
- )
96
-
97
-
98
- class AbstractProgressManager(ABC):
99
- @abstractmethod
100
- def update_progress(self, progress: float) -> None:
101
- """Notify the caller of the updated progress.
102
-
103
- :param progress: The new progress to relay to the caller. 0.0-1.0
104
- """
105
- raise NotImplementedError
106
-
107
- @abstractmethod
108
- def update_progress_text(self, text: str) -> None:
109
- """Notify the caller of the updated progress.
110
-
111
- :param text: The new message to relay to the caller.
112
- """
113
- raise NotImplementedError
114
-
115
- @abstractmethod
116
- def get_child(
117
- self, progress_min: float, progress_max: float
118
- ) -> AbstractProgressManager:
119
- """Get a child ExecutionContext.
120
-
121
- If calling multiple functions, this allows segmenting the reported time.
122
-
123
- :param progress_min: The minimum progress for the child to use 0.0-1.0
124
- :param progress_max: The maximum progress for the child to use 0.0-1.0
125
- :return: A new ExecutionContext
126
- """
127
- raise NotImplementedError
128
-
129
-
130
- class VoidProgressManager(AbstractProgressManager):
131
- def update_progress(self, progress: float) -> None:
132
- pass
133
-
134
- def update_progress_text(self, text: str) -> None:
135
- pass
136
-
137
- def get_child(
138
- self, progress_min: float, progress_max: float
139
- ) -> VoidProgressManager:
140
- return self
141
-
142
-
143
- class _ProgressManager(AbstractProgressManager):
144
- def __init__(
145
- self,
146
- progress_change: SignalInstance[float],
147
- progress_text_change: SignalInstance[str],
148
- progress_min: float,
149
- progress_max: float,
150
- ) -> None:
151
- self._progress_change = progress_change
152
- self._progress_text_change = progress_text_change
153
- assert 0.0 <= progress_min <= progress_max <= 1.0
154
- self._progress_min = progress_min
155
- self._progress_delta = progress_max - progress_min
156
-
157
- def update_progress(self, progress: float) -> None:
158
- assert 0.0 <= progress <= 1.0
159
- self._progress_change.emit(self._progress_min + progress * self._progress_delta)
160
-
161
- def update_progress_text(self, text: str) -> None:
162
- self._progress_text_change.emit(text)
163
-
164
- def get_child(self, progress_min: float, progress_max: float) -> _ProgressManager:
165
- assert 0.0 <= progress_min <= progress_max <= 1.0
166
- return _ProgressManager(
167
- self._progress_change,
168
- self._progress_text_change,
169
- self._progress_min + progress_min * self._progress_delta,
170
- self._progress_min + progress_max * self._progress_delta,
171
- )
172
-
173
-
174
- class ProgressManager(_ProgressManager):
175
- progress_change = Signal[float](float)
176
- progress_text_change = Signal[str](str)
177
-
178
- def __init__(self) -> None:
179
- super().__init__(
180
- self.progress_change,
181
- self.progress_text_change,
182
- 0.0,
183
- 1.0,
184
- )
185
-
186
-
187
- class AbstractTaskManager(AbstractCancelManager, AbstractProgressManager, ABC):
188
- pass
189
-
190
-
191
- class VoidTaskManager(VoidCancelManager, VoidProgressManager, AbstractTaskManager):
192
- """An empty Execution Context that ignores all calls."""
193
-
194
-
195
- class _TaskManager(CancelManager, ProgressManager, AbstractTaskManager):
196
- def __init__(
197
- self,
198
- cancelled: Pointer[bool],
199
- cancel_signal: SignalInstance[()],
200
- progress_change: SignalInstance[float],
201
- progress_text_change: SignalInstance[str],
202
- progress_min: float,
203
- progress_max: float,
204
- ) -> None:
205
- _CancelManager.__init__(self, cancelled, cancel_signal)
206
- _ProgressManager.__init__(
207
- self,
208
- progress_change,
209
- progress_text_change,
210
- progress_min,
211
- progress_max,
212
- )
213
-
214
- def get_child(self, progress_min: float, progress_max: float) -> _TaskManager:
215
- assert 0.0 <= progress_min <= progress_max <= 1.0
216
- return _TaskManager(
217
- self._cancelled,
218
- self._on_cancel,
219
- self._progress_change,
220
- self._progress_text_change,
221
- self._progress_min + progress_min * self._progress_delta,
222
- self._progress_min + progress_max * self._progress_delta,
223
- )
224
-
225
-
226
- class TaskManager(_TaskManager):
227
- def __init__(self) -> None:
228
- super().__init__(
229
- Pointer[bool](False),
230
- self._cancel_signal,
231
- self.progress_change,
232
- self.progress_text_change,
233
- 0.0,
234
- 1.0,
235
- )
@@ -1,111 +0,0 @@
1
- from __future__ import annotations
2
- from typing import TypeVar, Any, Generic, Callable, overload
3
-
4
- GetT = TypeVar("GetT")
5
- SetT = TypeVar("SetT")
6
-
7
-
8
- class TypedProperty(Generic[GetT, SetT]):
9
- """
10
- Type hinting with the vanilla property does not support having a different type on the setter.
11
- See https://github.com/python/mypy/issues/3004
12
- This is a custom property implementation that supports independently typing the getter and setter to appease mypy.
13
-
14
- Note that the getter, setter and deleter return the method they were given and not a property instance.
15
- This was to appease mypy complaining about overriding variables.
16
- This has a side effect that a setter can be used as a setter or the method
17
-
18
- >>> class MyClass:
19
- >>> def __init__(self) -> None:
20
- >>> self._value = 1
21
- >>>
22
- >>> @TypedProperty[int, int | float]
23
- >>> def value(self) -> int:
24
- >>> return self._value
25
- >>>
26
- >>> @value.setter
27
- >>> def set_value(self, val: int | float) -> None:
28
- >>> self._value = int(val)
29
- >>>
30
- >>> @value.deleter
31
- >>> def del_value(self) -> None:
32
- >>> del self._value
33
- >>>
34
- >>>
35
- >>> inst = MyClass()
36
- >>> assert inst.value == 1
37
- >>> inst.value = 2
38
- >>> assert inst.value == 2
39
- >>> inst.set_value(3)
40
- >>> assert inst.value == 3
41
- >>> del inst.value
42
- >>> try:
43
- >>> inst.value
44
- >>> except AttributeError:
45
- >>> pass
46
- >>> else:
47
- >>> raise Exception
48
- >>> inst.value = 4
49
- >>> assert inst.value == 4
50
-
51
- If you want the original methods to be private then just prefix them with an underscore.
52
- """
53
-
54
- fget: Callable[[Any], GetT] | None
55
- fset: Callable[[Any, SetT], None] | None
56
- fdel: Callable[[Any], None] | None
57
-
58
- def __init__(
59
- self,
60
- fget: Callable[[Any], GetT] | None = None,
61
- fset: Callable[[Any, SetT], None] | None = None,
62
- fdel: Callable[[Any], None] | None = None,
63
- doc: str | None = None,
64
- ) -> None:
65
- self.fget = fget
66
- self.fset = fset
67
- self.fdel = fdel
68
- if doc is None and fget is not None:
69
- doc = fget.__doc__
70
- self.__doc__ = doc
71
- self._name = ""
72
-
73
- def __set_name__(self, owner: Any, name: str) -> None:
74
- self._name = name
75
-
76
- @overload
77
- def __get__(self, obj: None, objtype: None) -> TypedProperty[GetT, SetT]: ...
78
-
79
- @overload
80
- def __get__(self, obj: object, objtype: type[object]) -> GetT: ...
81
-
82
- def __get__(
83
- self, obj: Any, objtype: Any = None
84
- ) -> GetT | TypedProperty[GetT, SetT]:
85
- if obj is None:
86
- return self
87
- if self.fget is None:
88
- raise AttributeError(f"property '{self._name}' has no getter")
89
- return self.fget(obj)
90
-
91
- def __set__(self, obj: Any, value: SetT) -> None:
92
- if self.fset is None:
93
- raise AttributeError(f"property '{self._name}' has no setter")
94
- self.fset(obj, value)
95
-
96
- def __delete__(self, obj: Any) -> None:
97
- if self.fdel is None:
98
- raise AttributeError(f"property '{self._name}' has no deleter")
99
- self.fdel(obj)
100
-
101
- def getter(self, fget: Callable[[Any], GetT]) -> Callable[[Any], GetT]:
102
- self.fget = fget
103
- return fget
104
-
105
- def setter(self, fset: Callable[[Any, SetT], None]) -> Callable[[Any, SetT], None]:
106
- self.fset = fset
107
- return fset
108
-
109
- def deleter(self, fdel: Callable[[Any], None]) -> Callable[[Any], None]:
110
- self.fdel = fdel
111
- return fdel
amulet/utils/weakref.py DELETED
@@ -1,70 +0,0 @@
1
- """Extension to the builtin weakref module."""
2
-
3
- from __future__ import annotations
4
- from typing import Any, TypeVar, Generic, Callable, final
5
- from weakref import WeakMethod as _WeakMethod, ReferenceType as _ReferenceType
6
-
7
- T = TypeVar("T")
8
-
9
-
10
- # Classes have an __del__ method to run code at object destruction.
11
- # This is usually sufficient if the object gets deleted before the interpreter exits.
12
- # In some cases global variables are set to None causing the __del__ to fail if run after interpreter shutdown.
13
- # I have noticed this while debugging.
14
- #
15
- # In the following example when debugging sys is None when __del__ is called after interpreter shutdown.
16
- #
17
- # >>> import sys
18
- # >>>
19
- # >>> class Cls:
20
- # >>> def __init__(self) -> None:
21
- # >>> self._sys_modules = sys.modules
22
- # >>> print(self._sys_modules)
23
- # >>>
24
- # >>> def __del__(self) -> None:
25
- # >>> print(self._sys_modules)
26
- # >>> print(sys)
27
- # >>>
28
- # >>> t = Cls()
29
- #
30
- # weakref.finalize takes care of this. It can be manually called in the __del__ method if the object is garbage
31
- # collected before interpreter shutdown or automatically run at interpreter exit. It can only be called once.
32
- # It must be given a weak method otherwise the instance will be kept alive until interpreter exit.
33
- # weakref.WeakMethod is not directly callable so CallableWeakMethod is implemented to allow this.
34
-
35
-
36
- @final
37
- class CallableWeakMethod(_WeakMethod):
38
- """
39
- A wrapper around WeakMethod that makes the method directly callable.
40
- If the method no longer exists, this does nothing.
41
- """
42
-
43
- def __call__(self, *args: Any, **kwargs: Any) -> Any:
44
- meth = super().__call__()
45
- if meth is not None:
46
- return meth(*args, **kwargs)
47
-
48
-
49
- @final
50
- class DetachableWeakRef(Generic[T]):
51
- """A weak reference that can be detached by the creator before the object is deleted."""
52
-
53
- _ref: Callable[[], T | None]
54
-
55
- @classmethod
56
- def new(cls, obj: T) -> tuple[DetachableWeakRef[T], Callable[[], None]]:
57
- """Get a new weak reference and a callable to detach the object.
58
- Once called the reference will always return None.
59
- """
60
- self = cls(obj)
61
- return self, self._detach
62
-
63
- def __init__(self, obj: T) -> None:
64
- self._ref = _ReferenceType(obj)
65
-
66
- def __call__(self) -> T | None:
67
- return self._ref()
68
-
69
- def _detach(self) -> None:
70
- self._ref = lambda: None