Skip to content

dizzy.generators.lib_python_uv

dizzy.generators.lib_python_uv

Python-uv runtime generator — generates lib/python-uv/ package structure.

DIZZY_GIT_URL = 'https://github.com/PNNL/dizzy' module-attribute

Where a generated workspace gets DIZZY from.

DIZZY is not published to a package index, by decision. A bare dizzy requirement would resolve to an unrelated project of the same name, so the generated workspace always names a source explicitly — git by default, or a local checkout via --dizzy-source.

render_element_pyproject_toml(kind, name)

Element package manifest — depends on the gen_def/gen_int workspace packages.

The implementation module lives at src/<name>.py and is shipped as the top-level module <name> ([tool.hatch.build] strips the src prefix).

Source code in dizzy/src/dizzy/generators/lib_python_uv.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
def render_element_pyproject_toml(kind: str, name: str) -> str:
    """Element package manifest — depends on the gen_def/gen_int workspace packages.

    The implementation module lives at ``src/<name>.py`` and is shipped as the
    top-level module ``<name>`` (``[tool.hatch.build]`` strips the ``src`` prefix).
    """
    return "\n".join(
        [
            "[project]",
            f'name = "{kind}-{name}"',
            'version = "0.1.0"',
            'requires-python = ">=3.11"',
            "dependencies = [",
            '    "gen_def",',
            '    "gen_int",',
            "]",
            "",
            "[tool.uv.sources]",
            "gen_def = { workspace = true }",
            "gen_int = { workspace = true }",
            "",
            "[build-system]",
            'requires = ["hatchling"]',
            'build-backend = "hatchling.build"',
            "",
            "[tool.hatch.build.targets.wheel]",
            'sources = ["src"]',
            f'include = ["src/{name}.py"]',
            "",
        ]
    )

render_workspace_pyproject_toml(members, include_wiring=False, dizzy_source=None)

The uv workspace manifest.

include_wiring adds the generated wiring package, which dizzy generate wiring emits as a fourth stage. It is opt-in because listing a member that has not been generated makes the whole workspace unresolvable. It also brings the DIZZY dependency with it, so the source below is written only alongside the package that actually needs it.

dizzy_source overrides where DIZZY comes from: a checkout path (the usual case when the generated lib lives inside the repository that generated it) or a git URL. The default is the canonical repository, because DIZZY is not published to an index.

Source code in dizzy/src/dizzy/generators/lib_python_uv.py
 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
def render_workspace_pyproject_toml(
    members: list[tuple[str, str]],
    include_wiring: bool = False,
    dizzy_source: str | None = None,
) -> str:
    """The uv workspace manifest.

    *include_wiring* adds the generated wiring package, which `dizzy generate
    wiring` emits as a fourth stage. It is opt-in because listing a member that
    has not been generated makes the whole workspace unresolvable. It also
    brings the DIZZY dependency with it, so the source below is written only
    alongside the package that actually needs it.

    *dizzy_source* overrides where DIZZY comes from: a checkout path (the usual
    case when the generated lib lives inside the repository that generated it)
    or a git URL. The default is the canonical repository, because DIZZY is not
    published to an index.
    """
    all_members = _TYPE_PACKAGE_MEMBERS + [f"{kind}/{name}" for kind, name in members]
    if include_wiring:
        all_members.append("wiring")
    member_lines = "\n".join(f'  "{member}",' for member in all_members)
    lines = [
        "[tool.uv.workspace]",
        "members = [",
        member_lines,
        "]",
        "",
    ]
    if include_wiring:
        # The wiring package is the one that depends on DIZZY itself. The source
        # goes at the workspace ROOT so it applies to every member, which keeps
        # the wiring package's own manifest portable.
        lines += [
            "[tool.uv.sources]",
            _dizzy_source_entry(dizzy_source),
            "",
        ]
    return "\n".join(lines)