[arch-projects] [namcap][PATCH 0/4] Add --version argument
*** BLURB HERE *** Added a --version argument to Namcap, since when I tried figuring out which version I had installed, I had to ask Pacman (there might be a simpler way, but I didn't figure it out). Patch 2 updates the current version number in the man-page. This is only done since I wanted to add a check that the version in the program is the same as the version in the manpage. Rikard Falkeborn (4): Remove obsolete version test Update manpage version and date Extract version from setup.py Add --version argument Namcap/tests/test_version.py | 37 +++++++++++++++++++++++++++++++++++++ Namcap/version.py | 25 +++++++++++++++++++++++++ namcap.1 | 5 ++++- namcap.py | 10 ++++++++-- setup.py | 3 ++- tests/version-check | 26 -------------------------- 6 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 Namcap/tests/test_version.py create mode 100644 Namcap/version.py delete mode 100755 tests/version-check -- 2.4.6
This file has not been updated since version 2.3, and noone seems to care about it. Remove it. --- tests/version-check | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100755 tests/version-check diff --git a/tests/version-check b/tests/version-check deleted file mode 100755 index 3edb4ac..0000000 --- a/tests/version-check +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# This file is part of the namcap test suite. -# It checks whether the version in namcap is the -# same throughout the program and documentation. -# Author: Abhishek Dasgupta <abhidg@gmail.com> -# License: GPL - -VERSION=2.3 - -die() { echo "$1"; exit 1; } - -setup_version() { - grep version ../setup.py | awk -F '=' '{print $2}' | sed "s/\"//g;s/,//g" -} - -manpage_version() { - head -n 1 ../namcap.1 | awk -F '\"' '{print $4}' | awk '{print $2}' -} - -if [ "$VERSION" != "$(setup_version)" ]; then - die "setup.py version not updated to $VERSION." -fi - -if [ "$VERSION" != "$(manpage_version)" ]; then - die "Manual page version not updated to $VERSION." -fi -- 2.4.6
--- namcap.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/namcap.1 b/namcap.1 index 9729699..70bb21c 100644 --- a/namcap.1 +++ b/namcap.1 @@ -1,4 +1,4 @@ -.TH namcap 1 "June 14, 2010" "namcap 2.6" "User Commands" +.TH namcap 1 "July 10, 2015" "namcap 3.2.5" "User Commands" .SH NAME namcap \- package analysis utility .SH SYNOPSIS -- 2.4.6
This will make it possible to reuse the function, and avoid having the version number defined in multiple places. --- Namcap/version.py | 25 +++++++++++++++++++++++++ setup.py | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Namcap/version.py diff --git a/Namcap/version.py b/Namcap/version.py new file mode 100644 index 0000000..9885d35 --- /dev/null +++ b/Namcap/version.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# namcap - version +# Copyright (c) 2015 Rikard Falkeborn <rikard.falkeborn@gmail.com> +# +# This program 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. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# + +def get_version(): + return '3.2.5' + +# vim: set ts=4 sw=4 noet: diff --git a/setup.py b/setup.py index e6d3956..369bd3e 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,13 @@ #!/usr/bin/env python from setuptools import setup, find_packages +import Namcap.version DATAFILES = [('/usr/share/man/man1', ['namcap.1']), ('/usr/share/namcap', ['namcap-tags', 'parsepkgbuild.sh']), ('/usr/share/doc/namcap',['README','AUTHORS','TODO'])] setup(name="namcap", - version="3.2.5", + version=Namcap.version.get_version(), description="Pacman package analyzer", author="Arch Dev Team", -- 2.4.6
* namcap --version or namcap -v prints the version and exits * Update manpage with the the new option * Add a test that the manpage version is the same as the program version --- Namcap/tests/test_version.py | 37 +++++++++++++++++++++++++++++++++++++ namcap.1 | 3 +++ namcap.py | 10 ++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Namcap/tests/test_version.py diff --git a/Namcap/tests/test_version.py b/Namcap/tests/test_version.py new file mode 100644 index 0000000..3a7e685 --- /dev/null +++ b/Namcap/tests/test_version.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# +# namcap tests - tests for the version module +# Copyright (C) 2015 Rikard Falkeborn <rikard.falkeborn@gmail.com> +# +# This program 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. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# + +import os +import unittest +import re +import Namcap.version + + +class VersionTests(unittest.TestCase): + def test_manpage(self): + ''' Test that the manpage and program has the same version.''' + here = os.path.dirname(os.path.realpath(__file__)) + with open(os.path.join(here, '..', '..', 'namcap.1')) as f: + first_line = f.readline() + match = re.search('"namcap (.*?)"', first_line) + self.assertEqual(match.group(1), Namcap.version.get_version()) + +# vim: set ts=4 sw=4 noet: diff --git a/namcap.1 b/namcap.1 index 70bb21c..a17bdf6 100644 --- a/namcap.1 +++ b/namcap.1 @@ -26,6 +26,9 @@ displays easily parseable namcap tags instead of the normal human readable descr only apply RULELIST rules to the package .IP RULELIST is a comma-separated list of rule names +.TP +.B "\-v, \-\-version" +print version and exit .SH RULES .TP .B arrays diff --git a/namcap.py b/namcap.py index cca5dd6..b62a2fa 100755 --- a/namcap.py +++ b/namcap.py @@ -31,6 +31,7 @@ import types import Namcap.depends import Namcap.tags +import Namcap.version # Functions def get_modules(): @@ -49,6 +50,7 @@ def usage(): print(" -e rulelist, --exclude=rulelist : don't apply RULELIST rules to the package") print(" -r rulelist, --rules=rulelist : only apply RULELIST rules to the package") print(" -t tags : use a custom tag file") + print(" -v version : print version and exit") sys.exit(2) @@ -171,9 +173,9 @@ filename = None # get our options and process them try: - optlist, args = getopt.getopt(sys.argv[1:], "ihmr:e:t:L", + optlist, args = getopt.getopt(sys.argv[1:], "ihmr:e:t:Lv", ["info", "help", "machine-readable", "rules=", - "exclude=", "tags=", "list"]) + "exclude=", "tags=", "list", "version"]) except getopt.GetoptError: usage() @@ -222,6 +224,10 @@ for i, k in optlist: if i in ('-t', '--tags'): filename = k + if i in ('-v', '--version'): + print(Namcap.version.get_version()) + sys.exit(0) + # If there are no args, print usage if (args == []): usage() -- 2.4.6
participants (1)
-
Rikard Falkeborn