public inbox for bitbake-devel@lists.openembedded.org
 help / color / mirror / Atom feed
From: Rob Woolley <rob.woolley@windriver.com>
To: <bitbake-devel@lists.openembedded.org>
Cc: <alex.kanavin@gmail.com>
Subject: [PATCH v2 04/13] bitbake-setup: Add checks for version information
Date: Tue, 31 Mar 2026 09:06:54 -0700	[thread overview]
Message-ID: <20260331160703.3137930-5-rob.woolley@windriver.com> (raw)
In-Reply-To: <20260331160703.3137930-1-rob.woolley@windriver.com>

The __version__ has been present since bbmake to ensure that the
Python script uses the appropriate bb module.  Other bitbake-*
scripts do not check the version.

When executed in place, the bitbake-* scripts manipulate sys.path
to find the bb module in ../lib. This path is inserted to the
beginning of sys.path and it cannot be overridden by any other
modules named bb.

This commit adds a check for ../lib/bb/__init__.py before making
changes to sys.path. It falls back to importing the bitbake_setup
module using a custom bitbake_setup package.

Signed-off-by: Rob Woolley <rob.woolley@windriver.com>
---
 bin/bitbake-setup | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index f90f01f55..073b18f95 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -23,10 +23,33 @@ import time
 
 
 bindir = os.path.abspath(os.path.dirname(__file__))
-sys.path[0:0] = [os.path.join(os.path.dirname(bindir), 'lib')]
+libdir = os.path.join(os.path.dirname(bindir), 'lib')
+bbfile = os.path.join(libdir, 'bb', '__init__.py')
 
-import bb.msg  # noqa: E402
-import bb.process  # noqa: E402
+# Obtain __version__ and import bb
+if os.path.exists(bbfile):
+    # Execute bitbake-setup in git repository
+    try:
+        sys.path[0:0] = [libdir]
+        import bb.msg  # noqa: E402
+        import bb.process  # noqa: E402
+        from bb import __version__  # noqa: E402
+    except ImportError as e:
+        print(f"Could not import bb from lib: {e}")
+else:
+    # Execute bitbake-setup installed with packages
+    try:
+        from importlib.metadata import version, PackageNotFoundError  # noqa:E402
+        try:
+            import bb.msg  # noqa: E402
+            import bb.process  # noqa: E402
+            __version__ = version("bitbake_setup")
+        except ImportError as e:
+            print(f"Could not import bb: {e}")
+        except PackageNotFoundError as e:
+            print(f"Could not find package bb: {e}")
+    except ImportError as e:
+        print(f"Could not import bb from package: {e}")
 
 logger = bb.msg.logger_create('bitbake-setup', sys.stdout)
 
-- 
2.49.0



  parent reply	other threads:[~2026-03-31 16:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 16:06 [PATCH v2 00/13] bitbake-setup PyPI Packaging Rob Woolley
2026-03-31 16:06 ` [PATCH v2 01/13] bitbake-setup: Resolve unused loop control variables Rob Woolley
2026-04-01 21:44   ` [bitbake-devel] " Richard Purdie
2026-03-31 16:06 ` [PATCH v2 02/13] bitbake-setup: Fix ambiguous variable names Rob Woolley
2026-03-31 16:06 ` [PATCH v2 03/13] bitbake-setup: Set function default to None Rob Woolley
2026-04-01 21:43   ` [bitbake-devel] " Richard Purdie
2026-03-31 16:06 ` Rob Woolley [this message]
2026-03-31 16:06 ` [PATCH v2 05/13] bitbake-setup: Add version option Rob Woolley
2026-03-31 16:06 ` [PATCH v2 06/13] bitbake-setup: Add the conditional script stanza Rob Woolley
2026-03-31 16:06 ` [PATCH v2 07/13] bitbake-setup: Add version check and catch exceptions Rob Woolley
2026-03-31 16:06 ` [PATCH v2 08/13] bitbake: Add checks for importing bb module Rob Woolley
2026-03-31 16:06 ` [PATCH v2 09/13] pypi: Add PyPI packaging for bitbake-setup Rob Woolley
2026-03-31 16:07 ` [PATCH v2 10/13] pypi: Add packaging documentation for developers Rob Woolley
2026-03-31 16:07 ` [PATCH v2 11/13] gitignore: Ignore temporary staging directory Rob Woolley
2026-03-31 16:07 ` [PATCH v2 12/13] lib: Vendorize bundled third-party libraries under bb._vendor Rob Woolley
2026-03-31 16:07 ` [PATCH v2 13/13] bb: Move codegen.py inside module Rob Woolley

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=20260331160703.3137930-5-rob.woolley@windriver.com \
    --to=rob.woolley@windriver.com \
    --cc=alex.kanavin@gmail.com \
    --cc=bitbake-devel@lists.openembedded.org \
    /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