Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(packaging): Enable support for versioning Git archives #737

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

webknjaz
Copy link
Contributor

@webknjaz webknjaz commented Dec 28, 2024

It's a follow-up to #735 that lacks this property. It's also an internal change.

It essentially allows one to

$ pip install https://github.com/antonbabenko/pre-commit-terraform/archive/339c31a.tar.gz

and get a correctly computed version in the installed metadata.

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.
  • This PR is an internal change that the end-users won't notice.

Description of your changes

See above.

How can we test changes

$ pip install https://github.com/antonbabenko/pre-commit-terraform/archive/339c31a.tar.gz

It's a follow-up to antonbabenko#735 that lacks this property. It's also an internal
change.

It essentially allows one to
```
$ pip install https://github.com/antonbabenko/pre-commit-terraform/archive/ae5057d.zip
```
and get a correctly computed version in the installed metadata.

[1]: https://setuptools-scm.rtfd.io/en/latest/usage/#git-archives
@webknjaz webknjaz marked this pull request as draft December 28, 2024 15:07
@MaxymVlasov
Copy link
Collaborator

I suppose that's why you marked it as draft?

via pre-commit-terraform 
➜ pip install https://github.com/antonbabenko/pre-commit-terraform/archive/339c31a.tar.gz
Collecting https://github.com/antonbabenko/pre-commit-terraform/archive/339c31a.tar.gz
  Downloading https://github.com/antonbabenko/pre-commit-terraform/archive/339c31a.tar.gz
     - 102.1 kB 2.2 MB/s 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [39 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      Traceback (most recent call last):
        File "/home/vm/code/0-other/open-source/pre-commit-terraform/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/vm/code/0-other/open-source/pre-commit-terraform/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/vm/code/0-other/open-source/pre-commit-terraform/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 152, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/build.py", line 58, in build_wheel
          return os.path.basename(next(builder.build(directory=wheel_directory, versions=['standard'])))
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 90, in build
          self.metadata.validate_fields()
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/metadata/core.py", line 265, in validate_fields
          _ = self.version
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/metadata/core.py", line 149, in version
          self._version = self._get_version()
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/metadata/core.py", line 244, in _get_version
          core_metadata = self.core
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/metadata/core.py", line 196, in core
          metadata_hook.update(self.core_raw_metadata)
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatch_vcs/metadata_hook.py", line 45, in update
          urls[key] = formatter.format(url)
        File "/usr/lib/python3.10/string.py", line 161, in format
          return self.vformat(format_string, args, kwargs)
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/utils/context.py", line 143, in vformat
          result, _ = self._vformat(format_string, args, kwargs, used_args, 10)
        File "/usr/lib/python3.10/string.py", line 218, in _vformat
          result.append(self.format_field(obj, format_spec))
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatchling/utils/context.py", line 161, in format_field
          return self.__formatters[formatter](value, data)
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatch_vcs/metadata_hook.py", line 39, in <lambda>
          'commit_hash': lambda *args: vcs_utils.get_commit_hash(self.root),
        File "/tmp/pip-build-env-f_b8t2yj/overlay/lib/python3.10/site-packages/hatch_vcs/vcs_utils.py", line 10, in get_commit_hash
          return subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root).decode('utf-8').strip()
        File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        File "/usr/lib/python3.10/subprocess.py", line 526, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 128.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

@MaxymVlasov MaxymVlasov changed the title chore(packaging): X📦 Enable support for versioning Git archives chore(packaging): Enable support for versioning Git archives Dec 28, 2024
@webknjaz
Copy link
Contributor Author

Yep: ofek/hatch-vcs#80. I'm withdrawing the effort until I hear from the upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants