Skip to content

Commit 389059e

Browse files
committed
MAINT: Add fallback version to versioneer + git-archive
1 parent 572fa1d commit 389059e

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

nibabel/_version.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import subprocess
1717
import sys
18+
import runpy
1819

1920

2021
def get_keywords():
@@ -155,6 +156,11 @@ def git_get_keywords(versionfile_abs):
155156
f.close()
156157
except EnvironmentError:
157158
pass
159+
try:
160+
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
161+
keywords["fallback"] = rel["VERSION"]
162+
except (FileNotFoundError, KeyError):
163+
pass
158164
return keywords
159165

160166

@@ -205,10 +211,10 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
205211
"full-revisionid": keywords["full"].strip(),
206212
"dirty": False, "error": None,
207213
"date": date}
208-
# no suitable tags, so version is "0+unknown", but full hex is still there
214+
# no suitable tags, so inspect ./info.py
209215
if verbose:
210-
print("no suitable tags, using unknown + full revision id")
211-
return {"version": "0+unknown",
216+
print("no suitable tags, falling back to info.VERSION or 0+unknown")
217+
return {"version": keywords.get("fallback", "0+unknown"),
212218
"full-revisionid": keywords["full"].strip(),
213219
"dirty": False, "error": "no suitable tags", "date": None}
214220

nibabel/info.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
""" Define long_description parameter
1+
""" Define distribution parameters for nibabel, including package version
22
3-
This parameter is used to fill settings in setup.py, the nibabel top-level
4-
docstring, and in building the docs.
3+
The long description parameter is used to fill settings in setup.py, the
4+
nibabel top-level docstring, and in building the docs.
55
We exec this file in several places, so it cannot import nibabel or use
66
relative imports.
77
"""
88

9+
# nibabel version information
10+
# This is a fall-back for versioneer when installing from a git archive.
11+
# This should be set to the intended next version + dev to indicate a
12+
# development (pre-release) version.
13+
_version_major = 3
14+
_version_minor = 0
15+
_version_micro = 0
16+
_version_extra = 'dev'
17+
# _version_extra = ''
18+
19+
# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
20+
VERSION = "%s.%s.%s%s" % (_version_major,
21+
_version_minor,
22+
_version_micro,
23+
_version_extra)
24+
25+
926
# Note: this long_description is the canonical place to edit this text.
1027
# It also appears in README.rst, but it should get there by running
1128
# ``tools/refresh_readme.py`` which pulls in this version.

versioneer.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
import re
288288
import subprocess
289289
import sys
290+
import runpy
290291

291292

292293
class VersioneerConfig:
@@ -435,6 +436,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
435436
import re
436437
import subprocess
437438
import sys
439+
import runpy
438440
439441
440442
def get_keywords():
@@ -575,6 +577,11 @@ def git_get_keywords(versionfile_abs):
575577
f.close()
576578
except EnvironmentError:
577579
pass
580+
try:
581+
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
582+
keywords["fallback"] = rel["VERSION"]
583+
except (FileNotFoundError, KeyError):
584+
pass
578585
return keywords
579586
580587
@@ -625,10 +632,10 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
625632
"full-revisionid": keywords["full"].strip(),
626633
"dirty": False, "error": None,
627634
"date": date}
628-
# no suitable tags, so version is "0+unknown", but full hex is still there
635+
# no suitable tags, so inspect ./info.py
629636
if verbose:
630-
print("no suitable tags, using unknown + full revision id")
631-
return {"version": "0+unknown",
637+
print("no suitable tags, falling back to info.VERSION or 0+unknown")
638+
return {"version": keywords.get("fallback", "0+unknown"),
632639
"full-revisionid": keywords["full"].strip(),
633640
"dirty": False, "error": "no suitable tags", "date": None}
634641
@@ -967,6 +974,11 @@ def git_get_keywords(versionfile_abs):
967974
f.close()
968975
except EnvironmentError:
969976
pass
977+
try:
978+
rel = runpy.run_path(os.path.join(os.path.dirname(versionfile_abs), "info.py"))
979+
keywords["fallback"] = rel["VERSION"]
980+
except (FileNotFoundError, KeyError):
981+
pass
970982
return keywords
971983

972984

@@ -1017,10 +1029,10 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
10171029
"full-revisionid": keywords["full"].strip(),
10181030
"dirty": False, "error": None,
10191031
"date": date}
1020-
# no suitable tags, so version is "0+unknown", but full hex is still there
1032+
# no suitable tags, so inspect ./info.py
10211033
if verbose:
1022-
print("no suitable tags, using unknown + full revision id")
1023-
return {"version": "0+unknown",
1034+
print("no suitable tags, falling back to info.VERSION or 0+unknown")
1035+
return {"version": keywords.get("fallback", "0+unknown"),
10241036
"full-revisionid": keywords["full"].strip(),
10251037
"dirty": False, "error": "no suitable tags", "date": None}
10261038

0 commit comments

Comments
 (0)