Skip to content

fix(cli): add setuptools_scm section#778

Open
Ardelean-Calin wants to merge 2 commits intocanonical:mainfrom
Ardelean-Calin:fix/setuptools
Open

fix(cli): add setuptools_scm section#778
Ardelean-Calin wants to merge 2 commits intocanonical:mainfrom
Ardelean-Calin:fix/setuptools

Conversation

@Ardelean-Calin
Copy link

@Ardelean-Calin Ardelean-Calin commented Aug 12, 2025

Description

A recent setuptools_scm update made it so that we can no longer install the testflinger-cli tool using

uv tool install git+https://github.com/canonical/testflinger#subdirectory=cli

We would get the following error:

error: The build backend returned an error
  Caused by: Call to `setuptools.build_meta.build_wheel` failed (exit status: 1)

[stderr]
toml section missing 'pyproject.toml does not contain a tool.setuptools_scm section'
Traceback (most recent call last):
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools_scm/_integration/pyproject_reading.py", line 113, in read_pyproject
    section = defn.get("tool", {})[tool_name]
KeyError: 'setuptools_scm'
Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
    self.run_setup()
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/__init__.py", line 115, in setup
    return distutils.core.setup(**attrs)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 148, in setup
    _setup_distribution = dist = klass(attrs)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/dist.py", line 321, in __init__
    _Distribution.__init__(self, dist_attrs)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 309, in __init__
    self.finalize_options()
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools/dist.py", line 784, in finalize_options
    ep(self)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools_scm/_integration/setuptools.py", line 129, in infer_version
    result.apply(dist)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools_scm/_integration/version_inference.py", line 48, in apply
    _version_missing(config)
  File "/home/calinp/.cache/uv/builds-v0/.tmpb5vBYp/lib/python3.10/site-packages/setuptools_scm/_get_version_impl.py", line 188, in _version_missing
    raise LookupError(error_msg)
LookupError: setuptools-scm was unable to detect version for /home/calinp/.cache/uv/git-v0/checkouts/04db69cccab77f75/7a1a7b8/cli.

Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj

Alternatively, set the version with the environment variable SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} as described in https://setuptools-scm.readthedocs.io/en/latest/config/

hint: This usually indicates a problem with the package or the build environment.

Basically it seems the tool.setuptools_scm section is no longer optional and neither is specifying a fallback revision (I chose 0.0.0 in this case).

Resolved issues

N/A

Documentation

I looked at the Install in a virtual environment section of the documentation and although I think that should be updated to include uv, that particular flow doesn't change. (It was broken before this commit, though)

Web service API changes

N/A

Tests

N/A

@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.00%. Comparing base (7a1a7b8) to head (fb95bdc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #778   +/-   ##
=======================================
  Coverage   64.00%   64.00%           
=======================================
  Files          94       94           
  Lines        7867     7867           
  Branches      757      757           
=======================================
  Hits         5035     5035           
  Misses       2686     2686           
  Partials      146      146           
Flag Coverage Δ *Carryforward flag
agent 69.49% <ø> (ø) Carriedforward from 7a1a7b8
cli 78.41% <ø> (ø)
device 51.47% <ø> (ø) Carriedforward from 7a1a7b8
server 85.12% <ø> (ø) Carriedforward from 7a1a7b8

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Agent 69.49% <ø> (ø)
CLI 78.41% <ø> (ø)
Common ∅ <ø> (∅)
Device Connectors 51.47% <ø> (ø)
Server 85.12% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rene-oromtz
Copy link
Contributor

Hi @Ardelean-Calin
Thanks for taking care of this!

I reported this yesterday in this bug and dev replied that when the root directory (where .git is located) is in an upper directory tool.setuptools_scm section is not optional. Even when we had the dynamic versioning enabled, seems that on setuptools 8.x.x the cli build version was always set to 0.0.0.

One option is to add this instead:

[tool.setuptools_scm]
root = ".."
tag_regex = "^rev(?P<version>[0-9]+)$"

But since we are not using the tag/version for the CLI while publishing it to the Snap Store, I think I also prefer the simpler approach to just do the fallback version specified in this PR. The rev tag is also for the whole repo so I don't think it even make sense to version the CLI with this.

What do you think @pedro-avalos?

@pedro-avalos
Copy link
Collaborator

pedro-avalos commented Aug 12, 2025

Hm, I'm not sure about the tag_regex, as the CLI doesn't really use that tag for versioning; the tag is for the server image revisions.

Apart from that, yeah I think we should have the root path in the configuration

@rene-oromtz
Copy link
Contributor

Seems that when setting the root, is does expect to found a tag from it
I tried setting:

[tool.setuptools_scm]
root = ".."
fallback_version = "0.0.0"

But got:

UserWarning: tag
      'rev186' no version found

Setting only root also fails for the same reason

@rene-oromtz
Copy link
Contributor

FYI, SCM 9.1.1 was yanked: https://pypi.org/project/setuptools-scm/9.1.1/

Latest version now is 8.3.1 for which CLI build should be able to work again.
I believe we can keep this PR open for now to define what will be the right approach for this and prepare if next release require any modification from our side.

@Ardelean-Calin
Copy link
Author

Ardelean-Calin commented Aug 13, 2025

I've updated pyproject.toml to include the relative root field. I've also removed the tag regex. For me this solves the issue that is described in this pull request - i.e. I can now install testflinger cli as such:

uv tool install git+https://github.com/Ardelean-Calin/testflinger@fix/setuptools#subdirectory=cli

The version is automatically deducted from the commit SHA as being 0.1.dev1903+g33afaf1.

The unit tests failed but it's not related to this PR, it's related to this repo's policy.

@github-actions
Copy link

github-actions bot commented Jan 7, 2026

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in a week.

@github-actions github-actions bot added the Stale label Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants