// Describe the version relative to last tag
command_git = ["git", "describe", "--match", "v[0-9]*"]version_buf = check_output(command_git).rstrip()
// Exclude the "v" for PEP440 conformity, see
// https://www.python.org/dev/peps/pep-0440///public-version-identifiers
version_buf = version_buf[1:]
// Create a niftynet/info.py module that will keep the
// version descriptor returned by Git
info_module = open(os.path.join("niftynet", "info.py"), "w")
info_module.write("// -*- coding: utf-8 -*-\n")
info_module.write("NiftyNet version tracker.\n")
info_module.write("\n")
info_module.write("This module only holds the NiftyNet version,")
info_module.write(" generated using the \n")
info_module.write("``{}`` command.\n".format(" ".join(command_git)))
info_module.write("\n")
info_module.write("\n")
info_module.write("\n")
info_module.write("\n")
info_module.write("VERSION_DESCRIPTOR = "{}"\n".format(version_buf))
info_module.close()
// Regex for checking PEP 440 conformity
// https://www.python.org/dev/peps/pep-0440///id79
pep440_regex = re.compile(
r"^\s*" + version.VERSION_PATTERN + r"\s*$",
re.VERBOSE | re.IGNORECASE,
)
// Split the git describe output, as it may not be a tagged commit
tokens = version_buf.split("-")
if len(tokens) > 1: // not a tagged commit
// Format a developmental release identifier according to PEP440, see:
// https://www.python.org/dev/peps/pep-0440///developmental-releases
version_git = "{}.dev{}".format(tokens[0], tokens[1])
After Change
from utilities.get_niftynet_version import get_niftynet_git_version
version_buf, version_git, command_git = get_niftynet_git_version()
// Create a niftynet/info.py module that will keep the
// version descriptor returned by Git