Registry¶
patiencepilot.variants.registry ¶
Variant registry for resolving Solitaire rules by name and options.
VariantFactory ¶
Bases: Protocol
Callable that creates a variant rules object from option values.
Source code in src/patiencepilot/variants/registry.py
17 18 19 20 21 22 | |
__call__ ¶
__call__(options: VariantOptions) -> Variant
Return a variant rules object.
Source code in src/patiencepilot/variants/registry.py
20 21 22 | |
StateOptionsResolver ¶
Bases: Protocol
Callable that extracts variant options from a state.
Source code in src/patiencepilot/variants/registry.py
25 26 27 28 29 30 | |
__call__ ¶
__call__(state: GameState) -> dict[str, object]
Return JSON-compatible variant options for state.
Source code in src/patiencepilot/variants/registry.py
28 29 30 | |
VariantDefinition
dataclass
¶
Registered Solitaire variant plus its option conversion functions.
Source code in src/patiencepilot/variants/registry.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
resolve ¶
resolve(options: VariantOptions | None = None) -> Variant
Return a rules object for this variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
Source code in src/patiencepilot/variants/registry.py
42 43 44 45 46 47 48 | |
VariantRegistry
dataclass
¶
Small immutable registry of supported Solitaire variants.
Source code in src/patiencepilot/variants/registry.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
__post_init__ ¶
__post_init__() -> None
Validate registry keys.
Source code in src/patiencepilot/variants/registry.py
57 58 59 60 61 62 63 64 65 66 | |
register ¶
register(definition: VariantDefinition) -> VariantRegistry
Return a new registry that also contains definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
VariantDefinition
|
Variant definition to add. |
required |
Source code in src/patiencepilot/variants/registry.py
73 74 75 76 77 78 79 | |
definition_for ¶
definition_for(name: str) -> VariantDefinition
Return the registered definition for name or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedVariantError
|
If no variant is registered for |
Source code in src/patiencepilot/variants/registry.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
resolve ¶
resolve(
name: str, options: VariantOptions | None = None
) -> Variant
Return a rules object by variant name and options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. |
required |
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
Source code in src/patiencepilot/variants/registry.py
100 101 102 103 104 105 106 107 | |
options_from_state ¶
options_from_state(state: GameState) -> dict[str, object]
Return registry options that reproduce state rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State whose variant metadata should be converted. |
required |
Source code in src/patiencepilot/variants/registry.py
109 110 111 112 113 114 115 | |
resolve_state ¶
resolve_state(state: GameState) -> Variant
Return rules for the variant metadata stored in state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
Source code in src/patiencepilot/variants/registry.py
117 118 119 120 121 122 123 | |
resolve_variant ¶
resolve_variant(
name: str = KlondikeRules.name,
options: VariantOptions | None = None,
*,
registry: VariantRegistry | None = None,
) -> Variant
Return rules for a registered variant name and options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variant name or alias. Defaults to |
name
|
options
|
VariantOptions | None
|
Variant-specific configuration values. |
None
|
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
resolve_state_variant ¶
resolve_state_variant(
state: GameState,
*,
registry: VariantRegistry | None = None,
) -> Variant
Return rules for the variant metadata stored in state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
142 143 144 145 146 147 148 149 | |
variant_options_from_state ¶
variant_options_from_state(
state: GameState,
*,
registry: VariantRegistry | None = None,
) -> dict[str, object]
Return registry options that reproduce state rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
State containing variant name and option metadata. |
required |
registry
|
VariantRegistry | None
|
Registry to use. Defaults to the package registry. |
None
|
Source code in src/patiencepilot/variants/registry.py
152 153 154 155 156 157 158 159 | |
variant_names ¶
variant_names(
*, registry: VariantRegistry | None = None
) -> tuple[str, ...]
Return canonical names of registered variants.
Source code in src/patiencepilot/variants/registry.py
162 163 164 | |