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

Hatch-vcs metadata hook fails when run on sdist tarball #36

Closed
jorisroovers opened this issue Mar 8, 2023 · 2 comments
Closed

Hatch-vcs metadata hook fails when run on sdist tarball #36

jorisroovers opened this issue Mar 8, 2023 · 2 comments

Comments

@jorisroovers
Copy link
Sponsor Contributor

When using the metadata hook and doing a hatch build -t wheel build from an sdist tarball that was previously built using hatch-vcs, the metadata hook will attempt to access version control to determine the commit_hash variable:

'commit_hash': lambda *args: vcs_utils.get_commit_hash(self.root),

This will cause hatch-vcs to crash since there’s no version control present in the sdist tarball.

Details on how to reproduce for my project gitlint: jorisroovers/gitlint#460

Discussed with @ofek in jorisroovers/gitlint#367

akhmerov added a commit to quantum-tinkerer/pymablock that referenced this issue Jun 5, 2023
@jorisroovers
Copy link
Sponsor Contributor Author

Had a closer look at this and was thinking hatch-vcs could read a fallback commit_hash from file in case git is unavailable (or raises an error). This commit_hash would be stored by hatch-vcs itself in case git is available.

So something like this (pseudo-code):

def get_commit_hash(self):
    try:
        commit_hash = vcs_utils.get_commit_hash(self.root)
        store_commit_hash(commit_hash, fallback_file)
    except:
        commit_hash = read_commit_hash(fallback_file)

# How it's used:
'commit_hash': lambda *args: get_commit_hash(),

In this scenario, the question becomes what the location and format of fallback_file would be to store commit_hash.

  • I thought PKG-INFO but I didn’t find a good field for it in the spec.
  • I found a section on Direct URL Data Structure but am unsure how to use it or whether hatch-vcs replaces this capability.
  • pyproject.toml / hatch.toml in a new table like [tool.hatch.metadata.hooks.vcs.info] but I don’t like the idea of rewriting that file
  • An additional metadata file that hatch-vcs creates, probably structured (toml/json/?), but also not very clean.

Any thoughts?

@ofek
Copy link
Owner

ofek commented Mar 24, 2024

Metadata is now persisted for dynamic fields properly as of Hatchling v1.22.0

@ofek ofek closed this as completed Mar 24, 2024
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

No branches or pull requests

2 participants