From ddb184be550d54345cfa71fe33d7a2a281e2ae2e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 1 Feb 2018 13:33:38 +0000 Subject: [PATCH] python: Expose version of the module Signed-off-by: Michael Tremer --- src/python/location-query.in | 4 ++++ src/python/locationmodule.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/python/location-query.in b/src/python/location-query.in index 260f4bd..e750ea4 100644 --- a/src/python/location-query.in +++ b/src/python/location-query.in @@ -42,6 +42,10 @@ class CLI(object): parser.add_argument("--debug", action="store_true", help=_("Enable debug output")) + # version + parser.add_argument("--version", action="version", + version="%%(prog)s %s" % location.__version__) + # lookup an IP address lookup = subparsers.add_parser("lookup", help=_("Lookup one or multiple IP addresses"), diff --git a/src/python/locationmodule.c b/src/python/locationmodule.c index 40b0c35..dcb5a47 100644 --- a/src/python/locationmodule.c +++ b/src/python/locationmodule.c @@ -106,5 +106,11 @@ PyMODINIT_FUNC PyInit_location(void) { Py_INCREF(&WriterType); PyModule_AddObject(m, "Writer", (PyObject *)&WriterType); + // Add constants + PyObject* d = PyModule_GetDict(m); + + // Version + PyDict_SetItemString(d, "__version__", PyUnicode_FromString(VERSION)); + return m; } -- 2.39.2