From aedb667d50e512655a590ec2af03504947dd9acb Mon Sep 17 00:00:00 2001 From: Siddharth Anand Date: Thu, 19 May 2016 18:49:08 +0000 Subject: [PATCH] Make enhancements to VersionView --- airflow/www/views.py | 2 +- setup.py | 63 ++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 3a0e2854aa4b4..bcd390ccd8909 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -2307,7 +2307,7 @@ def version(self): # Get the Git repo and git hash git_version = None try: - with open("airflow/git_version") as f: + with open(os.path.join(*[settings.AIRFLOW_HOME, 'airflow', 'git_version'])) as f: git_version = f.readline() except Exception as e: self.logger.error(e) diff --git a/setup.py b/setup.py index 43fefd88a9bca..fd1d537588099 100644 --- a/setup.py +++ b/setup.py @@ -39,41 +39,48 @@ def run(self): def git_version(version): + """ + Return a version to identify the state of the underlying git repo. The version will + indicate whether the head of the current git-backed working directory is tied to a + release tag or not : it will indicate the former with a 'release:{version}' prefix + and the latter with a 'dev0' prefix. Following the prefix will be a sha of the current + branch head. Finally, a "dirty" suffix is appended to indicate that uncommitted changes + are present. + """ + repo = None try: import git + repo = git.Repo('.git') except ImportError: logger.warn('gitpython not found: Cannot compute the git version.') return '' - try: - repo = git.Repo('.git') - except ImportError: + except Exception as e: logger.warn('Git repo not found: Cannot compute the git version.') return '' - sha = repo.head.commit.hexsha - if repo.is_dirty(): - return '.dev0+{sha}.dirty'.format(sha=sha) - # commit is clean - # is it release of `version` ? - try: - tag = repo.git.describe( - match='[0-9]*', exact_match=True, - tags=True, dirty=True) - assert tag == version, (tag, version) - return '.release:{version}+{sha}'.format(version=version, - sha=sha) - except git.GitCommandError: - return '.dev0+{sha}'.format(sha=sha) - - -def write_version(filename=os.path.join('airflow', 'git_version')): - cnt = """%(git_revision)s""" - text = cnt % {'git_revision': - git_version(version)} - try: - with open(filename, 'w') as a: - a.write(text) - except Exception as e: - logger.error(e) + if repo: + sha = repo.head.commit.hexsha + if repo.is_dirty(): + return '.dev0+{sha}.dirty'.format(sha=sha) + # commit is clean + # is it release of `version` ? + try: + tag = repo.git.describe( + match='[0-9]*', exact_match=True, + tags=True, dirty=True) + assert tag == version, (tag, version) + return '.release:{version}+{sha}'.format(version=version, + sha=sha) + except git.GitCommandError: + return '.dev0+{sha}'.format(sha=sha) + else: + return 'no_git_version' + + +def write_version(filename=os.path.join(*['airflow', + 'git_version'])): + text = "{}".format(git_version(version)) + with open(filename, 'w') as a: + a.write(text) async = [