linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-gpio@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [libgpiod][PATCH 09/11] bindings: python: decouple the version of the bindings from libgpiod API version
Date: Wed, 30 Nov 2022 13:42:29 +0100	[thread overview]
Message-ID: <20221130124231.1054001-10-brgl@bgdev.pl> (raw)
In-Reply-To: <20221130124231.1054001-1-brgl@bgdev.pl>

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Python bindings now have their own setup.py script and can be built
separately from the rest of the code-base. Let's decouple the python
package version from libgpiod API (but let's keep a module attribute
containing the API version) by introducing a version.py submodule that
can be executed by the setup.py script. This way we have a single
canonical place defining the version number.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 bindings/python/gpiod/__init__.py     |  3 ++-
 bindings/python/gpiod/ext/module.c    |  2 +-
 bindings/python/gpiod/version.py      |  5 +++++
 bindings/python/setup.py              | 10 +++-------
 bindings/python/tests/tests_module.py | 15 ++++++++-------
 5 files changed, 19 insertions(+), 16 deletions(-)
 create mode 100644 bindings/python/gpiod/version.py

diff --git a/bindings/python/gpiod/__init__.py b/bindings/python/gpiod/__init__.py
index 7854cfd..9cbb8df 100644
--- a/bindings/python/gpiod/__init__.py
+++ b/bindings/python/gpiod/__init__.py
@@ -16,8 +16,9 @@ from .exception import ChipClosedError, RequestReleasedError
 from .info_event import InfoEvent
 from .line_request import LineRequest
 from .line_settings import LineSettings
+from .version import __version__
 
-__version__ = _ext.__version__
+api_version = _ext.api_version
 
 
 def is_gpiochip_device(path: str) -> bool:
diff --git a/bindings/python/gpiod/ext/module.c b/bindings/python/gpiod/ext/module.c
index 12fb92c..8b5a032 100644
--- a/bindings/python/gpiod/ext/module.c
+++ b/bindings/python/gpiod/ext/module.c
@@ -165,7 +165,7 @@ PyMODINIT_FUNC PyInit__ext(void)
 	if (!module)
 		return NULL;
 
-	ret = PyModule_AddStringConstant(module, "__version__",
+	ret = PyModule_AddStringConstant(module, "api_version",
 					 gpiod_version_string());
 	if (ret) {
 		Py_DECREF(module);
diff --git a/bindings/python/gpiod/version.py b/bindings/python/gpiod/version.py
new file mode 100644
index 0000000..c650969
--- /dev/null
+++ b/bindings/python/gpiod/version.py
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# SPDX-FileCopyrightText: 2022 Linaro Ltd.
+# SPDX-FileCopyrightTest: 2022 Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
+
+__version__ = "2.0.0"
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index ec8f99d..2a8481c 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -32,16 +32,12 @@ with_tests = bool(environ["GPIOD_WITH_TESTS"])
 if with_tests:
     extensions.append(gpiosim_ext)
 
-# FIXME Find a better way to get the version
-version = None
-try:
-    version = environ["GPIOD_VERSION_STR"]
-except KeyError:
-    pass
+with open("gpiod/version.py", "r") as fd:
+    exec(fd.read())
 
 setup(
     name="gpiod",
     packages=find_packages(include=["gpiod"]),
     ext_modules=extensions,
-    version=version,
+    version=__version__,
 )
diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py
index 4eeae76..de56356 100644
--- a/bindings/python/tests/tests_module.py
+++ b/bindings/python/tests/tests_module.py
@@ -3,7 +3,6 @@
 
 import gpiod
 import os
-import re
 import unittest
 
 from . import gpiosim
@@ -51,9 +50,11 @@ class IsGPIOChip(TestCase):
 
 
 class VersionString(TestCase):
-    def test_version_string(self):
-        self.assertTrue(
-            re.match(
-                "^[0-9][1-9]?\\.[0-9][1-9]?([\\.0-9]?|\\-devel)$", gpiod.__version__
-            )
-        )
+
+    VERSION_PATTERN = "^[0-9][1-9]?\\.[0-9][1-9]?(\\.[0-9]?|\\-devel)$"
+
+    def test_api_version_string(self):
+        self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN)
+
+    def test_module_version(self):
+        self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN)
-- 
2.37.2


  parent reply	other threads:[~2022-11-30 12:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 12:42 [libgpiod][PATCH 00/11] treewide: an assortment of tweaks and improvements Bartosz Golaszewski
2022-11-30 12:42 ` [libgpiod][PATCH 01/11] treewide: use C enum types explicitly Bartosz Golaszewski
2022-12-01  2:06   ` Viresh Kumar
2022-11-30 12:42 ` [libgpiod][PATCH 02/11] treewide: apply formatting changes with clang-format Bartosz Golaszewski
2022-11-30 13:59   ` Andy Shevchenko
2022-12-01 14:21     ` Bartosz Golaszewski
2022-11-30 12:42 ` [libgpiod][PATCH 03/11] treewide: use plural 'events' in read_edge_event() functions Bartosz Golaszewski
2022-12-01  2:08   ` Viresh Kumar
2022-11-30 12:42 ` [libgpiod][PATCH 04/11] treewide: rename EVENT_CLOCK to CLOCK Bartosz Golaszewski
2022-12-01  2:09   ` Viresh Kumar
2022-11-30 12:42 ` [libgpiod][PATCH 05/11] gpiosim: rename HOG_DIR to DIRECTION Bartosz Golaszewski
2022-12-01  2:10   ` Viresh Kumar
2022-11-30 12:42 ` [libgpiod][PATCH 06/11] tools: display the correct license with --version Bartosz Golaszewski
2022-11-30 12:42 ` [libgpiod][PATCH 07/11] bindings: rust: make reuse happy Bartosz Golaszewski
2022-11-30 14:05   ` Andy Shevchenko
2022-11-30 16:20     ` Bartosz Golaszewski
2022-12-01  2:20       ` Viresh Kumar
2022-12-01  8:29         ` Bartosz Golaszewski
2022-12-01  9:00           ` Viresh Kumar
2022-12-01  2:14   ` Viresh Kumar
2022-11-30 12:42 ` [libgpiod][PATCH 08/11] bindings: rust: include rust sources in the release tarballs Bartosz Golaszewski
2022-12-01  2:13   ` Viresh Kumar
2022-11-30 12:42 ` Bartosz Golaszewski [this message]
2022-11-30 12:42 ` [libgpiod][PATCH 10/11] bindings: python: fix the GPIOD_WITH_TESTS build flag Bartosz Golaszewski
2022-11-30 12:42 ` [libgpiod][PATCH 11/11] bindings: python: extend setup.py Bartosz Golaszewski
2022-11-30 14:09   ` Andy Shevchenko
2022-11-30 16:16     ` Bartosz Golaszewski
2022-12-07  8:58 ` [libgpiod][PATCH 00/11] treewide: an assortment of tweaks and improvements Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221130124231.1054001-10-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).