API Reference¶
Config reference¶
Generated from add_config_value()
registrations in
sphinx_vite_builder/__init__.py.
PEP 517 backend¶
-
sphinx_vite_builder.build.build_wheel(wheel_directory, config_settings=None, metadata_directory=None)¶sphinx_vite_builder.build.build_wheel(wheel_directory, config_settings=None, metadata_directory=None)¶
PEP 517
build_wheel: vite-build, then hatchling-pack.Examples
With
SPHINX_VITE_BUILDER_SKIP=1set, the hook short-circuits vite and delegates straight tohatchling.buildagainst a minimal synthetic project, producing a real.whl:>>> import os, pathlib, tempfile, textwrap >>> os.environ["SPHINX_VITE_BUILDER_SKIP"] = "1" >>> cwd = os.getcwd() >>> with tempfile.TemporaryDirectory() as tmp: ... project = pathlib.Path(tmp) ... _ = (project / "pyproject.toml").write_text(textwrap.dedent(''' ... [build-system] ... requires = ["hatchling"] ... build-backend = "hatchling.build" ... [project] ... name = "doctest-pkg" ... version = "0.0.0" ... ''').lstrip()) ... pkg = project / "doctest_pkg" ... pkg.mkdir() ... _ = (pkg / "__init__.py").write_text("") ... dist = project / "dist" ... dist.mkdir() ... os.chdir(project) ... try: ... name = build_wheel(str(dist)) ... finally: ... os.chdir(cwd) ... del os.environ["SPHINX_VITE_BUILDER_SKIP"] >>> name.endswith(".whl") True
-
sphinx_vite_builder.build.build_editable(wheel_directory, config_settings=None, metadata_directory=None)¶sphinx_vite_builder.build.build_editable(wheel_directory, config_settings=None, metadata_directory=None)¶
PEP 660
build_editable: vite-build, then hatchling-pack-editable.The delegation pattern matches
build_wheel(); see that function’s docstring for an end-to-end example exercising theSPHINX_VITE_BUILDER_SKIP=1short-circuit.Examples
>>> import inspect >>> sorted(inspect.signature(build_editable).parameters) ['config_settings', 'metadata_directory', 'wheel_directory']
-
sphinx_vite_builder.build.build_sdist(sdist_directory, config_settings=None)¶sphinx_vite_builder.build.build_sdist(sdist_directory, config_settings=None)¶
PEP 517
build_sdist: pre-bake static so the sdist→wheel chain works.Running vite at sdist-build time means the resulting
.tar.gzcontains a populatedstatic/tree (even though the source repo gitignores it). Downstream consumers can thenpip installfrom the sdist without pnpm or Node — the wheel-from-sdist build will skip vite (noweb/in the unpacked tree) and ship the pre-baked assets via hatchling’s normal file selection.The delegation pattern matches
build_wheel(); see that function’s docstring for an end-to-end example exercising theSPHINX_VITE_BUILDER_SKIP=1short-circuit.Examples
>>> import inspect >>> sorted(inspect.signature(build_sdist).parameters) ['config_settings', 'sdist_directory']
Hatchling hook¶
-
class sphinx_vite_builder.hatch_plugin.ViteBuildHook¶class sphinx_vite_builder.hatch_plugin.ViteBuildHook¶
Bases:
BuildHookInterface[Any]Run
pnpm exec vite buildbefore each hatchling build target.Activated via
[tool.hatch.build.hooks.vite]in a consumer’spyproject.toml; the table key (vite) must matchPLUGIN_NAMEso hatchling can route the config block.Examples
The class declares the canonical
PLUGIN_NAMEhatchling looks up when matching[tool.hatch.build.hooks.<name>]to a discovered hook. The name is part of the public contract — changing it would break existing consumerpyproject.tomlconfigurations.>>> ViteBuildHook.PLUGIN_NAME 'vite'
-
sphinx_vite_builder.hatch_plugin.hatch_register_build_hook()¶sphinx_vite_builder.hatch_plugin.hatch_register_build_hook()¶
Hatchling plugin entry point.
Discovered via the
[project.entry-points.hatch] vite = ...registration in this package’spyproject.toml. Returns hook classes (not instances); hatchling instantiates them per build.Examples
The function returns exactly one hook class so the
[tool.hatch.build.hooks.vite]table key resolves toViteBuildHook:>>> hooks = hatch_register_build_hook() >>> [hook.PLUGIN_NAME for hook in hooks] ['vite']
Diagnostic errors¶
-
class sphinx_vite_builder._internal.errors.SphinxViteBuilderError¶class sphinx_vite_builder._internal.errors.SphinxViteBuilderError¶
Bases:
ExceptionBase class for all sphinx-vite-builder-raised diagnostic errors.
-
class sphinx_vite_builder._internal.errors.PnpmMissingError¶class sphinx_vite_builder._internal.errors.PnpmMissingError¶
Bases:
SphinxViteBuilderErrorRaised when
pnpmis not onPATH.pnpm is not pip-installable, so the backend cannot bootstrap it the way maturin bootstraps Rust via
puccinialin. The hint surfaces the canonical install paths (corepack enable, the pnpm.io install URL) so the user has an actionable next step.
-
class sphinx_vite_builder._internal.errors.NodeModulesInstallError¶class sphinx_vite_builder._internal.errors.NodeModulesInstallError¶
Bases:
SphinxViteBuilderErrorRaised when
pnpm installexits non-zero.Surfaces the install command that failed and a re-run recipe. Callers should attach the captured stderr to the message before raising so the underlying pnpm diagnostic is visible at the call site.
-
class sphinx_vite_builder._internal.errors.ViteFailedError¶class sphinx_vite_builder._internal.errors.ViteFailedError¶
Bases:
SphinxViteBuilderErrorRaised when
pnpm exec vite buildexits non-zero.Surfaces the vite invocation that failed plus context (cwd, exit code). Callers should attach the captured stderr.