hatch-vcs icon indicating copy to clipboard operation
hatch-vcs copied to clipboard

[Feature Request] Allow specifying a custom version scheme

Open dhirschfeld opened this issue 1 year ago • 16 comments

In setuptools_scm you can supply a callable (ScmVersion) -> str

image

https://setuptools-scm.readthedocs.io/en/latest/config/#configuration-parameters

However, it appears that the only way to use a custom callable is by defining it in setup.py and passing it to setup via the use_scm_version parameter:

image

https://setuptools-scm.readthedocs.io/en/latest/customizing/

If I add a dummy setup.py which defined a myversion_func and specify it in my pyproject.toml as:

[tool.hatch.version.raw-options]
version_scheme = "myversion_func"

hatch apppears to not pick it up:

❯ hatch version
Traceback (most recent call last):
  File "C:\python\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "<snip>\lib\site-packages\hatchling\__main__.py", line 6, in <module>
    sys.exit(hatchling())
  File "<snip>\lib\site-packages\hatchling\cli\__init__.py", line 26, in hatchling
    command(**kwargs)
  File "<snip>\lib\site-packages\hatchling\cli\version\__init__.py", line 29, in version_impl
    version_data = source.get_version_data()
  File "<snip>\lib\site-packages\hatch_vcs\version_source.py", line 70, in get_version_data
    version = get_version(**self.construct_setuptools_scm_config())
  File "<snip>\lib\site-packages\setuptools_scm\_get_version_impl.py", line 155, in get_version
    maybe_version = _get_version(config, force_write_version_files=True)
  File "<snip>\lib\site-packages\setuptools_scm\_get_version_impl.py", line 96, in _get_version
    version_string = _format_version(parsed_version)
  File "<snip>\lib\site-packages\setuptools_scm\version.py", line 435, in format_version
    assert main_version is not None
AssertionError

Is there any way with hatch-vcs to use a custom version format?

dhirschfeld avatar Nov 17 '23 15:11 dhirschfeld