版本源插件¶
已知的第三方插件¶
- hatch-vcs - 使用您首选的版本控制系统(如 Git)
- hatch-nodejs-version - 使用 NodeJS
package.json
文件中的version
字段 - hatch-regex-commit - 自动创建 Git 提交和标签,以实现版本增量
- versioningit - 根据 Git 或 Mercurial 标签确定版本,支持可定制的版本格式
VersionSourceInterface
¶
Example usage:
from hatchling.version.source.plugin.interface import VersionSourceInterface
class SpecialVersionSource(VersionSourceInterface):
PLUGIN_NAME = 'special'
...
from hatchling.plugin import hookimpl
from .plugin import SpecialVersionSource
@hookimpl
def hatch_register_version_source():
return SpecialVersionSource
Source code in backend/src/hatchling/version/source/plugin/interface.py
class VersionSourceInterface(ABC): # no cov
"""
Example usage:
```python tab="plugin.py"
from hatchling.version.source.plugin.interface import VersionSourceInterface
class SpecialVersionSource(VersionSourceInterface):
PLUGIN_NAME = 'special'
...
```
```python tab="hooks.py"
from hatchling.plugin import hookimpl
from .plugin import SpecialVersionSource
@hookimpl
def hatch_register_version_source():
return SpecialVersionSource
```
"""
PLUGIN_NAME = ''
"""The name used for selection."""
def __init__(self, root: str, config: dict) -> None:
self.__root = root
self.__config = config
@property
def root(self) -> str:
"""
The root of the project tree as a string.
"""
return self.__root
@property
def config(self) -> dict:
"""
```toml config-example
[tool.hatch.version]
```
"""
return self.__config
@abstractmethod
def get_version_data(self) -> dict:
"""
This should return a mapping with a `version` key representing the current version of the project and will be
displayed when invoking the [`version`](../../cli/reference.md#hatch-version) command without any arguments.
The mapping can contain anything else and will be passed to
[set_version](reference.md#hatchling.version.source.plugin.interface.VersionSourceInterface.set_version)
when updating the version.
"""
def set_version(self, version: str, version_data: dict) -> None:
"""
This should update the version to the first argument with the data provided during retrieval.
"""
raise NotImplementedError
PLUGIN_NAME = ''
class-attribute
instance-attribute
¶
The name used for selection.
root: str
property
¶
The root of the project tree as a string.
config: dict
property
¶
[tool.hatch.version]
[version]
get_version_data() -> dict
abstractmethod
¶
This should return a mapping with a version
key representing the current version of the project and will be displayed when invoking the version
command without any arguments.
The mapping can contain anything else and will be passed to set_version when updating the version.
Source code in backend/src/hatchling/version/source/plugin/interface.py
@abstractmethod
def get_version_data(self) -> dict:
"""
This should return a mapping with a `version` key representing the current version of the project and will be
displayed when invoking the [`version`](../../cli/reference.md#hatch-version) command without any arguments.
The mapping can contain anything else and will be passed to
[set_version](reference.md#hatchling.version.source.plugin.interface.VersionSourceInterface.set_version)
when updating the version.
"""
set_version(version: str, version_data: dict) -> None
¶
This should update the version to the first argument with the data provided during retrieval.
Source code in backend/src/hatchling/version/source/plugin/interface.py
def set_version(self, version: str, version_data: dict) -> None:
"""
This should update the version to the first argument with the data provided during retrieval.
"""
raise NotImplementedError