Skip to content

version-file build hooks seems to fail for setuptools-scm>=9.0.0 #2035

@mpasson

Description

@mpasson

I'm not sure this is the correct place for this issue, but it seems that building a python package containing the version-file build hooks fails for versions of setuptools-scm greater-equal to 9.0.0.

.venv ❯ uv build
Building source distribution...
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "/Users/marcopassoni/.cache/uv/builds-v0/.tmpX6Nh67/lib/python3.12/site-packages/hatchling/build.py", line 34, in build_sdist
    return os.path.basename(next(builder.build(directory=sdist_directory, versions=['standard'])))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marcopassoni/.cache/uv/builds-v0/.tmpX6Nh67/lib/python3.12/site-packages/hatchling/builders/plugin/interface.py", line 147, in build
    build_hook.initialize(version, build_data)
  File "/Users/marcopassoni/.cache/uv/builds-v0/.tmpX6Nh67/lib/python3.12/site-packages/hatch_vcs/build_hook.py", line 35, in initialize
    dump_version(self.root, self.metadata.version, self.config_version_file, **kwargs)
  File "/Users/marcopassoni/.cache/uv/builds-v0/.tmpX6Nh67/lib/python3.12/site-packages/setuptools_scm/_integration/dump_version.py", line 77, in dump_version
    write_version_to_path(
  File "/Users/marcopassoni/.cache/uv/builds-v0/.tmpX6Nh67/lib/python3.12/site-packages/setuptools_scm/_integration/dump_version.py", line 111, in write_version_to_path
    content = final_template.format(version=version, version_tuple=version_tuple)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'scm_version'
  × Failed to build `/Users/marcopassoni/Documents/MyPrograms/<package>`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `hatchling.build.build_sdist` failed (exit status: 1)
      hint: This usually indicates a problem with the package or the build environment.

The relevant parts of the pyproject.toml are:

[project]
name = <package>
requires-python = ">=3.12"
dynamic = ['version']

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = 'vcs'

[tool.hatch.build.hooks.vcs]
version-file = "src/<package>/_pinned_version.py"

Restricting stetuptools_scm to versions previous to 9.0.0:

requires = ["hatchling", "hatch-vcs", "setuptools-scm<9.0.0"]

solves the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions