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

Open
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/a7155a7.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/a7155a7.tar.gz

@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.

@webknjaz webknjaz force-pushed the maintenance/versioning-git-archives branch from 8d8350e to a7155a7 Compare January 14, 2025 00:43
@webknjaz webknjaz marked this pull request as ready for review January 14, 2025 00:44
@webknjaz
Copy link
Contributor Author

@MaxymVlasov this can be merged now.

@MaxymVlasov
Copy link
Collaborator

MaxymVlasov commented Jan 14, 2025

Nice, shellcheckcheck which fails in this PR, highlight that default shellcheck in OSes are outdated, and need to "download pre-compiled binaries for the latest release" from here
I'll fix it separate PR to unblock this one

@webknjaz
Copy link
Contributor Author

@MaxymVlasov no, it's not outdated. You can see in the other job that it's of the latest version.

The problem here is that your other workflow did not execute this check for the past 3 months and it's version changed over this period of time. It's actually two problems:

  1. it should run against all files in CI
  2. the dep's version should be pinned

FWIW, I think I saw a Python implementation of the same check somewhere that gives you more control over the version pinning.

@MaxymVlasov
Copy link
Collaborator

ubuntu22.04 has 0.8.0 of it, if install it via apt install, so issue popup only when GH changed their workers to 24.04 - whic has latest shellcheck 0.10.0, released in Mar 2024.

That's why I, as user of ubuntu 22.04 locally, and in CI itself which use same official instalation method via apt, didn't face this tiny style issue before

@webknjaz webknjaz force-pushed the maintenance/versioning-git-archives branch from a7155a7 to 32afbff Compare January 14, 2025 19:39
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.38%. Comparing base (e01b4de) to head (0f07114).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #737      +/-   ##
===========================================
- Coverage   100.00%   96.38%   -3.62%     
===========================================
  Files            9       10       +1     
  Lines          161      249      +88     
  Branches         5        7       +2     
===========================================
+ Hits           161      240      +79     
- Misses           0        9       +9     
Flag Coverage Δ
CI-GHA 96.38% <ø> (-3.62%) ⬇️
MyPy 91.05% <ø> (?)
OS-Linux 96.38% <ø> (-3.62%) ⬇️
OS-Windows 100.00% <ø> (?)
OS-macOS 100.00% <ø> (ø)
Py-3.10.11 100.00% <ø> (?)
Py-3.10.16 100.00% <ø> (?)
Py-3.11.11 100.00% <ø> (?)
Py-3.11.9 100.00% <ø> (ø)
Py-3.12.8 100.00% <ø> (?)
Py-3.13.1 96.38% <ø> (?)
Py-3.9.13 100.00% <ø> (?)
Py-3.9.21 100.00% <ø> (ø)
VM-macos-13 100.00% <ø> (?)
VM-macos-14 100.00% <ø> (ø)
VM-ubuntu-24.04 100.00% <ø> (ø)
VM-ubuntu-latest 91.05% <ø> (?)
VM-windows-2025 100.00% <ø> (?)
pytest 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

'Source Archive' = 'https://github.com/antonbabenko/pre-commit-terraform/archive/{commit_hash}.tar.gz'
# FIXME: Uncomment 'Source Archive' as soon as
# FIXME: https://github.com/ofek/hatch-vcs/issues/80 is fixed.
# 'Source Archive' = 'https://github.com/antonbabenko/pre-commit-terraform/archive/{commit_hash}.tar.gz'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not essential to "Enable support for versioning Git archives"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's another feature. You're not using it now anyway.

@webknjaz webknjaz force-pushed the maintenance/versioning-git-archives branch from 32afbff to 1115c64 Compare January 15, 2025 01:33
@webknjaz
Copy link
Contributor Author

That's why I, as user of ubuntu 22.04 locally, and in CI itself which use same official instalation method via apt, didn't face this tiny style issue before

The point still stands: the software wasn't pinned. The VM image upgrade was just a method by which said upgrade happened. These images could also be pinned. I've been considering doing this in my projects too, due to similar cases of the underlying software being swapped out unexpectedly, especially in low-activity projects.

@MaxymVlasov
Copy link
Collaborator

Agree, everything should be pinned, especially if it not cost much to achive that

@MaxymVlasov
Copy link
Collaborator

Error updating the branch: user doesn't have permission to update head repository

Rebase/merge please last changes, and I'll merge this PR

webknjaz and others added 2 commits January 15, 2025 16:08
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
This is a workaround for ofek/hatch-vcs#80
that manifests itself as a traceback when calling Git commands.

The commit must be reverted once said upstream issue is fixed.
@webknjaz webknjaz force-pushed the maintenance/versioning-git-archives branch from 1115c64 to 0f07114 Compare January 15, 2025 15:08
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