Versioning own pre-commit hook with dynamic versioning #132
-
Hi! One of my maintained projects provides Example of .pre-commit-hooks.yaml:
In such case, It falls back to a full history clone on errors. I don’t figure out which errors are possible here yet. Of course, I can try to raise As you can see it looks completely incompatible to have a My question is what could you suggest to make it work? The last notes
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
The current solution: if __version__ == '0.0.1.dev1':
# If CLI was installed from shallow clone, __version__ will be 0.0.1.dev1 due to non-strict versioning.
# This happens when installing CLI as pre-commit hook.
# We are not able to provide the version based on Git Tag in this case.
# This fallback version is maintained manually.
# One benefit of it is that we could pass the version with a special suffix to mark pre-commit hook usage.
import os
version_filepath = os.path.join(os.path.dirname(__file__), 'pre-commit-hook-version')
with open(version_filepath, 'r', encoding='UTF-8') as f:
__version__ = f.read().strip() It will be awesome to describe the fallback version file in |
Beta Was this translation helpful? Give feedback.
-
Hi! I don't have a good solution offhand, but I found some related issues while looking into this:
I also found this other workaround that triggers a fetch while building the package: Kintyre/ksconf@cb07437 . Maybe we could add support for something like this in the plugin. From my perspective, the best solution would be if pre-commit allowed opting into full clones, but it looks like they may not be open to adding that option, given this comment: pre-commit/pre-commit#1924 (comment) . For reference, is this causing any errors or misbehavior? When I use pre-commit, I just look at the |
Beta Was this translation helpful? Give feedback.
I've just published v0.25.0b2 on PyPI that adds a new option (41c868d, 7a823d1). Could you try configuring
fix-shallow-repository = true
and test it out? It will rungit fetch --unshallow
if it detects a shallow repository.Edit:
Sorry, I think I missed a condition, so it will still complain about the shallow repository. One moment...Fixed in v0.25.0b2 by switching fromgit fetch --tags
togit fetch --unshallow
.