[PATCH v2 3/3] templates: Add Patchwork version

Daniel Axtens dja at axtens.net
Mon Feb 13 07:38:31 AEDT 2017


Hi Stephen,

> 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 <stephen at that.guru>
> ---
>  patchwork/__init__.py                    | 24 ++++++++++++
>  patchwork/context_processors.py          |  6 +++
>  patchwork/settings/base.py               |  2 +
>  patchwork/templates/patchwork/about.html |  2 +-
>  patchwork/version.py                     | 63 ++++++++++++++++++++++++++++++++
>  templates/base.html                      |  2 +-
>  tools/docker/Dockerfile                  |  2 +-
>  7 files changed, 98 insertions(+), 3 deletions(-)
>  create mode 100644 patchwork/version.py
>
> diff --git a/patchwork/__init__.py b/patchwork/__init__.py
> index e69de29..f82d711 100644
> --- a/patchwork/__init__.py
> +++ b/patchwork/__init__.py
> @@ -0,0 +1,24 @@
> +# Patchwork - automated patch tracking system
> +# Copyright (C) 2016 Stephen Finucane <stephen at that.guru>
> +#
> +# 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 = (2, 0, 0, 'alpha', 0)
> +
> +__version__ = get_latest_version(VERSION)

Hey, a use of __init__.py that I agree with! :P

> +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
I realise that git's way of doing version-N-hash is ... not immediately
intuitive, but I hesitate to mangle it futher: better the devil you know
and all that.

> +
> +
> +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 (OSError, FileNotFoundError):
> +        return ''
> +
> +    return git_version.strip().decode('utf-8')
Hmm, I'm not sure about the semantic meaning of calling strip on a
bytestring. I would have gone with .decode(...).strip(). But I have
verified that it works, so it's up to you.

Also the pedant in me would like some sort of error handling in case
someone decides to put arbitrary non-utf-8 bytes in a tag
name. errors=replace should do the trick.


> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> index 883d43a..ff05707 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/
>

For changes to Docker (and fwiw, generally):
Acked-by: Daniel Axtens <dja at axtens.net>

Regards,
Daniel


More information about the Patchwork mailing list