Skip to content

Commit 3a6bf6c

Browse files
committed
VERSIONEER: Improve short version file handling
Made and tagged nibabel-specific hacks for including a fallback version for using with git-archive. This is no longer the canonical versioneer but should behave identically except in git archives made on non-release revisions.
1 parent 4c2fd46 commit 3a6bf6c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

nibabel/_version.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def git_get_keywords(versionfile_abs):
156156
f.close()
157157
except EnvironmentError:
158158
pass
159+
# CJM: Nibabel hack to ensure we can git-archive off-release versions and
160+
# revert to old X.Y.Zdev versions + githash
159161
try:
160162
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
161163
keywords["fallback"] = rel["VERSION"]
@@ -167,8 +169,9 @@ def git_get_keywords(versionfile_abs):
167169
@register_vcs_handler("git", "keywords")
168170
def git_versions_from_keywords(keywords, tag_prefix, verbose):
169171
"""Get version information from git keywords."""
170-
if not keywords:
171-
raise NotThisMethod("no keywords at all, weird")
172+
# CJM: Nibabel fix to avoid hitting unguarded dictionary lookup, better explanation
173+
if "refnames" not in keywords:
174+
raise NotThisMethod("Short version file found")
172175
date = keywords.get("date")
173176
if date is not None:
174177
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant

versioneer.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ def git_get_keywords(versionfile_abs):
577577
f.close()
578578
except EnvironmentError:
579579
pass
580+
# CJM: Nibabel hack to ensure we can git-archive off-release versions and
581+
# revert to old X.Y.Zdev versions + githash
580582
try:
581583
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
582584
keywords["fallback"] = rel["VERSION"]
@@ -588,8 +590,9 @@ def git_get_keywords(versionfile_abs):
588590
@register_vcs_handler("git", "keywords")
589591
def git_versions_from_keywords(keywords, tag_prefix, verbose):
590592
"""Get version information from git keywords."""
591-
if not keywords:
592-
raise NotThisMethod("no keywords at all, weird")
593+
# CJM: Nibabel fix to avoid hitting unguarded dictionary lookup, better explanation
594+
if "refnames" not in keywords:
595+
raise NotThisMethod("Short version file found")
593596
date = keywords.get("date")
594597
if date is not None:
595598
# git-2.2.0 added "%%cI", which expands to an ISO-8601 -compliant
@@ -974,6 +977,8 @@ def git_get_keywords(versionfile_abs):
974977
f.close()
975978
except EnvironmentError:
976979
pass
980+
# CJM: Nibabel hack to ensure we can git-archive off-release versions and
981+
# revert to old X.Y.Zdev versions + githash
977982
try:
978983
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
979984
keywords["fallback"] = rel["VERSION"]
@@ -985,8 +990,9 @@ def git_get_keywords(versionfile_abs):
985990
@register_vcs_handler("git", "keywords")
986991
def git_versions_from_keywords(keywords, tag_prefix, verbose):
987992
"""Get version information from git keywords."""
988-
if not keywords:
989-
raise NotThisMethod("no keywords at all, weird")
993+
# CJM: Nibabel fix to avoid hitting unguarded dictionary lookup, better explanation
994+
if "refnames" not in keywords:
995+
raise NotThisMethod("Short version file found")
990996
date = keywords.get("date")
991997
if date is not None:
992998
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant

0 commit comments

Comments
 (0)