Search code examples
pythonpython-3.xpackagingsetuptools-scm

check-manifest fails after upgrading setuptools_scm from 6.0.1 to 6.3.1


I have been using setuptools-scm version 6.0.1 for my python project. The project also uses check-manifest with a pre-commit hook. Ever since I upgraded setuptools-scm to 6.3.1, the check-manifest hook has been failing with the following error that looks like it wasn't able to determine the correct version string from sdist packaging.

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'

It is interesting to see that the reported version string is completely wrong (extras-0.3.0.dev3+g4d323bc.d20210909). Part of the library name seems to be getting added with the version string.

However, it still runs fine with 6.0.1, so downgrading is an option. But I would like to know how to make them work together. I have looked into some other threads suggesting the use of a weak flag or setting SETUPTOOLS_SCM_PRETEND_VERSION=0.0, but none of the approaches worked. I am not sure why it is getting extras as part of the version string. Here's my pyproject.toml file:

[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
)/
'''

Update: I have added an issue in the setuptools-scm project regarding this.

Update: This was indeed a bug in the check-manifest library. Go to reported issue and a possible fix.


Solution

  • This issue caused due to a bug in the check-manifest library where the sdist filenames containing dashes were being parsed incorrectly when trying to extract the version string.

    Possible solutions:

    1. Wait for the maintainers to provide a fix,
    2. Remove check-manifest dependency from pre-commit or build dependencies.
    3. Rename python library removing the dash, e.g. logging-extras to logging_extras in setup.py file.

    EDIT

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