0

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

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,但没有一种方法有效。我不确定为什么它会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关于此的问题。

更新:这确实是检查清单库中的一个错误。转到 报告的问题可能的修复

4

1 回答 1

0

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

可能的解决方案:

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

编辑

我的 PR 被接受了,并且该修复程序以 0.47 发布

于 2021-09-15T23:47:26.870 回答