|
7 | 7 | | `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use |
|
8 | 8 | | `version` | `str` | `None` | Current version. Example: "0.1.2" |
|
9 | 9 | | `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] |
|
| 10 | +| `version_provider` | `str` | `commitizen` | Version provider used to read and write version [See more](#version-providers) | |
10 | 11 | | `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] |
|
11 | 12 | | `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` |
|
12 | 13 | | `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. |
|
@@ -112,6 +113,54 @@ commitizen:
|
112 | 113 | - fg:#858585 italic
|
113 | 114 | ```
|
114 | 115 |
|
| 116 | +## Version providers |
| 117 | +
|
| 118 | +Commitizen can read and write version from different sources. |
| 119 | +By default, it use the `commitizen` one which is using the `version` field from the commitizen settings. |
| 120 | +But you can use any `commitizen.provider` entrypoint as value for `version_provider`. |
| 121 | + |
| 122 | +### Custom version provider |
| 123 | + |
| 124 | +You can add you own version provider by extending `VersionProvider` and exposing it on the `commitizen.provider` entrypoint. |
| 125 | + |
| 126 | +Here a quick example of a `my-provider` provider reading and writing version in a `VERSION` file. |
| 127 | + |
| 128 | +`my_provider.py` |
| 129 | + |
| 130 | +```python |
| 131 | +from pathlib import Path |
| 132 | +from commitizen.providers import VersionProvider |
| 133 | +
|
| 134 | +
|
| 135 | +class MyProvider(VersionProvider): |
| 136 | + file = Path() / "VERSION" |
| 137 | +
|
| 138 | + def get_version(self) -> str: |
| 139 | + return self.file.read_text() |
| 140 | +
|
| 141 | + def set_version(self, version: str): |
| 142 | + self.file.write_text(version) |
| 143 | +
|
| 144 | +``` |
| 145 | + |
| 146 | +`setup.py` |
| 147 | + |
| 148 | +```python |
| 149 | +from setuptools import setup |
| 150 | +
|
| 151 | +setup( |
| 152 | + name='my-commitizen-provider', |
| 153 | + version='0.1.0', |
| 154 | + py_modules=['my_provider'], |
| 155 | + install_requires=['commitizen'], |
| 156 | + entry_points = { |
| 157 | + 'commitizen.provider': [ |
| 158 | + 'my-provider = my_provider:MyProvider', |
| 159 | + ] |
| 160 | + } |
| 161 | +) |
| 162 | +``` |
| 163 | + |
115 | 164 | [version_files]: bump.md#version_files
|
116 | 165 | [tag_format]: bump.md#tag_format
|
117 | 166 | [bump_message]: bump.md#bump_message
|
|
0 commit comments