mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
320 stars 23 forks source link

"RuntimeError: Unable to detect version control system" #80

Closed chenrui333 closed 5 months ago

chenrui333 commented 5 months ago

πŸ‘‹ while upgrading bbot to 1.1.6.1, noticed some build failure with dunamai-1.19.2, namely

  Running command Preparing metadata (pyproject.toml)
  Traceback (most recent call last):
    File "/opt/homebrew/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/opt/homebrew/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/opt/homebrew/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
      return hook(metadata_directory, config_settings)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/poetry/core/masonry/api.py", line 42, in prepare_metadata_for_build_wheel
      poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/poetry_dynamic_versioning/patch.py", line 26, in alt_poetry_create
      name = _get_and_apply_version(
             ^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/poetry_dynamic_versioning/__init__.py", line 608, in _get_and_apply_version
      version, instance = _get_version(config, name)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/poetry_dynamic_versioning/__init__.py", line 452, in _get_version
      version = _get_version_from_dunamai(vcs, pattern, config)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/poetry_dynamic_versioning/__init__.py", line 417, in _get_version_from_dunamai
      return Version.from_vcs(
             ^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/dunamai/__init__.py", line 1946, in from_vcs
      return cls._do_vcs_callback(
             ^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/dunamai/__init__.py", line 1985, in _do_vcs_callback
      return callback(**kwargs)
             ^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/dunamai/__init__.py", line 1906, in from_any_vcs
      vcs = _detect_vcs(None, path)
            ^^^^^^^^^^^^^^^^^^^^^^^
    File "/private/tmp/pip-build-env-dlmklj3q/overlay/lib/python3.12/site-packages/dunamai/__init__.py", line 385, in _detect_vcs
      raise RuntimeError(" ".join(error_parts))
  RuntimeError: Unable to detect version control system. Checked: Git, Subversion. Not installed: Mercurial, Darcs, Bazaar, Fossil, Pijul.
  error: subprocess-exited-with-error

  Γ— Preparing metadata (pyproject.toml) did not run successfully.
  β”‚ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /opt/homebrew/Cellar/bbot/1.1.6.1/libexec/bin/python /opt/homebrew/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_wheel /private/tmp/tmp66u1w2f2
  cwd: /private/tmp/bbot-20240410-10857-67jzh1/bbot-1.1.6.1
  Preparing metadata (pyproject.toml): finished with status 'error'
error: metadata-generation-failed

Any thoughts about why that is happening? Thanks!

relates to https://github.com/Homebrew/homebrew-core/pull/168552

mtkennerly commented 5 months ago

Hi! There appears to be a problem in the pyproject.toml in 1.1.6.1's .tar.gz. The tool.poetry-dynamic-versioning section sets enable = true, whereas 1.1.6 sets it to enable = false.

When you run poetry build for a project using the poetry-dynamic-versioning plugin (which in turn uses Dunamai), it automatically sets enable = false in the artifacts, so that consumers with just the source code but no Git history don't fail. My guess is that someone ran poetry build && poetry publish without the plugin installed, so it didn't update that field. Now the build in Homebrew is trying to access the Git history, which isn't available.

This should be fixed in bbot and a new version published to fix pyproject.toml.

mtkennerly commented 5 months ago

I've reported this upstream: https://github.com/blacklanternsecurity/bbot/issues/1257

chenrui333 commented 5 months ago

@mtkennerly thanks for the pointer. πŸ‘