This is managed using a combination of hardcoded string, for installations from tarball, and 'git describe', for installations from a Git repo.
This includes installing Git in the Docker environment, to enable this in the development environment. Signed-off-by: Stephen Finucane <[email protected]> --- patchwork/__init__.py | 24 +++++++++++++++++ patchwork/context_processors.py | 6 +++++ patchwork/settings/base.py | 2 ++ patchwork/version.py | 57 +++++++++++++++++++++++++++++++++++++++++ templates/base.html | 4 +-- tools/docker/Dockerfile | 2 +- 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 patchwork/version.py diff --git a/patchwork/__init__.py b/patchwork/__init__.py index e69de29..930cb21 100644 --- a/patchwork/__init__.py +++ b/patchwork/__init__.py @@ -0,0 +1,24 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Stephen Finucane <[email protected]> +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from patchwork.version import get_latest_version + +VERSION = (1, 1, 0) + +__version__ = get_latest_version(VERSION) diff --git a/patchwork/context_processors.py b/patchwork/context_processors.py index 8f1de9e..b021b31 100644 --- a/patchwork/context_processors.py +++ b/patchwork/context_processors.py @@ -19,6 +19,12 @@ from django.contrib.sites.models import Site +import patchwork + def site(request): return {'site': Site.objects.get_current()} + + +def version(request): + return {'version': patchwork.__version__} diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py index b78ed4b..5117e71 100644 --- a/patchwork/settings/base.py +++ b/patchwork/settings/base.py @@ -70,6 +70,7 @@ if django.VERSION >= (1, 8): 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'patchwork.context_processors.site', + 'patchwork.context_processors.version', ], }, }, @@ -85,6 +86,7 @@ else: 'django.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'patchwork.context_processors.site', + 'patchwork.context_processors.version', ] diff --git a/patchwork/version.py b/patchwork/version.py new file mode 100644 index 0000000..79c1f2a --- /dev/null +++ b/patchwork/version.py @@ -0,0 +1,57 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Stephen Finucane <[email protected]> +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import subprocess +import os + + +ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), + os.pardir) + + +def get_latest_version(version): + """Returns the most recent version available. + + This is either the hard-coded version or, if using Git, the version + per the most recent Git tag. + """ + git_version = _format_git_version(_get_raw_git_version()) + str_version = '.'.join([str(x) for x in version]) + + return git_version or str_version + + +def _format_git_version(version): + """Returns a version based on Git tags.""" + if '-' in version: # after tag + # convert version-N-githash to version.postN-githash + return version.replace('-', '.post', 1) + else: # at tag + return version + + +def _get_raw_git_version(): + """Returns the raw git version via 'git-describe'.""" + try: + git_version = subprocess.check_output(['git', 'describe'], + cwd=ROOT_DIR) + except FileNotFoundError: + return '' + + return git_version.strip().decode('utf-8') diff --git a/templates/base.html b/templates/base.html index 3c9fc7d..2b8e551 100644 --- a/templates/base.html +++ b/templates/base.html @@ -112,8 +112,8 @@ {% endblock %} </div> <div id="footer"> - <a href="http://jk.ozlabs.org/projects/patchwork/">patchwork</a> - patch tracking system | <a + <a href="http://jk.ozlabs.org/projects/patchwork/">patchwork</a> + patch tracking system | version {{version}} | <a href="{% url 'help' path="about/" %}">about patchwork</a> </div> </body> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index b39204c..ea3b541 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -21,7 +21,7 @@ RUN apt-get update -qq && \ python3.5-dev python3-pip python3-setuptools python3-wheel \ python3.4-dev findutils=4.4.2-7 \ libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \ - chromium-browser build-essential && \ + chromium-browser build-essential git && \ ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/ # User -- 2.7.4 _______________________________________________ Patchwork mailing list [email protected] https://lists.ozlabs.org/listinfo/patchwork
