Skip to content
Snippets Groups Projects
Commit 45bbc767 authored by cmaffeo2's avatar cmaffeo2
Browse files

Fixed version script so it changes directories to version.__file__

parent 22534586
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ __all__ = ("get_version") ...@@ -38,6 +38,7 @@ __all__ = ("get_version")
from pathlib import Path from pathlib import Path
import subprocess import subprocess
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import os
maintainer = "Chris Maffeo <cmaffeo2@illinois.edu>" maintainer = "Chris Maffeo <cmaffeo2@illinois.edu>"
...@@ -49,7 +50,7 @@ def check_git_repository(): ...@@ -49,7 +50,7 @@ def check_git_repository():
remotes = subprocess.check_output(['git', 'remote', '-v'], stderr=subprocess.STDOUT) remotes = subprocess.check_output(['git', 'remote', '-v'], stderr=subprocess.STDOUT)
return b'mrdna.git' in remotes return b'mrdna.git' in remotes
except: except:
return False return False
def call_git_describe(abbrev): def call_git_describe(abbrev):
try: try:
...@@ -100,38 +101,44 @@ def get_version(abbrev=7): ...@@ -100,38 +101,44 @@ def get_version(abbrev=7):
release_version = read_release_version() release_version = read_release_version()
if not check_git_repository(): old_wd = os.getcwd()
return release_version try:
# raise Exception(__function__ +" called from outside a version controlled source repository") os.chdir(Path(__file__).parent)
if not check_git_repository():
return release_version
# raise Exception(__function__ +" called from outside a version controlled source repository")
# First try to get the current version using “git describe”.
split_version = call_git_describe(abbrev).split("-") # First try to get the current version using “git describe”.
version = split_version[0]
if len(split_version) > 1 and int(split_version[-2]) > 0:
version += ".dev{}".format(int(split_version[-2]))
split_version = call_git_describe(abbrev).split("-")
version = split_version[0]
if len(split_version) > 1 and int(split_version[-2]) > 0:
version += ".dev{}".format(int(split_version[-2]))
# If that doesn't work, fall back on the value that's in
# RELEASE-VERSION.
if version is None: # If that doesn't work, fall back on the value that's in
version = release_version # RELEASE-VERSION.
# If we still don't have anything, that's an error. if version is None:
version = release_version
if version is None: # If we still don't have anything, that's an error.
raise ValueError("Cannot find the version number!")
# If the current version is different from what's in the if version is None:
# RELEASE-VERSION file, update the file to be current. raise ValueError("Cannot find the version number!")
if version != release_version: # If the current version is different from what's in the
write_release_version(version) # RELEASE-VERSION file, update the file to be current.
# Finally, return the current version. if version != release_version:
write_release_version(version)
finally:
os.chdir(old_wd)
# Finally, return the current version.
return version return version
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment