bindings: python: add the __version__ module attribute
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 2 Apr 2020 08:11:23 +0000 (10:11 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 2 Apr 2020 09:02:20 +0000 (11:02 +0200)
The python module provides the version_string() function that returns
the API version but the standard way to do this according to PEP 396
is by providing the __version__ attribute at the module level.

Add __version__ constant to gpiod module and mark version_string() as
deprecated in the doc.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings/python/gpiodmodule.c

index 5b157e6863baf05b458bc143e048bbaddfbf011d..e5db26b8895464b7a48c4464817d4481ff524bdd 100644 (file)
@@ -2690,6 +2690,7 @@ static gpiod_LineObject *gpiod_Module_find_line(PyObject *Py_UNUSED(self),
 PyDoc_STRVAR(gpiod_Module_version_string_doc,
 "version_string() -> string\n"
 "\n"
+"DEPRECATED: use __version__ module attribute instead.\n"
 "Get the API version of the library as a human-readable string.");
 
 static PyObject *gpiod_Module_version_string(PyObject *Py_UNUSED(ignored0),
@@ -2934,5 +2935,10 @@ PyMODINIT_FUNC PyInit_gpiod(void)
                        return NULL;
        }
 
+       rv = PyModule_AddStringConstant(module, "__version__",
+                                       gpiod_version_string());
+       if (rv < 0)
+               return NULL;
+
        return module;
 }