amulet-core 2.0a3__cp312-cp312-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.
- amulet/__init__.cp312-win_amd64.pyd +0 -0
- amulet/__init__.pyi +30 -0
- amulet/__pyinstaller/__init__.py +2 -0
- amulet/__pyinstaller/hook-amulet.py +4 -0
- amulet/_init.py +28 -0
- amulet/_version.py +21 -0
- amulet/biome.cpp +36 -0
- amulet/biome.hpp +43 -0
- amulet/biome.pyi +77 -0
- amulet/block.cpp +435 -0
- amulet/block.hpp +119 -0
- amulet/block.pyi +273 -0
- amulet/block_entity.cpp +12 -0
- amulet/block_entity.hpp +56 -0
- amulet/block_entity.pyi +80 -0
- amulet/chunk.cpp +16 -0
- amulet/chunk.hpp +99 -0
- amulet/chunk.pyi +30 -0
- amulet/chunk_/components/biome.py +155 -0
- amulet/chunk_/components/block_entity.py +117 -0
- amulet/chunk_/components/entity.py +64 -0
- amulet/chunk_/components/height_2d.py +16 -0
- amulet/chunk_components.pyi +95 -0
- amulet/collections.pyi +37 -0
- amulet/data_types.py +29 -0
- amulet/entity.py +180 -0
- amulet/errors.py +63 -0
- amulet/game/__init__.py +7 -0
- amulet/game/_game.py +152 -0
- amulet/game/_universal/__init__.py +1 -0
- amulet/game/_universal/_biome.py +17 -0
- amulet/game/_universal/_block.py +47 -0
- amulet/game/_universal/_version.py +68 -0
- amulet/game/abc/__init__.py +22 -0
- amulet/game/abc/_block_specification.py +150 -0
- amulet/game/abc/biome.py +213 -0
- amulet/game/abc/block.py +331 -0
- amulet/game/abc/game_version_container.py +25 -0
- amulet/game/abc/json_interface.py +27 -0
- amulet/game/abc/version.py +44 -0
- amulet/game/bedrock/__init__.py +1 -0
- amulet/game/bedrock/_biome.py +35 -0
- amulet/game/bedrock/_block.py +42 -0
- amulet/game/bedrock/_version.py +165 -0
- amulet/game/java/__init__.py +2 -0
- amulet/game/java/_biome.py +35 -0
- amulet/game/java/_block.py +60 -0
- amulet/game/java/_version.py +176 -0
- amulet/game/translate/__init__.py +12 -0
- amulet/game/translate/_functions/__init__.py +15 -0
- amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
- amulet/game/translate/_functions/_code_functions/_text.py +553 -0
- amulet/game/translate/_functions/_code_functions/banner_pattern.py +67 -0
- amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +152 -0
- amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +88 -0
- amulet/game/translate/_functions/_code_functions/bedrock_sign.py +152 -0
- amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +16 -0
- amulet/game/translate/_functions/_code_functions/custom_name.py +146 -0
- amulet/game/translate/_functions/_frozen.py +66 -0
- amulet/game/translate/_functions/_state.py +54 -0
- amulet/game/translate/_functions/_typing.py +98 -0
- amulet/game/translate/_functions/abc.py +116 -0
- amulet/game/translate/_functions/carry_nbt.py +160 -0
- amulet/game/translate/_functions/carry_properties.py +80 -0
- amulet/game/translate/_functions/code.py +143 -0
- amulet/game/translate/_functions/map_block_name.py +66 -0
- amulet/game/translate/_functions/map_nbt.py +111 -0
- amulet/game/translate/_functions/map_properties.py +93 -0
- amulet/game/translate/_functions/multiblock.py +112 -0
- amulet/game/translate/_functions/new_block.py +42 -0
- amulet/game/translate/_functions/new_entity.py +43 -0
- amulet/game/translate/_functions/new_nbt.py +206 -0
- amulet/game/translate/_functions/new_properties.py +64 -0
- amulet/game/translate/_functions/sequence.py +51 -0
- amulet/game/translate/_functions/walk_input_nbt.py +331 -0
- amulet/game/translate/_translator.py +433 -0
- amulet/item.py +75 -0
- amulet/level/__init__.pyi +27 -0
- amulet/level/_load.py +100 -0
- amulet/level/abc/__init__.py +12 -0
- amulet/level/abc/_chunk_handle.py +335 -0
- amulet/level/abc/_dimension.py +86 -0
- amulet/level/abc/_history/__init__.py +1 -0
- amulet/level/abc/_history/_cache.py +224 -0
- amulet/level/abc/_history/_history_manager.py +291 -0
- amulet/level/abc/_level/__init__.py +5 -0
- amulet/level/abc/_level/_compactable_level.py +10 -0
- amulet/level/abc/_level/_creatable_level.py +29 -0
- amulet/level/abc/_level/_disk_level.py +17 -0
- amulet/level/abc/_level/_level.py +453 -0
- amulet/level/abc/_level/_loadable_level.py +42 -0
- amulet/level/abc/_player_storage.py +7 -0
- amulet/level/abc/_raw_level.py +187 -0
- amulet/level/abc/_registry.py +40 -0
- amulet/level/bedrock/__init__.py +2 -0
- amulet/level/bedrock/_chunk_handle.py +19 -0
- amulet/level/bedrock/_dimension.py +22 -0
- amulet/level/bedrock/_level.py +187 -0
- amulet/level/bedrock/_raw/__init__.py +5 -0
- amulet/level/bedrock/_raw/_actor_counter.py +53 -0
- amulet/level/bedrock/_raw/_chunk.py +54 -0
- amulet/level/bedrock/_raw/_chunk_decode.py +668 -0
- amulet/level/bedrock/_raw/_chunk_encode.py +602 -0
- amulet/level/bedrock/_raw/_constant.py +9 -0
- amulet/level/bedrock/_raw/_dimension.py +343 -0
- amulet/level/bedrock/_raw/_level.py +463 -0
- amulet/level/bedrock/_raw/_level_dat.py +90 -0
- amulet/level/bedrock/_raw/_typing.py +6 -0
- amulet/level/bedrock/_raw/leveldb_chunk_versions.py +83 -0
- amulet/level/bedrock/chunk/__init__.py +1 -0
- amulet/level/bedrock/chunk/_chunk.py +126 -0
- amulet/level/bedrock/chunk/components/__init__.py +0 -0
- amulet/level/bedrock/chunk/components/chunk_version.py +12 -0
- amulet/level/bedrock/chunk/components/finalised_state.py +13 -0
- amulet/level/bedrock/chunk/components/raw_chunk.py +15 -0
- amulet/level/construction/__init__.py +0 -0
- amulet/level/java/__init__.pyi +21 -0
- amulet/level/java/_chunk_handle.py +17 -0
- amulet/level/java/_chunk_handle.pyi +15 -0
- amulet/level/java/_dimension.py +20 -0
- amulet/level/java/_dimension.pyi +13 -0
- amulet/level/java/_level.py +184 -0
- amulet/level/java/_level.pyi +120 -0
- amulet/level/java/_raw/__init__.pyi +19 -0
- amulet/level/java/_raw/_chunk.pyi +23 -0
- amulet/level/java/_raw/_chunk_decode.py +561 -0
- amulet/level/java/_raw/_chunk_encode.py +463 -0
- amulet/level/java/_raw/_constant.py +9 -0
- amulet/level/java/_raw/_constant.pyi +20 -0
- amulet/level/java/_raw/_data_pack/__init__.py +2 -0
- amulet/level/java/_raw/_data_pack/__init__.pyi +8 -0
- amulet/level/java/_raw/_data_pack/data_pack.py +241 -0
- amulet/level/java/_raw/_data_pack/data_pack.pyi +197 -0
- amulet/level/java/_raw/_data_pack/data_pack_manager.py +77 -0
- amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +75 -0
- amulet/level/java/_raw/_dimension.py +86 -0
- amulet/level/java/_raw/_dimension.pyi +72 -0
- amulet/level/java/_raw/_level.py +507 -0
- amulet/level/java/_raw/_level.pyi +238 -0
- amulet/level/java/_raw/_typing.py +3 -0
- amulet/level/java/_raw/_typing.pyi +5 -0
- amulet/level/java/anvil/__init__.py +2 -0
- amulet/level/java/anvil/__init__.pyi +11 -0
- amulet/level/java/anvil/_dimension.py +170 -0
- amulet/level/java/anvil/_dimension.pyi +109 -0
- amulet/level/java/anvil/_region.py +421 -0
- amulet/level/java/anvil/_region.pyi +197 -0
- amulet/level/java/anvil/_sector_manager.py +223 -0
- amulet/level/java/anvil/_sector_manager.pyi +142 -0
- amulet/level/java/chunk.pyi +81 -0
- amulet/level/java/chunk_/_chunk.py +260 -0
- amulet/level/java/chunk_/components/inhabited_time.py +12 -0
- amulet/level/java/chunk_/components/last_update.py +12 -0
- amulet/level/java/chunk_/components/legacy_version.py +12 -0
- amulet/level/java/chunk_/components/light_populated.py +12 -0
- amulet/level/java/chunk_/components/named_height_2d.py +37 -0
- amulet/level/java/chunk_/components/status.py +11 -0
- amulet/level/java/chunk_/components/terrain_populated.py +12 -0
- amulet/level/java/chunk_components.pyi +22 -0
- amulet/level/java/long_array.pyi +38 -0
- amulet/level/java_forge/__init__.py +0 -0
- amulet/level/mcstructure/__init__.py +0 -0
- amulet/level/nbt/__init__.py +0 -0
- amulet/level/schematic/__init__.py +0 -0
- amulet/level/sponge_schematic/__init__.py +0 -0
- amulet/level/temporary_level/__init__.py +1 -0
- amulet/level/temporary_level/_level.py +16 -0
- amulet/palette/__init__.pyi +8 -0
- amulet/palette/biome_palette.pyi +45 -0
- amulet/palette/block_palette.pyi +45 -0
- amulet/player.py +64 -0
- amulet/py.typed +0 -0
- amulet/selection/__init__.py +2 -0
- amulet/selection/abstract_selection.py +342 -0
- amulet/selection/box.py +852 -0
- amulet/selection/group.py +481 -0
- amulet/utils/__init__.pyi +28 -0
- amulet/utils/call_spec/__init__.py +24 -0
- amulet/utils/call_spec/__init__.pyi +53 -0
- amulet/utils/call_spec/_call_spec.py +262 -0
- amulet/utils/call_spec/_call_spec.pyi +272 -0
- amulet/utils/format_utils.py +41 -0
- amulet/utils/generator.py +18 -0
- amulet/utils/matrix.py +243 -0
- amulet/utils/matrix.pyi +177 -0
- amulet/utils/numpy.pyi +11 -0
- amulet/utils/numpy_helpers.py +19 -0
- amulet/utils/shareable_lock.py +335 -0
- amulet/utils/shareable_lock.pyi +190 -0
- amulet/utils/signal/__init__.py +10 -0
- amulet/utils/signal/__init__.pyi +25 -0
- amulet/utils/signal/_signal.py +228 -0
- amulet/utils/signal/_signal.pyi +84 -0
- amulet/utils/task_manager.py +235 -0
- amulet/utils/task_manager.pyi +168 -0
- amulet/utils/typed_property.py +111 -0
- amulet/utils/typing.py +4 -0
- amulet/utils/typing.pyi +6 -0
- amulet/utils/weakref.py +70 -0
- amulet/utils/weakref.pyi +50 -0
- amulet/utils/world_utils.py +102 -0
- amulet/utils/world_utils.pyi +109 -0
- amulet/version.cpp +136 -0
- amulet/version.hpp +142 -0
- amulet/version.pyi +94 -0
- amulet_core-2.0a3.dist-info/METADATA +103 -0
- amulet_core-2.0a3.dist-info/RECORD +210 -0
- amulet_core-2.0a3.dist-info/WHEEL +5 -0
- amulet_core-2.0a3.dist-info/entry_points.txt +2 -0
- amulet_core-2.0a3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""This modules contains classes to notify other code of the call specification for a function.
|
|
2
|
+
The aim is to support generating GUIs without having to manually program a GUI to handle the function call.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import (
|
|
8
|
+
Any,
|
|
9
|
+
Callable,
|
|
10
|
+
Hashable,
|
|
11
|
+
Protocol,
|
|
12
|
+
TypeVar,
|
|
13
|
+
cast,
|
|
14
|
+
ParamSpec,
|
|
15
|
+
overload,
|
|
16
|
+
Concatenate,
|
|
17
|
+
runtime_checkable,
|
|
18
|
+
)
|
|
19
|
+
from collections.abc import Sequence
|
|
20
|
+
from abc import ABC, abstractmethod
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AbstractArg(ABC):
|
|
24
|
+
"""The base class for all arguments."""
|
|
25
|
+
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
28
|
+
raise NotImplementedError
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AbstractHashableArg(AbstractArg, ABC):
|
|
32
|
+
"""A base class for all arguments that are hashable."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class DocumentationArg(AbstractArg):
|
|
36
|
+
"""A way to add documentation for an argument."""
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self, arg: AbstractArg, name: str | None = None, description: str | None = None
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Construct a DocumentationArg instance.
|
|
42
|
+
|
|
43
|
+
:param arg: The argument this documentation relates to.
|
|
44
|
+
:param name: The short name for the argument.
|
|
45
|
+
:param description: A longer description for the argument.
|
|
46
|
+
"""
|
|
47
|
+
self.arg = arg
|
|
48
|
+
self.name = name
|
|
49
|
+
self.description = description
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ConstantArg(AbstractArg):
|
|
53
|
+
"""A constant argument.
|
|
54
|
+
Use this for fixed values.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def __init__(self, value: Any) -> None:
|
|
58
|
+
self.value = value
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class StringArg(AbstractHashableArg):
|
|
62
|
+
"""A string argument"""
|
|
63
|
+
|
|
64
|
+
def __init__(self, default: str = "") -> None:
|
|
65
|
+
self.default = default
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class FilePathArg(StringArg):
|
|
69
|
+
"""A path to a file on disk. Converts to a string."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class DirectoryPathArg(StringArg):
|
|
73
|
+
"""A path to a directory on disk. Converts to a string."""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class BytesArg(AbstractHashableArg):
|
|
77
|
+
"""A bytes argument"""
|
|
78
|
+
|
|
79
|
+
def __init__(self, default: bytes = b"") -> None:
|
|
80
|
+
self.default = default
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class BoolArg(AbstractHashableArg):
|
|
84
|
+
"""A bool argument"""
|
|
85
|
+
|
|
86
|
+
def __init__(self, default: bool = False) -> None:
|
|
87
|
+
self.default = default
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class IntArg(AbstractHashableArg):
|
|
91
|
+
"""An int argument"""
|
|
92
|
+
|
|
93
|
+
def __init__(
|
|
94
|
+
self,
|
|
95
|
+
default: int = 0,
|
|
96
|
+
min_value: int | None = None,
|
|
97
|
+
max_value: int | None = None,
|
|
98
|
+
) -> None:
|
|
99
|
+
self.default = default
|
|
100
|
+
self.min_value = min_value
|
|
101
|
+
self.max_value = max_value
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class FloatArg(AbstractHashableArg):
|
|
105
|
+
"""A float argument"""
|
|
106
|
+
|
|
107
|
+
def __init__(
|
|
108
|
+
self,
|
|
109
|
+
default: float = 0,
|
|
110
|
+
min_value: float | None = None,
|
|
111
|
+
max_value: float | None = None,
|
|
112
|
+
) -> None:
|
|
113
|
+
self.default = default
|
|
114
|
+
self.min_value = min_value
|
|
115
|
+
self.max_value = max_value
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class TupleArg(AbstractArg):
|
|
119
|
+
"""A tuple argument"""
|
|
120
|
+
|
|
121
|
+
def __init__(self, *args: AbstractArg) -> None:
|
|
122
|
+
self.args = args
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class HashableTupleArg(AbstractArg):
|
|
126
|
+
"""A tuple argument where all elements are hashable."""
|
|
127
|
+
|
|
128
|
+
def __init__(self, *args: AbstractHashableArg) -> None:
|
|
129
|
+
self.args = args
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class SequenceArg(AbstractArg):
|
|
133
|
+
"""
|
|
134
|
+
A sequence of other arguments.
|
|
135
|
+
Each element must match element_type.
|
|
136
|
+
length must be a positive integer for a fixed length or None for unbounded length.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def __init__(
|
|
140
|
+
self,
|
|
141
|
+
element_type: AbstractArg,
|
|
142
|
+
default: Sequence[AbstractArg] = (),
|
|
143
|
+
min_length: int | None = None,
|
|
144
|
+
max_length: int | None = None,
|
|
145
|
+
) -> None:
|
|
146
|
+
self.element_type = element_type
|
|
147
|
+
self.default = default
|
|
148
|
+
self.min_length = min_length
|
|
149
|
+
self.max_length = max_length
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class PositionalArgs(SequenceArg):
|
|
153
|
+
"""A sequence of arguments that should be unpacked into the container.
|
|
154
|
+
This is useful when a CallableArg can take a variable number of an argument.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class DictArg(AbstractArg):
|
|
159
|
+
"""A dictionary argument"""
|
|
160
|
+
|
|
161
|
+
def __init__(self, key: AbstractHashableArg, value: AbstractArg) -> None:
|
|
162
|
+
self.key = key
|
|
163
|
+
self.value = value
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class UnionArg(AbstractArg):
|
|
167
|
+
"""The object must match one of the types in args"""
|
|
168
|
+
|
|
169
|
+
def __init__(self, *args: AbstractArg) -> None:
|
|
170
|
+
self.args = args
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class HashableUnionArg(AbstractArg):
|
|
174
|
+
"""The object must match one of the types in args"""
|
|
175
|
+
|
|
176
|
+
def __init__(self, *args: AbstractHashableArg) -> None:
|
|
177
|
+
self.args = args
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class CallableArg(AbstractArg):
|
|
181
|
+
"""An argument generated by a function.
|
|
182
|
+
This can be used to create instances of classes.
|
|
183
|
+
kwargs specify the arguments to pass to the function.
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
def __init__(
|
|
187
|
+
self, func: Callable[..., Any], *args: AbstractArg, **kwargs: AbstractArg
|
|
188
|
+
) -> None:
|
|
189
|
+
self.func = func
|
|
190
|
+
self.call_spec = CallSpec(*args, **kwargs)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class HashableCallableArg(AbstractHashableArg):
|
|
194
|
+
"""An argument generated by a function.
|
|
195
|
+
This can be used to create instances of classes.
|
|
196
|
+
kwargs specify the arguments to pass to the function.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
def __init__(self, func: Callable[..., Hashable], call_spec: CallSpec) -> None:
|
|
200
|
+
self.func = func
|
|
201
|
+
self.call_spec = call_spec
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class CallSpec:
|
|
205
|
+
"""Arguments and keyword arguments that should be unpacked to call a function."""
|
|
206
|
+
|
|
207
|
+
def __init__(self, *args: AbstractArg, **kwargs: AbstractArg) -> None:
|
|
208
|
+
self.args = args
|
|
209
|
+
self.kwargs = kwargs
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# The following is a really janky workaround to add a variable to a function or method in a way that mypy likes.
|
|
213
|
+
# This would be made so much simpler if Python had an Intersection type hint.
|
|
214
|
+
|
|
215
|
+
P = ParamSpec("P")
|
|
216
|
+
R = TypeVar("R", covariant=True)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@runtime_checkable
|
|
220
|
+
class TypedCallable(Protocol[P, R]):
|
|
221
|
+
call_spec: CallSpec
|
|
222
|
+
|
|
223
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@runtime_checkable
|
|
227
|
+
class TypedMethod(Protocol[P, R]):
|
|
228
|
+
call_spec: CallSpec
|
|
229
|
+
|
|
230
|
+
def __call__(self, self_: Any, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
231
|
+
|
|
232
|
+
@overload
|
|
233
|
+
def __get__(self, instance: None, owner: None) -> TypedMethod[P, R]: ...
|
|
234
|
+
|
|
235
|
+
@overload
|
|
236
|
+
def __get__(self, instance: object, owner: object) -> TypedCallable[P, R]: ...
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def callable_spec(
|
|
240
|
+
*args: AbstractArg, **kwargs: AbstractArg
|
|
241
|
+
) -> Callable[[Callable[P, R]], TypedCallable[P, R]]:
|
|
242
|
+
call_spec: CallSpec = CallSpec(*args, **kwargs)
|
|
243
|
+
|
|
244
|
+
def wrap(func: Callable[P, R]) -> TypedCallable[P, R]:
|
|
245
|
+
func_ = cast(TypedCallable[P, R], func)
|
|
246
|
+
func_.call_spec = call_spec
|
|
247
|
+
return func_
|
|
248
|
+
|
|
249
|
+
return wrap
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def method_spec(
|
|
253
|
+
*args: AbstractArg, **kwargs: AbstractArg
|
|
254
|
+
) -> Callable[[Callable[Concatenate[Any, P], R]], TypedMethod[P, R]]:
|
|
255
|
+
call_spec: CallSpec = CallSpec(*args, **kwargs)
|
|
256
|
+
|
|
257
|
+
def wrap(func: Callable[Concatenate[Any, P], R]) -> TypedMethod[P, R]:
|
|
258
|
+
func_ = cast(TypedMethod[P, R], func)
|
|
259
|
+
func_.call_spec = call_spec
|
|
260
|
+
return func_
|
|
261
|
+
|
|
262
|
+
return wrap
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This modules contains classes to notify other code of the call specification for a function.
|
|
3
|
+
The aim is to support generating GUIs without having to manually program a GUI to handle the function call.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import abc
|
|
9
|
+
import typing
|
|
10
|
+
from abc import ABC, abstractmethod
|
|
11
|
+
from collections.abc import Sequence
|
|
12
|
+
from typing import Any, ParamSpec, Protocol, TypeVar, cast, overload, runtime_checkable
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"ABC",
|
|
16
|
+
"AbstractArg",
|
|
17
|
+
"AbstractHashableArg",
|
|
18
|
+
"Any",
|
|
19
|
+
"BoolArg",
|
|
20
|
+
"BytesArg",
|
|
21
|
+
"CallSpec",
|
|
22
|
+
"CallableArg",
|
|
23
|
+
"ConstantArg",
|
|
24
|
+
"DictArg",
|
|
25
|
+
"DirectoryPathArg",
|
|
26
|
+
"DocumentationArg",
|
|
27
|
+
"FilePathArg",
|
|
28
|
+
"FloatArg",
|
|
29
|
+
"HashableCallableArg",
|
|
30
|
+
"HashableTupleArg",
|
|
31
|
+
"HashableUnionArg",
|
|
32
|
+
"IntArg",
|
|
33
|
+
"P",
|
|
34
|
+
"ParamSpec",
|
|
35
|
+
"PositionalArgs",
|
|
36
|
+
"Protocol",
|
|
37
|
+
"R",
|
|
38
|
+
"Sequence",
|
|
39
|
+
"SequenceArg",
|
|
40
|
+
"StringArg",
|
|
41
|
+
"TupleArg",
|
|
42
|
+
"TypeVar",
|
|
43
|
+
"TypedCallable",
|
|
44
|
+
"TypedMethod",
|
|
45
|
+
"UnionArg",
|
|
46
|
+
"abstractmethod",
|
|
47
|
+
"callable_spec",
|
|
48
|
+
"cast",
|
|
49
|
+
"method_spec",
|
|
50
|
+
"overload",
|
|
51
|
+
"runtime_checkable",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
class AbstractArg(abc.ABC):
|
|
55
|
+
"""
|
|
56
|
+
The base class for all arguments.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: ...
|
|
60
|
+
|
|
61
|
+
class AbstractHashableArg(AbstractArg, abc.ABC):
|
|
62
|
+
"""
|
|
63
|
+
A base class for all arguments that are hashable.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
class BoolArg(AbstractHashableArg):
|
|
67
|
+
"""
|
|
68
|
+
A bool argument
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, default: bool = False) -> None: ...
|
|
72
|
+
|
|
73
|
+
class BytesArg(AbstractHashableArg):
|
|
74
|
+
"""
|
|
75
|
+
A bytes argument
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
def __init__(self, default: bytes = ...) -> None: ...
|
|
79
|
+
|
|
80
|
+
class CallSpec:
|
|
81
|
+
"""
|
|
82
|
+
Arguments and keyword arguments that should be unpacked to call a function.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
def __init__(self, *args: AbstractArg, **kwargs: AbstractArg) -> None: ...
|
|
86
|
+
|
|
87
|
+
class CallableArg(AbstractArg):
|
|
88
|
+
"""
|
|
89
|
+
An argument generated by a function.
|
|
90
|
+
This can be used to create instances of classes.
|
|
91
|
+
kwargs specify the arguments to pass to the function.
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(
|
|
96
|
+
self,
|
|
97
|
+
func: typing.Callable[..., typing.Any],
|
|
98
|
+
*args: AbstractArg,
|
|
99
|
+
**kwargs: AbstractArg,
|
|
100
|
+
) -> None: ...
|
|
101
|
+
|
|
102
|
+
class ConstantArg(AbstractArg):
|
|
103
|
+
"""
|
|
104
|
+
A constant argument.
|
|
105
|
+
Use this for fixed values.
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
def __init__(self, value: typing.Any) -> None: ...
|
|
110
|
+
|
|
111
|
+
class DictArg(AbstractArg):
|
|
112
|
+
"""
|
|
113
|
+
A dictionary argument
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def __init__(self, key: AbstractHashableArg, value: AbstractArg) -> None: ...
|
|
117
|
+
|
|
118
|
+
class DirectoryPathArg(StringArg):
|
|
119
|
+
"""
|
|
120
|
+
A path to a directory on disk. Converts to a string.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
class DocumentationArg(AbstractArg):
|
|
124
|
+
"""
|
|
125
|
+
A way to add documentation for an argument.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __init__(
|
|
129
|
+
self, arg: AbstractArg, name: str | None = None, description: str | None = None
|
|
130
|
+
) -> None:
|
|
131
|
+
"""
|
|
132
|
+
Construct a DocumentationArg instance.
|
|
133
|
+
|
|
134
|
+
:param arg: The argument this documentation relates to.
|
|
135
|
+
:param name: The short name for the argument.
|
|
136
|
+
:param description: A longer description for the argument.
|
|
137
|
+
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
class FilePathArg(StringArg):
|
|
141
|
+
"""
|
|
142
|
+
A path to a file on disk. Converts to a string.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
class FloatArg(AbstractHashableArg):
|
|
146
|
+
"""
|
|
147
|
+
A float argument
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
def __init__(
|
|
151
|
+
self,
|
|
152
|
+
default: float = 0,
|
|
153
|
+
min_value: float | None = None,
|
|
154
|
+
max_value: float | None = None,
|
|
155
|
+
) -> None: ...
|
|
156
|
+
|
|
157
|
+
class HashableCallableArg(AbstractHashableArg):
|
|
158
|
+
"""
|
|
159
|
+
An argument generated by a function.
|
|
160
|
+
This can be used to create instances of classes.
|
|
161
|
+
kwargs specify the arguments to pass to the function.
|
|
162
|
+
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
def __init__(
|
|
166
|
+
self, func: typing.Callable[..., Hashable], call_spec: CallSpec
|
|
167
|
+
) -> None: ...
|
|
168
|
+
|
|
169
|
+
class HashableTupleArg(AbstractArg):
|
|
170
|
+
"""
|
|
171
|
+
A tuple argument where all elements are hashable.
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
def __init__(self, *args: AbstractHashableArg) -> None: ...
|
|
175
|
+
|
|
176
|
+
class HashableUnionArg(AbstractArg):
|
|
177
|
+
"""
|
|
178
|
+
The object must match one of the types in args
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
def __init__(self, *args: AbstractHashableArg) -> None: ...
|
|
182
|
+
|
|
183
|
+
class IntArg(AbstractHashableArg):
|
|
184
|
+
"""
|
|
185
|
+
An int argument
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
def __init__(
|
|
189
|
+
self,
|
|
190
|
+
default: int = 0,
|
|
191
|
+
min_value: int | None = None,
|
|
192
|
+
max_value: int | None = None,
|
|
193
|
+
) -> None: ...
|
|
194
|
+
|
|
195
|
+
class PositionalArgs(SequenceArg):
|
|
196
|
+
"""
|
|
197
|
+
A sequence of arguments that should be unpacked into the container.
|
|
198
|
+
This is useful when a CallableArg can take a variable number of an argument.
|
|
199
|
+
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
class SequenceArg(AbstractArg):
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
A sequence of other arguments.
|
|
206
|
+
Each element must match element_type.
|
|
207
|
+
length must be a positive integer for a fixed length or None for unbounded length.
|
|
208
|
+
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
def __init__(
|
|
212
|
+
self,
|
|
213
|
+
element_type: AbstractArg,
|
|
214
|
+
default: typing.Sequence[AbstractArg] = tuple(),
|
|
215
|
+
min_length: int | None = None,
|
|
216
|
+
max_length: int | None = None,
|
|
217
|
+
) -> None: ...
|
|
218
|
+
|
|
219
|
+
class StringArg(AbstractHashableArg):
|
|
220
|
+
"""
|
|
221
|
+
A string argument
|
|
222
|
+
"""
|
|
223
|
+
|
|
224
|
+
def __init__(self, default: str) -> None: ...
|
|
225
|
+
|
|
226
|
+
class TupleArg(AbstractArg):
|
|
227
|
+
"""
|
|
228
|
+
A tuple argument
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
def __init__(self, *args: AbstractArg) -> None: ...
|
|
232
|
+
|
|
233
|
+
class TypedCallable(typing.Protocol):
|
|
234
|
+
__non_callable_proto_members__: typing.ClassVar[set] = {"call_spec"}
|
|
235
|
+
_is_runtime_protocol: typing.ClassVar[bool] = True
|
|
236
|
+
@classmethod
|
|
237
|
+
def __subclasshook__(cls, other): ...
|
|
238
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
239
|
+
def __init__(self, *args, **kwargs): ...
|
|
240
|
+
|
|
241
|
+
class TypedMethod(typing.Protocol):
|
|
242
|
+
__non_callable_proto_members__: typing.ClassVar[set] = {"call_spec"}
|
|
243
|
+
_is_runtime_protocol: typing.ClassVar[bool] = True
|
|
244
|
+
@staticmethod
|
|
245
|
+
def __get__(*args, **kwds):
|
|
246
|
+
"""
|
|
247
|
+
Helper for @overload to raise when called.
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
@classmethod
|
|
251
|
+
def __subclasshook__(cls, other): ...
|
|
252
|
+
def __call__(self, self_: typing.Any, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
253
|
+
def __init__(self, *args, **kwargs): ...
|
|
254
|
+
|
|
255
|
+
class UnionArg(AbstractArg):
|
|
256
|
+
"""
|
|
257
|
+
The object must match one of the types in args
|
|
258
|
+
"""
|
|
259
|
+
|
|
260
|
+
def __init__(self, *args: AbstractArg) -> None: ...
|
|
261
|
+
|
|
262
|
+
def callable_spec(
|
|
263
|
+
*args: AbstractArg, **kwargs: AbstractArg
|
|
264
|
+
) -> typing.Callable[[typing.Callable[P, R]], TypedCallable[P, R]]: ...
|
|
265
|
+
def method_spec(
|
|
266
|
+
*args: AbstractArg, **kwargs: AbstractArg
|
|
267
|
+
) -> typing.Callable[
|
|
268
|
+
[typing.Callable[Concatenate[typing.Any, P], R]], TypedMethod[P, R]
|
|
269
|
+
]: ...
|
|
270
|
+
|
|
271
|
+
P: typing.ParamSpec # value = ~P
|
|
272
|
+
R: typing.TypeVar # value = +R
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
from amulet_nbt import read_nbt, NamedTag
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def check_all_exist(in_dir: str, *args: str) -> bool:
|
|
10
|
+
"""
|
|
11
|
+
Check that all files exist in a parent directory
|
|
12
|
+
|
|
13
|
+
:param in_dir: The parent directory
|
|
14
|
+
:param args: file or folder names to look for
|
|
15
|
+
:return: Boolean value indicating whether all were found
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
return all(os.path.exists(os.path.join(in_dir, child)) for child in args)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def check_one_exists(in_dir: str, *args: str) -> bool:
|
|
22
|
+
"""
|
|
23
|
+
Check that at least one file exists in a parent directory
|
|
24
|
+
|
|
25
|
+
:param in_dir: The parent directory
|
|
26
|
+
:param args: file or folder names to look for
|
|
27
|
+
:return: Boolean value indicating whether at least one was found
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
return any(os.path.exists(os.path.join(in_dir, child)) for child in args)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def load_leveldat(in_dir: str) -> NamedTag:
|
|
34
|
+
"""
|
|
35
|
+
Load the root tag of the level.dat file in the directory
|
|
36
|
+
|
|
37
|
+
:param in_dir: The world directory containing the level.dat file
|
|
38
|
+
:return: The NBT root tag
|
|
39
|
+
"""
|
|
40
|
+
warnings.warn("load_leveldat is depreciated.", DeprecationWarning)
|
|
41
|
+
return read_nbt(os.path.join(in_dir, "level.dat"))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Generator, TypeVar, Any
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
T = TypeVar("T")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def generator_unpacker(gen: Generator[Any, Any, T]) -> T:
|
|
8
|
+
"""
|
|
9
|
+
Unpack a generator and return the value returned by the generator.
|
|
10
|
+
|
|
11
|
+
:param gen: The generator to unpack.
|
|
12
|
+
:return: The value that was returned by the generator.
|
|
13
|
+
"""
|
|
14
|
+
try:
|
|
15
|
+
while True:
|
|
16
|
+
next(gen)
|
|
17
|
+
except StopIteration as e:
|
|
18
|
+
return e.value # type: ignore
|