-
-
Notifications
You must be signed in to change notification settings - Fork 310
Closed
Labels
Description
Description
Projects using version handlers like hatch, which by themselves can have a configurable version handling, it would be great to have a generic CommandProvider.
The commitizen settings should just define which commands to run for getting and setting the version.
Possible Solution
Configure the provider via
[tool.commitizen]
...
version_provider = "command-provider"
provider_get_version = "hatch version" # example for hatch
provider_set_version = "hatch version {version}" # example for hatchSimplified implementation:
from commitizen import cmd
from commitizen.providers import base_provider
class CommandProvider(base_provider.VersionProvider):
"""
Base class for command-based version providers
The commitizen configuration needs to specify the `provider_get_version` and `provider_set_version` script.
The `provider_set_script` command must contain a `{version}` placeholder for the new version.
"""
def get_version(self) -> str:
script = self.config.settings.get("provider_get_script")
if script is None:
msg = "The 'provider_get_script' setting is missing in the commitizen configuration"
raise KeyError(msg)
result = cmd.run(script)
return result.out.strip()
def set_version(self, version: str) -> None:
script = self.config.settings.get("provider_set_script")
if script is None:
msg = "The 'provider_set_script' setting is missing in the commitizen configuration"
raise KeyError(msg)
cmd.run(script.format(version=version))Additional context
No response
Related issues
No response