Skip to content

nskit.recipes

Recipes for the mixer, using entrypoints to make them available.

nskit.recipes.recipe.RecipeRecipe

Bases: PyRecipe

A Recipe for creating Recipes, meta!

Source code in .venv-docs/lib/python3.12/site-packages/nskit/recipes/recipe.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class RecipeRecipe(PyRecipe):
    """A Recipe for creating Recipes, meta!"""

    recipe_entrypoint: str = RECIPE_ENTRYPOINT
    contents: List[Union[File, Folder]] = Field(
        [
            ingredients.gitignore,
            ingredients.noxfile,
            ingredients.pre_commit,
            recipe_ingredients.pyproject_toml,
            recipe_ingredients.readme_md,
            ingredients.test_dir,
            recipe_ingredients.src_dir,
            ingredients.docs_dir,
            LicenseFile()
        ],
        description='The folder contents')

contents: List[Union[File, Folder]] = Field([ingredients.gitignore, ingredients.noxfile, ingredients.pre_commit, recipe_ingredients.pyproject_toml, recipe_ingredients.readme_md, ingredients.test_dir, recipe_ingredients.src_dir, ingredients.docs_dir, LicenseFile()], description='The folder contents') class-attribute instance-attribute

nskit.recipes.python.api.APIRecipe

Bases: PyRecipe

API Service Recipe.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/recipes/python/api.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class APIRecipe(PyRecipe):
    """API Service Recipe."""

    contents: List[Union[File, Folder]] = Field(
        [
            ingredients.gitignore,
            ingredients.noxfile,
            ingredients.pre_commit,
            api_ingredients.pyproject_toml,
            api_ingredients.readme_md,
            ingredients.test_dir,
            api_ingredients.src_dir,
            api_ingredients.docker.dockerignore,
            api_ingredients.docker.api_dockerfile,
            ingredients.docs_dir,
            LicenseFile()
        ],
        description='The folder contents')

contents: List[Union[File, Folder]] = Field([ingredients.gitignore, ingredients.noxfile, ingredients.pre_commit, api_ingredients.pyproject_toml, api_ingredients.readme_md, ingredients.test_dir, api_ingredients.src_dir, api_ingredients.docker.dockerignore, api_ingredients.docker.api_dockerfile, ingredients.docs_dir, LicenseFile()], description='The folder contents') class-attribute instance-attribute

nskit.recipes.python.package.PackageRecipe

Bases: PyRecipe

Package Recipe.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/recipes/python/package.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class PackageRecipe(PyRecipe):
    """Package Recipe."""

    contents: List[Union[File, Folder]] = Field(
        [
            ingredients.gitignore,
            ingredients.noxfile,
            ingredients.pre_commit,
            ingredients.pyproject_toml,
            ingredients.readme_md,
            ingredients.test_dir,
            ingredients.src_dir,
            ingredients.docs_dir,
            LicenseFile()
        ],
        description='The folder contents')

contents: List[Union[File, Folder]] = Field([ingredients.gitignore, ingredients.noxfile, ingredients.pre_commit, ingredients.pyproject_toml, ingredients.readme_md, ingredients.test_dir, ingredients.src_dir, ingredients.docs_dir, LicenseFile()], description='The folder contents') class-attribute instance-attribute

Python Ingredients

nskit.recipes.python.PyRecipe

Bases: CodeRecipe

Base recipe for python recipes.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/recipes/python/__init__.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class PyRecipe(CodeRecipe):
    """Base recipe for python recipes."""

    version: str = __version__
    """Version of the recipe."""

    repo: PyRepoMetadata = Field(...)
    """Python repo metadata."""

    @staticmethod
    def _to_pep8(value):
        return str(value).lower().replace(' ', '_').replace('-', '_')

    def model_post_init(self, *args):  # noqa: U100
        """Set repo name handling."""
        self.repo.name = self.name

name: str = Field(None, validate_default=True, description='The repository name') class-attribute instance-attribute

version: str = __version__ class-attribute instance-attribute

Version of the recipe.

repo: PyRepoMetadata = Field(...) class-attribute instance-attribute

Python repo metadata.

pre_hooks: List[Hook] = 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: Optional[List[Callable]] = Field([hooks.git.GitInit(), hooks.pre_commit.PrecommitInstall()], validate_default=True, description='Hooks that can be used to modify a recipe path and context after writing') class-attribute instance-attribute

extension_name: Optional[str] = Field(None, description='The name of the recipe as an extension to load.') class-attribute instance-attribute

git: GitConfig = GitConfig() class-attribute instance-attribute

context property

Get the context on the initialised recipe.

recipe_batch property

Get information about the specific info of this recipe.

dryrun(base_path=None, override_path=None, **additional_context)

See the recipe as a dry run.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/mixer/components/recipe.py
133
134
135
136
137
138
139
140
141
142
143
def dryrun(
        self,
        base_path: Optional[Path] = None,
        override_path: Optional[Path] = None,
        **additional_context):
    """See the recipe as a dry run."""
    combined_context = self.context
    combined_context.update(additional_context)
    if base_path is None:
        base_path = Path.cwd()
    return super().dryrun(base_path=base_path, context=combined_context, override_path=override_path)

validate(base_path=None, override_path=None, **additional_context)

Validate the created repo.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/mixer/components/recipe.py
145
146
147
148
149
150
151
152
153
154
155
def validate(
        self,
        base_path: Optional[Path] = None,
        override_path: Optional[Path] = None,
        **additional_context):
    """Validate the created repo."""
    combined_context = self.context
    combined_context.update(additional_context)
    if base_path is None:
        base_path = Path.cwd()
    return super().validate(base_path=base_path, context=combined_context, override_path=override_path)

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 .venv-docs/lib/python3.12/site-packages/nskit/mixer/components/recipe.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def create(self, base_path: Optional[Path] = None, override_path: Optional[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).
    """
    if base_path is None:
        base_path = Path.cwd()
    else:
        base_path = Path(base_path)
    context = self.context
    context.update(additional_context)
    recipe_path = self.get_path(base_path, context, override_path=override_path)
    for hook in self.pre_hooks:
        recipe_path, context = hook(recipe_path, context)
    content = self.write(recipe_path.parent, context, override_path=recipe_path.name)
    recipe_path = list(content.keys())[0]
    for hook in self.post_hooks:
        recipe_path, context = hook(recipe_path, context)
    self._write_batch(Path(recipe_path))
    return {Path(recipe_path): list(content.values())[0]}

load(recipe_name, **kwargs) staticmethod

Load a recipe as an extension.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/mixer/components/recipe.py
157
158
159
160
161
162
163
164
165
@staticmethod
def load(recipe_name: str, **kwargs):
    """Load a recipe as an extension."""
    recipe_klass = load_extension(RECIPE_ENTRYPOINT, recipe_name)
    if recipe_klass is None:
        raise ValueError(f'Recipe {recipe_name} not found, it may be mis-spelt or not installed. Available recipes: {get_extension_names(RECIPE_ENTRYPOINT)}')
    recipe = recipe_klass(**kwargs)
    recipe.extension_name = recipe_name
    return recipe

nskit.recipes.python.PyRepoMetadata

Bases: RepoMetadata

Repo Metadata for python templates.

Source code in .venv-docs/lib/python3.12/site-packages/nskit/recipes/python/__init__.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class PyRepoMetadata(RepoMetadata):
    """Repo Metadata for python templates."""

    _name: str = None

    @property
    def name(self):
        """Get repo name."""
        return self._name

    @name.setter
    def name(self, value):
        """Set repo name."""
        if isinstance(value, str):
            self._name = value

    def _get_name_parts(self):
        return re.split('|'.join(map(re.escape, list(set(_DELIMITERS+[self.repo_separator])))), self.name)

    @property
    def py_name(self):
        """Get python module name."""
        return '.'.join(self._get_name_parts())

    @property
    def py_root(self):
        """Get root python module name."""
        return self._get_name_parts()[0]

    @property
    def src_path(self):
        """Get module folder structure (src not included)."""
        return Path(*self._get_name_parts()).as_posix()

    @property
    def module_depth(self) -> int:
        """Get the module depth.

        ``a.b.c`` has a depth of 3, ``a`` has a depth of 1
        """
        return len(self._get_name_parts())

owner: str = Field(..., description='Who is the owner of the repo') class-attribute instance-attribute

email: EmailStr = Field(..., description='The email for the repo owner') class-attribute instance-attribute

url: HttpUrl = Field(..., description='The Repository url.') class-attribute instance-attribute

name property writable

Get repo name.

py_name property

Get python module name.

py_root property

Get root python module name.

src_path property

Get module folder structure (src not included).

module_depth: int property

Get the module depth.

a.b.c has a depth of 3, a has a depth of 1

nskit.recipes.python.ingredients

Ingredients for repos.

gitignore = File(name='.gitignore', content='nskit.recipes.python.ingredients:gitignore.template') module-attribute

noxfile = File(name='noxfile.py', content='nskit.recipes.python.ingredients:noxfile.py.template') module-attribute

pre_commit = File(name='.pre-commit-config.yaml', content='nskit.recipes.python.ingredients:pre-commit-config.yaml.template') module-attribute

pyproject_toml = File(name='pyproject.toml', content='nskit.recipes.python.ingredients:pyproject.toml.template') module-attribute

readme_md = File(name='README.md', content='nskit.recipes.python.ingredients:readme.md.template') module-attribute

test_dir = Folder(name='tests', contents=[Folder(name='unit', contents=[File(name='test_placeholder.py', content=test_placeholder)]), Folder(name='functional', contents=[File(name='.git-keep', content='')])]) module-attribute

src_dir = Folder(name='src', contents=[Folder(id_='src_path', name='{{repo.src_path}}', contents=[File(name='__init__.py', content='nskit.recipes.python.ingredients:__init__.py.template')])]) module-attribute

nskit.recipes.python.ingredients.api

API Service ingredients.

Contains fastapi based api service ingredients.

pyproject_toml = File(name='pyproject.toml', content='nskit.recipes.python.ingredients.api:pyproject.toml.template') module-attribute

readme_md = File(name='README.md', content='nskit.recipes.python.ingredients.api:readme.md.template') module-attribute

src_dir

Adds app.py, auth.py, server.py, api/__init__.py, base.py to [nskit.recipes.python.ingredients.src_dir]

nskit.recipes.python.ingredients.api.docker

Docker ingredients.

Contains dockerfile, .dockerignore files.

api_dockerfile = File(name='Dockerfile', content='nskit.recipes.python.ingredients.api.docker:api.Dockerfile.template') module-attribute

dockerignore = File(name='.dockerignore', content='nskit.recipes.python.ingredients.api.docker:dockerignore.template') module-attribute

nskit.recipes.python.ingredients.recipe

Ingredients for a recipe recipe.

pyproject_toml = File(name='pyproject.toml', content='nskit.recipes.python.ingredients.recipe:pyproject.toml.template') module-attribute

readme_md = File(name='README.md', content='nskit.recipes.python.ingredients.recipe:readme.md.template') module-attribute

src_dir

Adds recipe.py and ingredient.py.template to [nskit.recipes.python.ingredients.src_dir]