setuptools-scm: LookupError: setuptools-scm was unable to detect version if [tool.setuptools_scm] is in pyproject.toml
project: https://github.com/ionelmc/python-lazy-object-proxy/ download the source code, extract the tar archive and enter the folder: https://github.com/ionelmc/python-lazy-object-proxy/archive/refs/tags/v1.10.0.tar.gz
In pyproject.toml there is empty table [tool.setuptools_scm] defined.
In setup.py you can find the use_scm_version keyword argument with fallback_version explicitly defined.
setup(
name='lazy-object-proxy',
use_scm_version={
'local_scheme': 'dirty-tag',
'write_to': 'src/lazy_object_proxy/_version.py',
'fallback_version': '1.10.0',
}, ...
Running SETUPTOOLS_SCM_DEBUG=1 python setup.py --version ends up with a LookupError:
DEBUG setuptools_scm.overrides dist name: lazy-object-proxy
DEBUG setuptools_scm.config check absolute root=. relative_to=pyproject.toml
DEBUG setuptools_scm.config file pyproject.toml
DEBUG setuptools_scm.entrypoints version_from_ep setuptools_scm.parse_scm in /home/ksurma/Downloads/python-lazy-object-proxy-1.10.0
DEBUG setuptools_scm.discover looking for ep setuptools_scm.parse_scm in /home/ksurma/Downloads/python-lazy-object-proxy-1.10.0
DEBUG setuptools_scm.entrypoints version_from_ep setuptools_scm.parse_scm_fallback in .
DEBUG setuptools_scm.discover looking for ep setuptools_scm.parse_scm_fallback in .
DEBUG setuptools_scm.discover found ep EntryPoint(name='pyproject.toml', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') in .
DEBUG setuptools_scm.entrypoints EntryPoint(name='pyproject.toml', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') found None
DEBUG setuptools_scm.discover found ep EntryPoint(name='setup.py', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') in .
DEBUG setuptools_scm.entrypoints EntryPoint(name='setup.py', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') found None
DEBUG setuptools_scm.config check absolute root=. relative_to=pyproject.toml
DEBUG setuptools_scm.config file pyproject.toml
Traceback (most recent call last):
File "/home/ksurma/Downloads/python-lazy-object-proxy-1.10.0/setup.py", line 76, in <module>
setup(
File "/usr/lib/python3.12/site-packages/setuptools/__init__.py", line 107, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 147, in setup
_setup_distribution = dist = klass(attrs)
^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/setuptools/dist.py", line 496, in __init__
_Distribution.__init__(
File "/usr/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 283, in __init__
self.finalize_options()
File "/usr/lib/python3.12/site-packages/setuptools/dist.py", line 935, in finalize_options
ep(self)
File "/home/ksurma/Downloads/python-lazy-object-proxy-1.10.0/.eggs/setuptools_scm-8.0.4-py3.12.egg/setuptools_scm/_integration/setuptools.py", line 121, in infer_version
_assign_version(dist, config)
File "/home/ksurma/Downloads/python-lazy-object-proxy-1.10.0/.eggs/setuptools_scm-8.0.4-py3.12.egg/setuptools_scm/_integration/setuptools.py", line 56, in _assign_version
_version_missing(config)
File "/home/ksurma/Downloads/python-lazy-object-proxy-1.10.0/.eggs/setuptools_scm-8.0.4-py3.12.egg/setuptools_scm/_get_version_impl.py", line 112, in _version_missing
raise LookupError(
LookupError: setuptools-scm was unable to detect version for /home/ksurma/Downloads/python-lazy-object-proxy-1.10.0.
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.
I comment out the [tool.setuptools_scm] table and run SETUPTOOLS_SCM_DEBUG=1 python setup.py --version again.
No error. Version is correctly set. Please note the found EntryPoint name set to pyproject.toml while in fact all this data is read from setup.py:
DEBUG setuptools_scm.overrides dist name: lazy-object-proxy
DEBUG setuptools_scm.config check absolute root=. relative_to=pyproject.toml
DEBUG setuptools_scm.config file pyproject.toml
DEBUG setuptools_scm.entrypoints version_from_ep setuptools_scm.parse_scm in /home/ksurma/Downloads/python-lazy-object-proxy-1.10.0
DEBUG setuptools_scm.discover looking for ep setuptools_scm.parse_scm in /home/ksurma/Downloads/python-lazy-object-proxy-1.10.0
DEBUG setuptools_scm.entrypoints version_from_ep setuptools_scm.parse_scm_fallback in .
DEBUG setuptools_scm.discover looking for ep setuptools_scm.parse_scm_fallback in .
DEBUG setuptools_scm.discover found ep EntryPoint(name='pyproject.toml', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') in .
DEBUG setuptools_scm.fallbacks FALLBACK 1.10.0
INFO setuptools_scm.version version 1.10.0 -> 1.10.0
DEBUG setuptools_scm.entrypoints EntryPoint(name='pyproject.toml', value='setuptools_scm.fallbacks:fallback_version', group='setuptools_scm.parse_scm_fallback') found <ScmVersion 1.10.0 dist=0 node=None dirty=False branch=None>
DEBUG setuptools_scm.version scm version <ScmVersion 1.10.0 dist=0 node=None dirty=False branch=None>
DEBUG setuptools_scm.version config Configuration(relative_to='pyproject.toml', root='.', version_scheme='guess-next-dev', local_scheme='dirty-tag', tag_regex=re.compile('^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'), parentdir_prefix_version=None, fallback_version='1.10.0', fallback_root='.', write_to='src/lazy_object_proxy/_version.py', write_to_template=None, version_file=None, version_file_template=None, parse=None, git_describe_command=None, dist_name='lazy-object-proxy', version_cls=<class 'packaging.version.Version'>, search_parent_directories=False, parent=PosixPath('.'))
DEBUG setuptools_scm.dump_version dump 1.10.0 into src/lazy_object_proxy/_version.py
1.10.0
We came across this issue while debugging a weird behavior of two Fedora’s build tools: copr, where the build consistently fails and locally in mock with exactly the same environment, where no such issue arises, the version is read correctly. Could it be that the mere order in which files are read creates such discrepancies?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 17 (16 by maintainers)
@hroncok thanks for that minimal repro case - I’ve been investigating a similar problem with the
python-trx-pythonpackage in Debian, where a_version.pyfile is unpredictably created-or-not at package build-time – it has a (non-empty)[tool.setuptools_scm]config table inpyproject.toml.I believe the unpredictable behaviour is likely to be from the same cause, and that it relates to the order that the
version_keywordandinfer_versionfunctions insetuptools_scmare invoked during package build.Findings (so far)
Both the
version_keywordandinfer_versionfunctions are declared as entrypoints inentry_points.txtfile ofsetuptools_scm:In the case of
version_keyword, the function is placed in thedistutils.setup_keywordsgroup, handled by_finalize_setup_keywordsinsetuptools– and therefore ultimately becomes part of the samefinalize_distribution_optionsgroup whereinfer_versionis found. This occurs indirectly, via theentry_points.txtfile ofsetuptools, separate to the entrypoints file ofsetuptools_scm.The
finalize_distribution_optionsentrypoint group is a documented distribution-customization feature ofsetuptools.Although the
finalize_distribution_optionsgroup does allow functions to declare anorderattribute on their callables to declare a runtime evaluation order, the default ordering is undefined (all items are defaulted to zero) and lacks a tiebreaker comparison.Issue #1022 seems to relate to this area too.
Observations / possible solutions
What I find locally following installation of
setuptoolsfrom recent tagged source versions (v69.2.0for example) is that without changing any of the library code, I can get your minimal test case to pass/fail reliably by simply adjusting the version number insetuptools:setup.cfgand reinstalling it. That doesn’t make much sense except to indicate a possible source of nondeterminism that does not relate to the code withinsetuptoolsitself, yet that can somehow be affected by (re)installations of the package. Ordering of reads from the filesystem, file timestamps, file paths and cache locations spring to mind as possible explanations, but I haven’t confirmed the specific cause in this case yet.I do think that the nondeterminism could be mitigated somewhere around the
finalize_optionsfunction by creating a reliable tiebreaker for sort-ordering of the entrypoint functions, or allocating fixedordervalues for them, but I think it would be better to determine what the origin of the ordering difference is before patching over it.