Skip to content

gitversioned.plugins.maturin_plugin

Maturin build backend wrapper for GitVersioned.

This module implements PEP 517 and PEP 660 build backend hooks to integrate dynamic version resolution into Rust-based Python packages. When a build frontend (such as pip or build) invokes this backend, the wrapper calculates the project version using Git repository metadata and configuration, updates Cargo.toml if necessary, and then invokes the corresponding Maturin backend hook to compile and package the project.

The main interfaces correspond to PEP 517/660 hooks, which automatically locate, configure, and invoke the underlying maturin implementation while transparently managing the logging setup and build environment configuration.

build_editable(wheel_directory, config_settings=None, metadata_directory=None)

Build an editable wheel, delegating to maturin.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

path = maturin_plugin.build_editable("dist/")

:param wheel_directory: Directory where the editable wheel should be written. :param config_settings: Configuration options passed by the build frontend. :param metadata_directory: Optional directory containing pre-built metadata. :returns: The filename of the built editable wheel. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def build_editable(
    wheel_directory: str,
    config_settings: dict[str, Any] | None = None,
    metadata_directory: str | None = None,
) -> str:
    """
    Build an editable wheel, delegating to maturin.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        path = maturin_plugin.build_editable("dist/")

    :param wheel_directory: Directory where the editable wheel
        should be written.
    :param config_settings: Configuration options passed by the
        build frontend.
    :param metadata_directory: Optional directory containing
        pre-built metadata.
    :returns: The filename of the built editable wheel.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().build_editable(
        wheel_directory,
        config_settings=config_settings,
        metadata_directory=metadata_directory,
    )

build_sdist(sdist_directory, config_settings=None)

Build a source distribution (sdist), delegating packaging to maturin.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

path = maturin_plugin.build_sdist("dist/")

:param sdist_directory: Directory where the constructed sdist should be written. :param config_settings: Configuration options passed by the build frontend. :returns: The filename of the built sdist. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def build_sdist(
    sdist_directory: str,
    config_settings: dict[str, Any] | None = None,
) -> str:
    """
    Build a source distribution (sdist), delegating packaging to maturin.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        path = maturin_plugin.build_sdist("dist/")

    :param sdist_directory: Directory where the constructed sdist
        should be written.
    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: The filename of the built sdist.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().build_sdist(
        sdist_directory,
        config_settings=config_settings,
    )

build_wheel(wheel_directory, config_settings=None, metadata_directory=None)

Build a wheel, delegating compilation and packaging to maturin.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

path = maturin_plugin.build_wheel("dist/")

:param wheel_directory: Directory where the constructed wheel should be written. :param config_settings: Configuration options passed by the build frontend. :param metadata_directory: Optional directory containing pre-built metadata. :returns: The filename of the built wheel. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def build_wheel(
    wheel_directory: str,
    config_settings: dict[str, Any] | None = None,
    metadata_directory: str | None = None,
) -> str:
    """
    Build a wheel, delegating compilation and packaging to maturin.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        path = maturin_plugin.build_wheel("dist/")

    :param wheel_directory: Directory where the constructed wheel
        should be written.
    :param config_settings: Configuration options passed by the
        build frontend.
    :param metadata_directory: Optional directory containing
        pre-built metadata.
    :returns: The filename of the built wheel.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().build_wheel(
        wheel_directory,
        config_settings=config_settings,
        metadata_directory=metadata_directory,
    )

get_requires_for_build_editable(config_settings=None)

Get additional packages required to build an editable wheel.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

reqs = maturin_plugin.get_requires_for_build_editable()

:param config_settings: Configuration options passed by the build frontend. :returns: A list of dependency specification strings. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def get_requires_for_build_editable(
    config_settings: dict[str, Any] | None = None,
) -> list[str]:
    """
    Get additional packages required to build an editable wheel.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        reqs = maturin_plugin.get_requires_for_build_editable()

    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: A list of dependency specification strings.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().get_requires_for_build_editable(
        config_settings=config_settings
    )

get_requires_for_build_sdist(config_settings=None)

Get additional packages required to build a source distribution (sdist).

.. code-block:: python

from gitversioned.plugins import maturin_plugin

reqs = maturin_plugin.get_requires_for_build_sdist()

:param config_settings: Configuration options passed by the build frontend. :returns: A list of dependency specification strings. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def get_requires_for_build_sdist(
    config_settings: dict[str, Any] | None = None,
) -> list[str]:
    """
    Get additional packages required to build a source distribution (sdist).

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        reqs = maturin_plugin.get_requires_for_build_sdist()

    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: A list of dependency specification strings.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().get_requires_for_build_sdist(config_settings=config_settings)

get_requires_for_build_wheel(config_settings=None)

Get additional packages required to build a wheel.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

reqs = maturin_plugin.get_requires_for_build_wheel()

:param config_settings: Configuration options passed by the build frontend. :returns: A list of dependency specification strings. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def get_requires_for_build_wheel(
    config_settings: dict[str, Any] | None = None,
) -> list[str]:
    """
    Get additional packages required to build a wheel.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        reqs = maturin_plugin.get_requires_for_build_wheel()

    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: A list of dependency specification strings.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().get_requires_for_build_wheel(config_settings=config_settings)

prepare_metadata_for_build_editable(metadata_directory, config_settings=None)

Prepare the dist-info metadata directory for an editable wheel build.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

path = maturin_plugin.prepare_metadata_for_build_editable("metadata/")

:param metadata_directory: Directory where the metadata should be written. :param config_settings: Configuration options passed by the build frontend. :returns: The basename of the metadata directory. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def prepare_metadata_for_build_editable(
    metadata_directory: str,
    config_settings: dict[str, Any] | None = None,
) -> str:
    """
    Prepare the dist-info metadata directory for an editable wheel build.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        path = maturin_plugin.prepare_metadata_for_build_editable("metadata/")

    :param metadata_directory: Directory where the metadata should
        be written.
    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: The basename of the metadata directory.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().prepare_metadata_for_build_editable(
        metadata_directory,
        config_settings=config_settings,
    )

prepare_metadata_for_build_wheel(metadata_directory, config_settings=None)

Prepare the dist-info metadata directory for a wheel build.

.. code-block:: python

from gitversioned.plugins import maturin_plugin

path = maturin_plugin.prepare_metadata_for_build_wheel("metadata/")

:param metadata_directory: Directory where the metadata should be written. :param config_settings: Configuration options passed by the build frontend. :returns: The basename of the metadata directory. :raises ImportError: If the maturin package is not installed.

Source code in src/gitversioned/plugins/maturin_plugin.py
def prepare_metadata_for_build_wheel(
    metadata_directory: str,
    config_settings: dict[str, Any] | None = None,
) -> str:
    """
    Prepare the dist-info metadata directory for a wheel build.

    .. code-block:: python

        from gitversioned.plugins import maturin_plugin

        path = maturin_plugin.prepare_metadata_for_build_wheel("metadata/")

    :param metadata_directory: Directory where the metadata should
        be written.
    :param config_settings: Configuration options passed by the
        build frontend.
    :returns: The basename of the metadata directory.
    :raises ImportError: If the maturin package is not installed.
    """
    return _get_maturin().prepare_metadata_for_build_wheel(
        metadata_directory,
        config_settings=config_settings,
    )