setuptools_scm 从 6.0.1 升级到 6.3.1 后检查清单失败

check-manifest fails after upgrading setuptools_scm from 6.0.1 to 6.3.1

我一直在为我的 python project 使用 setuptools-scm 版本 6.0.1。该项目还使用 check-manifest 和预提交挂钩。自从我将 setuptools-scm 升级到 6.3.1 后,check-manifest 挂钩一直失败并出现以下错误,看起来它无法从 sdist 包装中确定正确的版本字符串。

ERROR Backend subproccess exited when trying to invoke build_sdist
Traceback (most recent call last):
  File "/home/zobayer/.cache/pre-commit/repoijtr5gb3/py_env-python3/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 349, in <module>
    main()
  File "/home/zobayer/.cache/pre-commit/repoijtr5gb3/py_env-python3/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 331, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/home/zobayer/.cache/pre-commit/repoijtr5gb3/py_env-python3/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 301, in build_sdist
    return backend.build_sdist(sdist_directory, config_settings)
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/build_meta.py", line 225, in build_sdist
    return self._build_with_temp_dir(['sdist', '--formats', 'gztar'],
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/build_meta.py", line 207, in _build_with_temp_dir
    self.run_setup()
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup
    exec(compile(code, __file__, 'exec'), locals())
  File "setup.py", line 8, in <module>
    setup(
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.8/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/dist.py", line 453, in __init__
    _Distribution.__init__(
  File "/usr/local/lib/python3.8/distutils/dist.py", line 292, in __init__
    self.finalize_options()
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools/dist.py", line 831, in finalize_options
    ep(self)
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools_scm/integration.py", line 94, in infer_version
    dist.metadata.version = _get_version(config)
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools_scm/__init__.py", line 185, in _get_version
    dump_version(
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/setuptools_scm/__init__.py", line 90, in dump_version
    parsed_version = Version(version)
  File "/tmp/build-env-nswqxife/lib/python3.8/site-packages/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'extras-0.3.0.dev3+g4d323bc.d20210909'

有趣的是,报告的版本字符串完全错误 (extras-0.3.0.dev3+g4d323bc.d20210909)。部分库名称似乎与版本字符串一起添加。

但是,它在 6.0.1 上仍然运行良好,因此降级是一个选项。但我想知道如何让它们一起工作。我研究了一些建议使用弱标志或设置 SETUPTOOLS_SCM_PRETEND_VERSION=0.0 的其他线程,但 none 的方法有效。我不确定为什么它会 extras 作为版本字符串的一部分。这是我的 pyproject.toml 文件:

[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "logging_/version.py"
write_to_template = "# -*- coding: utf-8 -*-\n\n__version__ = '{version}'\n"
version_scheme = "release-branch-semver"

[tool.check-manifest]
ignore = ["logging_/version.py"]

[tool.black]
line-length = 120
include = '\.pyi?$'
exclude = '''
/(
    \.eggs
  | \.git
  | \.pytest_cache
  | \.tox
  | \.venv
  | build
  | dist
)/
'''

更新:我已经在setuptools-scm项目中添加了an issue

更新:这确实是检查清单库中的错误。转到 reported issue and a possible fix

此问题是由于 check-manifest 库中的一个错误导致的,在该错误中,在尝试提取版本字符串时,包含破折号的 sdist 文件名被错误地解析。

可能的解决方案:

  1. 等待维护者提供修复,
  2. 从预提交或构建依赖项中删除检查清单依赖项。
  3. 重命名 python 库删除破折号,例如logging-extras 到 setup.py 文件中的 logging_extras

编辑

My PR got accepted, and the fix is released with 0.47