nskit.mixer
Components¶
nskit.mixer.components.file.File
¶
Bases: FileSystemObject
File component.
Source code in src/nskit/mixer/components/file.py
dryrun(base_path, context, override_path=None)
¶
Preview the file contents using the context.
Source code in src/nskit/mixer/components/file.py
render_content(context)
¶
Return the rendered content using the context and the Jinja environment.
Source code in src/nskit/mixer/components/file.py
validate(base_path, context, override_path=None)
¶
Validate the output against expected.
Source code in src/nskit/mixer/components/file.py
write(base_path, context, override_path=None)
¶
Write the rendered content to the appropriate path within the base_path.
Source code in src/nskit/mixer/components/file.py
nskit.mixer.components.folder.Folder
¶
Bases: FileSystemObject
Folder component.
Source code in src/nskit/mixer/components/folder.py
__getitem__(name_or_id)
¶
__setitem__(name_or_id, value)
¶
Set an item by name or id.
dryrun(base_path, context, override_path=None)
¶
Preview the file contents using the context.
Source code in src/nskit/mixer/components/folder.py
index(name_or_id)
¶
Get the index of a specific file or folder given the name (or ID).
Source code in src/nskit/mixer/components/folder.py
validate(base_path, context, override_path=None)
¶
Validate the output against expected.
Source code in src/nskit/mixer/components/folder.py
write(base_path, context, override_path=None)
¶
Write the rendered content to the appropriate path within the base_path.
Source code in src/nskit/mixer/components/folder.py
nskit.mixer.components.recipe.Recipe
¶
Bases: Folder
The base Recipe object.
A Recipe is a folder, with additional methods for handling context for the Jinja templating.
It also includes hooks that can be run before rendering (pre-hooks) e.g. checking or changing values,
and after (post-hooks) e.g. running post-generation steps.
Source code in src/nskit/mixer/components/recipe.py
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
name = Field(None, validate_default=True, description='The repository name')
class-attribute
instance-attribute
¶
version = Field(None, description='The recipe version')
class-attribute
instance-attribute
¶
contents = Field(default_factory=list, description='The folder contents')
class-attribute
instance-attribute
¶
pre_hooks = Field(default_factory=list, validate_default=True, description='Hooks that can be used to modify a recipe path and context before writing')
class-attribute
instance-attribute
¶
post_hooks = Field(default_factory=list, validate_default=True, description='Hooks that can be used to modify a recipe path and context after writing')
class-attribute
instance-attribute
¶
extension_name = Field(None, description='The name of the recipe as an extension to load.')
class-attribute
instance-attribute
¶
context
property
¶
Get the context on the initialised recipe.
create(base_path=None, override_path=None, **additional_context)
¶
Create the recipe.
Use the configured parameters and any additional context as kwargs to create the recipe at the base path (or current directory if not provided).
Source code in src/nskit/mixer/components/recipe.py
dryrun(base_path=None, override_path=None, **additional_context)
¶
See the recipe as a dry run.
Source code in src/nskit/mixer/components/recipe.py
validate(base_path=None, override_path=None, **additional_context)
¶
Validate the created repo.
Source code in src/nskit/mixer/components/recipe.py
load(recipe_name, entrypoint=None, initialize=True, **kwargs)
staticmethod
¶
Load a recipe as an extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_name
|
str
|
Name of the recipe to load |
required |
entrypoint
|
Optional[str]
|
Recipe entrypoint to use (defaults to RECIPE_ENTRYPOINT) |
None
|
initialize
|
bool
|
Whether to initialize the recipe instance (default True) |
True
|
**kwargs
|
Arguments to pass to recipe initialization |
{}
|
Returns:
| Type | Description |
|---|---|
|
Recipe instance if initialize=True, otherwise recipe class |
Source code in src/nskit/mixer/components/recipe.py
inspect(recipe_name, entrypoint=None, include_private=False, include_folder=False, include_base=False)
staticmethod
¶
Get the fields on a recipe as an extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_name
|
str
|
Name of the recipe to inspect |
required |
entrypoint
|
Optional[str]
|
Recipe entrypoint to use (defaults to RECIPE_ENTRYPOINT) |
None
|
include_private
|
bool
|
Include private fields |
False
|
include_folder
|
bool
|
Include folder fields |
False
|
include_base
|
bool
|
Include base recipe fields |
False
|
Returns:
| Type | Description |
|---|---|
|
Signature of the recipe |
Source code in src/nskit/mixer/components/recipe.py
nskit.mixer.components.recipe.RecipeField(default=..., *, env_var=None, template=None, prompt_text=None, display_name=None, help_text=None, options=None, options_provider=None, default_provider=None, conditional_rules=None, description=None, **kwargs)
¶
Convenience wrapper around pydantic.Field for recipe fields.
Packs interactive metadata into json_schema_extra so it is available
for FieldParser.from_recipe_model() introspection without affecting
Pydantic validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Any
|
Default value for the field. |
...
|
env_var
|
Optional[str]
|
Environment variable name for default resolution. |
None
|
template
|
Optional[str]
|
Jinja2 template expression for derived defaults. |
None
|
prompt_text
|
Optional[str]
|
Custom prompt text for interactive collection. |
None
|
display_name
|
Optional[str]
|
Human-readable field name for UI prompting. |
None
|
help_text
|
Optional[str]
|
Additional help text shown alongside the prompt. |
None
|
options
|
Optional[list[str]]
|
Available choices for enum-type fields. |
None
|
options_provider
|
Optional[str]
|
Named provider for dynamically resolved options.
The |
None
|
default_provider
|
Optional[str]
|
Named provider for dynamically resolved defaults.
The |
None
|
conditional_rules
|
Optional[list[dict]]
|
Rules controlling field visibility. Each may use the
structured |
None
|
description
|
Optional[str]
|
Description of the field's purpose. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
FieldInfo
|
A Pydantic |
Source code in src/nskit/mixer/components/recipe.py
nskit.mixer.components.hook.Hook
¶
Bases: ABC, BaseModel
Hook component.
Hooks receive the recipe path and context, and optionally the recipe
instance itself. The recipe kwarg enables pre-write hooks to mutate
the recipe's contents before rendering.
Backwards-compatible: existing hooks that define
call(self, recipe_path, context) without **kwargs continue to work —
the recipe kwarg is only forwarded if the hook's call signature accepts it.
Source code in src/nskit/mixer/components/hook.py
__call__(recipe_path, context, **kwargs)
¶
Call the hook and return tuple (recipe_path, context).
Inspects the call method signature to determine whether to forward
kwargs (like recipe). This ensures backwards compatibility with
existing hooks that only accept (recipe_path, context).
Source code in src/nskit/mixer/components/hook.py
call(recipe_path, context, **kwargs)
abstractmethod
¶
Execute the hook logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path where the recipe will be (pre) or was (post) written. |
required |
context
|
dict[str, Any]
|
Template rendering context (all recipe fields + properties). |
required |
**kwargs
|
Additional keyword arguments. Currently passes |
{}
|
Returns:
| Type | Description |
|---|---|
Optional[tuple[Path, dict]]
|
None to keep path/context unchanged, or |
Source code in src/nskit/mixer/components/hook.py
nskit.mixer.components.license_file.LicenseFile
¶
Bases: File
License File created by downloading from Github.
Source code in src/nskit/mixer/components/license_file.py
nskit.mixer.components.license_file.LicenseOptionsEnum
¶
Bases: Enum
License Options for the license file.
Built from Github API licenses.get_all_commonly_used.
Source code in src/nskit/mixer/components/license_file.py
contains(value)
classmethod
¶
Return True if value is in cls.
BACKPORT FROM PYTHON 3.12
value is in cls if:
1) value is a member of cls, or
2) value is the value of one of the cls's members.
Source code in src/nskit/mixer/components/license_file.py
Repo Metadata¶
nskit.mixer.repo.CodeRecipe
¶
Bases: Recipe
Recipe for a (git) code repo.
Language-agnostic: includes a default git init hook only. Language-specific
recipes (e.g. PyRecipe) extend post_hooks with their own tooling
(such as pre-commit installation) and set language accordingly.
Source code in src/nskit/mixer/repo.py
nskit.mixer.repo.RepoMetadata
¶
Bases: BaseConfiguration
Repository/package metadata information.
Source code in src/nskit/mixer/repo.py
Hooks¶
nskit.mixer.hooks.git.GitInit
¶
Bases: Hook
Git Hook to (re) initialise a repo.
Source code in src/nskit/mixer/hooks/git.py
call(recipe_path, context)
¶
(re)initialise the repo.
Source code in src/nskit/mixer/hooks/git.py
nskit.mixer.hooks.pre_commit.PrecommitInstall
¶
Bases: Hook
Precommit install hook.
Source code in src/nskit/mixer/hooks/pre_commit.py
call(recipe_path, context)
¶
Run the pre-commit install and install hooks command.
Source code in src/nskit/mixer/hooks/pre_commit.py
Utilities¶
nskit.mixer.utilities.Resource
¶
Bases: str
A type for a package resource uri.