hatchling_plugin
gitversioned.plugins.hatchling_plugin ¶
Hatchling version source plugin for GitVersioned.
This module provides the Hatchling plugin interface to dynamically resolve project versions from Git state. It bridges Hatch's versioning configuration with GitVersioned's core version resolution and file generation engine.
GitVersionedVersionSource ¶
Bases: VersionSourceInterface
Hatchling version source interface for GitVersioned.
This class provides the implementation for the Hatchling version source plugin interface, allowing projects using Hatchling to dynamically resolve their versions via GitVersioned. It handles version resolution, manual version setting, and project metadata extraction.
.. code-block:: python
source = GitVersionedVersionSource(root_dir, config)
version_data = source.get_version_data()
Attributes:
| Name | Type | Description |
|---|---|---|
PLUGIN_NAME | str | The registered name of the plugin within the Hatchling ecosystem |
Source code in src/gitversioned/plugins/hatchling_plugin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 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 | |
get_package_name() ¶
Retrieves the normalized package name from project metadata.
Extracts the project name from the Hatchling metadata and normalizes it by replacing hyphens with underscores.
.. code-block:: python
name = source.get_package_name()
Returns:
| Type | Description |
|---|---|
str | The normalized package name |
Source code in src/gitversioned/plugins/hatchling_plugin.py
get_project_root() ¶
Resolves the absolute path to the project root directory.
.. code-block:: python
root = source.get_project_root()
Returns:
| Type | Description |
|---|---|
Path | The resolved absolute path to the project root |
Source code in src/gitversioned/plugins/hatchling_plugin.py
get_settings_kwargs() ¶
Extracts and prepares the configuration settings for GitVersioned.
Gathers the project root, package name, source root, and plugin configuration from the Hatchling environment to construct the GitVersioned settings.
.. code-block:: python
kwargs = source.get_settings_kwargs()
settings = Settings(**kwargs)
Returns:
| Type | Description |
|---|---|
dict[str, Any] | A dictionary of keyword arguments for configuring GitVersioned |
Source code in src/gitversioned/plugins/hatchling_plugin.py
get_src_root() ¶
Determines the source root directory for the project.
Resolves the source directory by checking explicit plugin configuration, Hatchling build targets, or falling back to standard repository layouts like 'src/package_name' or 'package_name'.
.. code-block:: python
src_root = source.get_src_root()
Returns:
| Type | Description |
|---|---|
Path | The resolved path to the source root directory |
Source code in src/gitversioned/plugins/hatchling_plugin.py
get_version_data() ¶
Computes the project version from Git state.
Resolves the version using the Git repository, build environment, and combined configuration context, optionally generating a version file if configured.
.. code-block:: python
data = source.get_version_data()
version = data["version"]
Returns:
| Type | Description |
|---|---|
dict[str, str] | A dictionary containing the resolved version string under the 'version' key |
Raises:
| Type | Description |
|---|---|
ValueError | If the version resolution process fails |
Source code in src/gitversioned/plugins/hatchling_plugin.py
set_version(version, version_data) ¶
Handler for manual version setting via the Hatch CLI.
This method updates the configured version source file with the explicitly provided version, making it the new persistent version source.
.. code-block:: python
source.set_version("1.2.3", {})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version | str | The raw version string passed by the user | required |
version_data | dict[str, Any] | Additional version data context from Hatchling | required |
Source code in src/gitversioned/plugins/hatchling_plugin.py
hatch_register_version_source() ¶
Register the GitVersioned source plugin with Hatchling.
Provides the entry point for Hatchling to discover and load the GitVersionedVersionSource plugin implementation.
.. code-block:: python
plugin_class = hatch_register_version_source()
Returns:
| Type | Description |
|---|---|
type[VersionSourceInterface] | The class representing the plugin interface |