hatch icon indicating copy to clipboard operation
hatch copied to clipboard

`hatch version` doesn't work on a `setuptools-scm` project unless `hatch-vcs` is installed

Open glyph opened this issue 2 months ago • 15 comments

I get a traceback like this when I try:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/__main__.py", line 6, in <module>
    sys.exit(hatchling())
             ~~~~~~~~~^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/__init__.py", line 26, in hatchling
    command(**kwargs)
    ~~~~~~~^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/version/__init__.py", line 31, in version_impl
    source = metadata.hatch.version.source
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/core.py", line 1503, in source
    raise UnknownPluginError(message)
hatchling.plugin.exceptions.UnknownPluginError: Unknown version source: vcs

see this conversation https://github.com/glyph/automat/commit/643f7ce4ff0dfbe0269d57e0611b24fd5a149d93#r163303552

glyph avatar Oct 02 '25 17:10 glyph

Hey there! So the Hatch version configuration ([tool.hatch.version]) is just for configuring the Hatchling backend i.e. how the version gets sourced for inclusion in distribution metadata. The hatch version command should work with any backend so perhaps just try removing that config section (and of course the hatch-vcs build dependency).

ofek avatar Oct 02 '25 17:10 ofek

Interesting. Let me give that a try…

glyph avatar Oct 02 '25 17:10 glyph

So, when I do that, I get this:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/__main__.py", line 6, in <module>
    sys.exit(hatchling())
             ~~~~~~~~~^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/__init__.py", line 26, in hatchling
    command(**kwargs)
    ~~~~~~~^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/version/__init__.py", line 31, in version_impl
    source = metadata.hatch.version.source
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/core.py", line 1425, in version
    raise ValueError(message)
ValueError: Missing `tool.hatch.version` configuration

Let me upgrade hatch in this venv to see if this is an old bug.

glyph avatar Oct 02 '25 17:10 glyph

Nope, still present on hatch 1.14.2.

To get that second traceback, this is the diff:

diff --git a/pyproject.toml b/pyproject.toml
index 90a03ff..c8450ea 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,6 @@ requires = [
   "setuptools >= 35.0.2",
   "wheel >= 0.29.0",
   "setuptools-scm",
-  "hatch-vcs",
 ]
 build-backend = "setuptools.build_meta"
 
@@ -58,6 +57,3 @@ where = ["src"]
 [tool.setuptools_scm]
 # No configuration required, but the section needs to exist?
 
-[tool.hatch]
-version.source = "vcs"
-

glyph avatar Oct 02 '25 17:10 glyph

@ofek so, I'm pretty sure that tool.hatch.version was specifically added because I started getting errors without it.

glyph avatar Oct 02 '25 17:10 glyph

Okay, it's possible that the old me was weird and treated versioning specially because of the ability to update the version. I bet if you instead used the definitely-agnostic hatch project metadata version command then it would work.

If that doesn't then I will look into this tonight and my apologies 🙏

ofek avatar Oct 02 '25 18:10 ofek

Did that work?

ofek avatar Oct 02 '25 21:10 ofek

Did that work?

Nope. With that same diff:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/__main__.py", line 6, in <module>
    sys.exit(hatchling())
             ~~~~~~~~~^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/__init__.py", line 26, in hatchling
    command(**kwargs)
    ~~~~~~~^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/cli/metadata/__init__.py", line 27, in metadata_impl
    metadata = resolve_metadata_fields(project_metadata)
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/utils.py", line 51, in resolve_metadata_fields
    'version': metadata.version,
               ^^^^^^^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/core.py", line 149, in version
    self._version = self._get_version()
                    ~~~~~~~~~~~~~~~~~^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/core.py", line 248, in _get_version
    version = self.hatch.version.cached
              ^^^^^^^^^^^^^^^^^^
  File "/Users/glyph/Library/Application Support/hatch/env/virtual/automat/rI8sZPBT/automat-build/lib/python3.13/site-packages/hatchling/metadata/core.py", line 1425, in version
    raise ValueError(message)
ValueError: Missing `tool.hatch.version` configuration

glyph avatar Oct 02 '25 21:10 glyph

Sorry, I played myself. It looks like I spent so long locally using stuff intended for the next non-patch release that I thought they were already features. This is implemented but unreleased.

ofek avatar Oct 03 '25 02:10 ofek

This is implemented but unreleased.

Has it been… a year since the last release? :)

glyph avatar Oct 03 '25 03:10 glyph

Since the last non-patch release yes, I have to backport the changelogs still but you can see them in the GitHub releases. I merged a bunch of stuff that were prerequisites for the workspaces feature leaving HEAD in an unreleasable state which is why patch releases are sourced from a different branch. UV then happened and social media hype ruined my motivation thus causing a little burnout. There is now a contributor @cjames23 picking that back up and development will be more frequent after that.

ofek avatar Oct 03 '25 03:10 ofek

I know what it's like to be stuck in release limbo like this 😔. Thanks for letting me know; should we just close this, since it is already fixed? I'd be happy to subscribe to a release issue instead.

glyph avatar Oct 03 '25 16:10 glyph

Or I guess I should try to verify that the bug isn't still present in HEAD first

glyph avatar Oct 03 '25 16:10 glyph

Were you able to confirm?

ofek avatar Oct 04 '25 16:10 ofek

As of 9e1fc3472f9f2536e9269cd2009f878e597a6061 it … sort of works. If I do hatch version I expect 25.4.17.dev9+gbd5651c79.d20251020 as my output on stdout, but instead it "syncs versions" for a minute and then I get this on stdout, and a bunch more on stderr:

running egg_info
writing src/Automat.egg-info/PKG-INFO
writing dependency_links to src/Automat.egg-info/dependency_links.txt
writing entry points to src/Automat.egg-info/entry_points.txt
writing requirements to src/Automat.egg-info/requires.txt
writing top-level names to src/Automat.egg-info/top_level.txt
adding license file 'LICENSE'
writing manifest file 'src/Automat.egg-info/SOURCES.txt'
running dist_info
creating /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info
writing /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/PKG-INFO
writing dependency_links to /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/dependency_links.txt
writing entry points to /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/entry_points.txt
writing requirements to /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/requires.txt
writing top-level names to /private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/top_level.txt
writing manifest file '/private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/SOURCES.txt'
adding license file 'LICENSE'
writing manifest file '/private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/Automat.egg-info/SOURCES.txt'
creating '/private/var/folders/s9/xg4g1zwd38d1hcd5vpjpb5fm0000gn/T/tmpod9gukcd/work/automat-25.4.17.dev9+gbd5651c79.d20251020.dist-info'
25.4.17.dev9+gbd5651c79.d20251020

glyph avatar Oct 20 '25 08:10 glyph