bitbake-setup PyPI Packaging
PATCH v2 1/13 bitbake-setup: Resolve unused loop control variables
In reply to Rob WoolleyThe ruff lint tool reported loop control variables that were not being used:
B007 Loop control variable dirs not used within loop body
Adding underscore as a prefix helps indicate that it is not being used inside the loop.
--- bin/bitbake-setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
bin/bitbake-setup +3 -3
@@ -134,7 +134,7 @@ def commit_config(config_dir): def _write_layer_list(dest, repodirs): layers = [] for r in repodirs: - for root, dirs, files in os.walk(os.path.join(dest,r)): + for root, _dirs, files in os.walk(os.path.join(dest,r)): if os.path.basename(root) == 'conf' and 'layer.conf' in files: layers.append(os.path.relpath(os.path.dirname(root), dest)) layers_f = os.path.join(dest, ".oe-layers.json")
@@ -445,7 +445,7 @@ The bitbake configuration files (local.conf, bblayers.conf and more) can be foun configure_vscode(setupdir, layerdir, bitbake_builddir, init_script) def get_registry_config(registry_path, id): - for root, dirs, files in os.walk(registry_path): + for root, _dirs, files in os.walk(registry_path): for f in files: if f.endswith('.conf.json') and id == get_config_name(f): return os.path.join(root, f)
@@ -996,7 +996,7 @@ def has_expired(expiry_date): def list_registry(registry_path, with_expired): json_data = {} - for root, dirs, files in os.walk(registry_path): + for root, _dirs, files in os.walk(registry_path): for f in files: if f.endswith('.conf.json'): config_name = get_config_name(f)
Signature · 1 line
2.49.0
v2 cover bitbake-setup PyPI Packaging
This is a new series to add PyPI packaging for bitbake-setup. It is based on my development branch here: https://github.com/robwoolley/bitbake/tree/add-pypi-v6
UPDATE: This series is based on the HEAD of bitbake master. It repeats any of the previous linting fixes that have not yet been applied. As such this v2 stands alone independent of any previous emails sent by me recently.
The main challenge has been to package bitbake-setup independently from the rest of bitbake. This necessitates creating a separate staging directory with pyproject.toml at the root. Details are in the commit messages.
I have tested using these changes to package all of bitbake to make sure that these changes didn't inhibit that from working. That is beyond the scope of work for what I was trying to do.
There are 2 challenges I had to overcome:
1. Ensuring that all primary workflows worked:
(a) Running bitbake and bitbake-setup directly from git
(b) Allowing developers to use pip install -e . to develop in-tree
(c) Enabling pip install in virtual environments and at the system-level
2. Historically, he sys.path modificiations made it easy to refer to the vendorized modules without worrying about system-wide package conflicts. Adding packaging support required that the modules be properly vendorized so they didn't conflict with the upstream packages. Vendorizing the bb module resulted in too much churn as we import bb and its sub-modules across all the files in lib/bb/*
Given that the bb package on PyPI is obscure and hasn't been updated in a very long time, I chose to bundle bb instead of vendorize it.
Here are the detailed testing steps that I used to verify this series before submitting it to bitbake-devel:
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install build
$ BB_SKIP_PYPI_TESTS=no bin/bitbake-selftest -v bb.tests.setup.PyPIPackagingTest
bb.tests.setup.PyPIPackagingTesttest_console_script_help (bb.tests.setup.PyPIPackagingTest)
Verify bitbake-setup --help runs successfully. ... oktest_console_script_list (bb.tests.setup.PyPIPackagingTest)
Verify bitbake-setup list runs successfully. ... oktest_entry_points (bb.tests.setup.PyPIPackagingTest)
Verify console script entry points are correctly defined. ... oktest_imports (bb.tests.setup.PyPIPackagingTest)
Verify all expected modules can be imported from installed package. ... ok test_package_metadata (bb.tests.setup.PyPIPackagingTest)
Verify package metadata is correctly set. ... oktest_vendored_dependencies (bb.tests.setup.PyPIPackagingTest)
Verify vendored dependencies (bs4, ply, progressbar, simplediff) are not bundled in package. ... ok test_version_from_wheel (bb.tests.setup.PyPIPackagingTest)
Verify version is set correctly (not fallback 0.0.0 unless expected). ... ok test_wheel_metadata_file (bb.tests.setup.PyPIPackagingTest)
Verify wheel METADATA file contains required fields. ... ok
----------------------------------------------------------------------
Ran 8 tests in 18.014s
OK
$ contrib/pypi/package-bitbake-setup.py
$ cd packaging_workspace/
$ pip install -e .
$ which bitbake-setup /ala-lpggp31/rwoolley/bitbake-testing/bitbake/venv/bin/bitbake-setup
$ bitbake-setup --version bitbake-setup 2.16.0
$ bitbake-setup list
NOTE: Fetching configuration registry
git://git.openembedded.org/bitbake;protocol=https;branch=master;rev=master
into
/tmp/bitbake-setup-list-v1m6p7s3/.bitbake-setup-cache/configurations
Available configurations:
oe-nodistro-master OpenEmbedded - 'nodistro' basic configuration
oe-nodistro-whinlatter OpenEmbedded - 'nodistro' basic configuration, release 5.3 'whinlatter' (supported until 2026-05-31)
poky-master Poky - The Yocto Project testing distribution configurations and hardware test platforms
poky-whinlatter Poky - The Yocto Project testing distribution configurations and hardware test platforms, release 5.3 'whinlatter' (supported until 2026-05-31)Run 'init' with one of the above configuration identifiers to set up a build.
$ pip uninstall bitbake-setup
$ python3 -m build
$ pip install dist/bitbake_setup-2.16.0-py3-none-any.whl Processing ./dist/bitbake_setup-2.16.0-py3-none-any.whl Installing collected packages: bitbake-setup Successfully installed bitbake-setup-2.16.0
$ cd $(mktemp -d)
$ bitbake-setup init
...
The bitbake configuration files (local.conf, bblayers.conf and more) can be found in
/tmp/tmp.s1MXZQ5XiF/bitbake-builds/poky-whinlatter/build/conf
PATCH v2 3/13 bitbake-setup: Set function default to None
The function defaults are evaluated once and use across calls can lead to unexpected behaviour.
Set the value to none and let the function initialize the value in the case when the value is not set.
Resolves B006 from flake8-bugbear
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -46,7 +46,7 @@ def color_enabled() -> bool: def get_diff_color_param() -> str: return "--color=always" if color_enabled() else "--color=never" -def print_configs(prompt: str, choices: list[str], descriptions: list[str] = []): +def print_configs(prompt: str, choices: list[str], descriptions: list[str] = None): """ Helper function to print a list of choices and align the output. Each option name is made bold to stand out, unless color is not enabled in
Signature · 1 line
2.49.0
PATCH v2 4/13 bitbake-setup: Add checks for version information
In reply to Rob WoolleyThe __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.
--- bin/bitbake-setup | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
bin/bitbake-setup +26 -3
@@ -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)
Signature · 1 line
2.49.0
PATCH v2 5/13 bitbake-setup: Add version option
In reply to Rob WoolleyThis adds the long-form version option to match bitbake.
--- bin/bitbake-setup | 1 + 1 file changed, 1 insertion(+)
bin/bitbake-setup +1 -0
@@ -1263,6 +1263,7 @@ def main(): ) parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') + parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR') parser.add_argument('--no-network', action='store_true', help='Do not check whether configuration repositories and layer repositories have been updated; use only the local cache.') parser.add_argument('--global-settings', action='store', metavar='PATH', help='Path to the global settings file.')
Signature · 1 line
2.49.0
PATCH v2 8/13 bitbake: Add checks for importing bb module
In reply to Rob WoolleyThe __version__ has been present since bbmake to ensure that the Python script uses the appropriate bb module. This was necessary when bbmake had functional code that had to match the bb module. The code has since been moved into bb/main.py. The skeleton code left in bin/bitbake rarely changes save for bumping the version.
When executed in place, the bitbake script manipulates sys.path to find the bb module in ../lib. This path is inserted to the beginning of sys.path and it cannot be overridden. This path is inserted regardless of whether the bb module is present in the lib directory.
This adds a check for the existence of the lib/bb/__init__.py file before inserting the directory to the beginning of sys.path. This supports bitbake to be executed from inside the git repository.
It deliberately fails in the situation where lib/bb/__init__.py is missing, but the bb package exists inside a site-package directory. This situation was previously possible.
--- bin/bitbake | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
bin/bitbake +14 -10
@@ -15,23 +15,27 @@ import sys import warnings warnings.simplefilter("default") -sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), - 'lib')) -try: - import bb -except RuntimeError as exc: - sys.exit(str(exc)) +bindir = os.path.abspath(os.path.dirname(__file__)) +libdir = os.path.join(os.path.dirname(bindir), 'lib') +bbfile = os.path.join(libdir, 'bb', '__init__.py') + +if os.path.exists(bbfile): + # Execute bitbake in git repository + try: + sys.path[0:0] = [libdir] + import bb + except ImportError as e: + print(f"Could not import bb from lib: {e}", file=sys.stderr) +else: + print(f"Could not find bb module", file=sys.stderr) + sys.exit(1) from bb import cookerdata from bb.main import bitbake_main, BitBakeConfigParameters, BBMainException bb.utils.check_system_locale() -__version__ = "2.16.0" - if __name__ == "__main__": - if __version__ != bb.__version__: - sys.exit("Bitbake core version and program version mismatch!") try: sys.exit(bitbake_main(BitBakeConfigParameters(sys.argv), cookerdata.CookerConfiguration()))
Signature · 1 line
2.49.0
PATCH v2 9/13 pypi: Add PyPI packaging for bitbake-setup
In reply to Rob WoolleyWe wish to publish bitbake-setup to PyPI to improve the workflow for new users that are familiar with pip install.
In order to publish bitbake-setup as a standalone package, we must create a staging directory for Python to build the package.
The package-bitbake-setup.py automates the staging of the necessary files. You may supply your desired directory as the first argument, but packaging_workspace in the root of the git repository is chosen by default.
The packaging process and related tests have also been included as part of bitbake-selftest and lib/bb/tests/setup.py. These tests use package-bitbake-setup.py.
The tests include:
* Verify bitbake-setup --help runs successfully.
* Verify bitbake-setup list runs successfully.
* Verify console script entry points are correctly defined.
* Verify all expected modules can be imported from installed package.
* Verify package metadata is correctly set.
* Verify vendored dependencies (bs4, ply, progressbar, simplediff) are not bundled in package.
* Verify version is set correctly (not fallback 0.0.0 unless expected).
* Verify wheel METADATA file contains required fields.
The pyproject.toml, LICENSE, and README.md files are used to create the package and provide information for PyPI.
--- bin/bitbake-selftest | 2 + contrib/pypi/LICENSE | 9 + contrib/pypi/README.md | 42 ++++ contrib/pypi/package-bitbake-setup.py | 79 +++++++ contrib/pypi/pyproject.toml | 92 ++++++++ lib/bb/tests/setup.py | 289 +++++++++++++++++++++++++- 6 files changed, 512 insertions(+), 1 deletion(-) create mode 100644 contrib/pypi/LICENSE create mode 100644 contrib/pypi/README.md create mode 100755 contrib/pypi/package-bitbake-setup.py create mode 100644 contrib/pypi/pyproject.toml
bin/bitbake-selftest +2 -0
@@ -67,6 +67,8 @@ ENV_HELP = """\ Environment variables: BB_SKIP_NETTESTS set to 'yes' in order to skip tests using network connection + BB_SKIP_PYPI_TESTS set to 'no' to run PyPI packaging tests + (default: yes/skip) BB_TMPDIR_NOCLEAN set to 'yes' to preserve test tmp directories """
contrib/pypi/LICENSE new file +9 -0
@@ -0,0 +1,9 @@ +bitbake-setup is licensed under the GNU General Public License version 2.0. See +LICENSE.GPL-2.0-only for further details. + +Individual files contain the following style tags instead of the full license text: + + SPDX-License-Identifier: GPL-2.0-only + +This enables machine processing of license information based on the SPDX +License Identifiers that are here available: http://spdx.org/licenses/
contrib/pypi/README.md new file +42 -0
43 lines not on this page · raw message
contrib/pypi/package-bitbake-setup.py new file +79 -0
79 lines not on this page · raw message
contrib/pypi/pyproject.toml new file +92 -0
92 lines not on this page · raw message
lib/bb/tests/setup.py +288 -1
305 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v2 12/13 lib: Vendorize bundled third-party libraries under bb._vendor
In reply to Rob WoolleyMove ply, progressbar, simplediff, and bs4 from lib/ into lib/bb/_vendor/ to avoid conflicts with system-installed versions and to support proper packaging. These libraries contain local modifications from their upstream versions.
- Create lib/bb/_vendor/__init__.py
- Move ply/, progressbar/, simplediff/, bs4/ into bb/_vendor/
- Convert absolute self-references to relative imports within ply (yacc.py) and bs4 (20 import sites across 8 files)
- Update all external import sites to use bb._vendor prefix:
bb/pysh/pyshlex.py, bb/pysh/pyshyacc.py, bb/ui/knotty.py, bb/siggen.py, bb/fetch2/wget.py, toaster/tests/views/test_views.py
---
lib/bb/_vendor/__init__.py | 18 ++++++++++++++++++
lib/{ => bb/_vendor}/bs4/AUTHORS | 0
lib/{ => bb/_vendor}/bs4/CHANGELOG | 0
lib/{ => bb/_vendor}/bs4/LICENSE | 0
lib/{ => bb/_vendor}/bs4/__init__.py | 0
lib/{ => bb/_vendor}/bs4/builder/__init__.py | 2 +-
lib/{ => bb/_vendor}/bs4/builder/_html5lib.py | 12 ++++++------
.../_vendor}/bs4/builder/_htmlparser.py | 6 +++---
lib/{ => bb/_vendor}/bs4/builder/_lxml.py | 6 +++---
lib/{ => bb/_vendor}/bs4/css.py | 2 +-
lib/{ => bb/_vendor}/bs4/dammit.py | 0
lib/{ => bb/_vendor}/bs4/diagnose.py | 9 ++++-----
lib/{ => bb/_vendor}/bs4/element.py | 6 +++---
lib/{ => bb/_vendor}/bs4/formatter.py | 2 +-
lib/{ => bb/_vendor}/ply/__init__.py | 0
lib/{ => bb/_vendor}/ply/lex.py | 0
lib/{ => bb/_vendor}/ply/yacc.py | 6 +-----
lib/{ => bb/_vendor}/progressbar/LICENSE.txt | 0
lib/{ => bb/_vendor}/progressbar/__init__.py | 0
lib/{ => bb/_vendor}/progressbar/compat.py | 0
.../_vendor}/progressbar/progressbar.py | 0
lib/{ => bb/_vendor}/progressbar/widgets.py | 0
lib/{ => bb/_vendor}/simplediff/LICENSE | 0
lib/{ => bb/_vendor}/simplediff/__init__.py | 0
lib/bb/fetch2/wget.py | 4 ++--
lib/bb/pysh/pyshlex.py | 2 +-
lib/bb/pysh/pyshyacc.py | 2 +-
lib/bb/siggen.py | 2 +-
lib/bb/ui/knotty.py | 2 +-
lib/toaster/tests/views/test_views.py | 2 +-
30 files changed, 48 insertions(+), 35 deletions(-)
create mode 100644 lib/bb/_vendor/__init__.py
rename lib/{ => bb/_vendor}/bs4/AUTHORS (100%)
rename lib/{ => bb/_vendor}/bs4/CHANGELOG (100%)
rename lib/{ => bb/_vendor}/bs4/LICENSE (100%)
rename lib/{ => bb/_vendor}/bs4/__init__.py (100%)
rename lib/{ => bb/_vendor}/bs4/builder/__init__.py (99%)
rename lib/{ => bb/_vendor}/bs4/builder/_html5lib.py (98%)
rename lib/{ => bb/_vendor}/bs4/builder/_htmlparser.py (99%)
rename lib/{ => bb/_vendor}/bs4/builder/_lxml.py (99%)
rename lib/{ => bb/_vendor}/bs4/css.py (99%)
rename lib/{ => bb/_vendor}/bs4/dammit.py (100%)
rename lib/{ => bb/_vendor}/bs4/diagnose.py (96%)
rename lib/{ => bb/_vendor}/bs4/element.py (99%)
rename lib/{ => bb/_vendor}/bs4/formatter.py (99%)
rename lib/{ => bb/_vendor}/ply/__init__.py (100%)
rename lib/{ => bb/_vendor}/ply/lex.py (100%)
rename lib/{ => bb/_vendor}/ply/yacc.py (99%)
rename lib/{ => bb/_vendor}/progressbar/LICENSE.txt (100%)
rename lib/{ => bb/_vendor}/progressbar/__init__.py (100%)
rename lib/{ => bb/_vendor}/progressbar/compat.py (100%)
rename lib/{ => bb/_vendor}/progressbar/progressbar.py (100%)
rename lib/{ => bb/_vendor}/progressbar/widgets.py (100%)
rename lib/{ => bb/_vendor}/simplediff/LICENSE (100%)
rename lib/{ => bb/_vendor}/simplediff/__init__.py (100%)lib/bb/_vendor/__init__.py new file +18 -0
@@ -0,0 +1,18 @@ +# +# Copyright BitBake Contributors +# +# SPDX-License-Identifier: GPL-2.0-only +# + +""" +Vendored third-party libraries for BitBake. + +These libraries have been modified from their upstream versions and are +bundled here to avoid conflicts with system-installed packages. + +Vendored packages: + - bs4 (BeautifulSoup4) + - ply + - progressbar + - simplediff +"""
lib/bb/_vendor/bs4/AUTHORS renamed from lib/bs4/AUTHORS +0 -0
lib/bb/_vendor/bs4/CHANGELOG renamed from lib/bs4/CHANGELOG +0 -0
lib/bb/_vendor/bs4/LICENSE renamed from lib/bs4/LICENSE +0 -0
lib/bb/_vendor/bs4/__init__.py renamed from lib/bs4/__init__.py +0 -0
lib/bb/_vendor/bs4/builder/__init__.py renamed from lib/bs4/builder/__init__.py +1 -1
@@ -6,7 +6,7 @@ import itertools import re import warnings import sys -from bs4.element import ( +from ..element import ( CharsetMetaAttributeValue, ContentMetaAttributeValue, RubyParenthesisString,
lib/bb/_vendor/bs4/builder/_html5lib.py renamed from lib/bs4/builder/_html5lib.py +6 -6
@@ -7,14 +7,14 @@ __all__ = [ import warnings import re -from bs4.builder import ( +from . import ( DetectsXMLParsedAsHTML, PERMISSIVE, HTML, HTML_5, HTMLTreeBuilder, ) -from bs4.element import ( +from ..element import ( NamespacedAttribute, nonwhitespace_re, )
@@ -23,7 +23,7 @@ from html5lib.constants import ( namespaces, prefixes, ) -from bs4.element import ( +from ..element import ( Comment, Doctype, NavigableString,
@@ -134,7 +134,7 @@ class TreeBuilderForHtml5lib(treebuilder_base.TreeBuilder): if soup: self.soup = soup else: - from bs4 import BeautifulSoup + from .. import BeautifulSoup # TODO: Why is the parser 'html.parser' here? To avoid an # infinite loop? self.soup = BeautifulSoup(
@@ -180,7 +180,7 @@ class TreeBuilderForHtml5lib(treebuilder_base.TreeBuilder): return TextNode(Comment(data), self.soup) def fragmentClass(self): - from bs4 import BeautifulSoup + from .. import BeautifulSoup # TODO: Why is the parser 'html.parser' here? To avoid an # infinite loop? self.soup = BeautifulSoup("", "html.parser")
@@ -198,7 +198,7 @@ class TreeBuilderForHtml5lib(treebuilder_base.TreeBuilder): return treebuilder_base.TreeBuilder.getFragment(self).element def testSerializer(self, element): - from bs4 import BeautifulSoup + from .. import BeautifulSoup rv = [] doctype_re = re.compile(r'^(.*?)(?: PUBLIC "(.*?)"(?: "(.*?)")?| SYSTEM "(.*?)")?$')
lib/bb/_vendor/bs4/builder/_htmlparser.py renamed from lib/bs4/builder/_htmlparser.py +3 -3
@@ -13,16 +13,16 @@ from html.parser import HTMLParser import sys import warnings -from bs4.element import ( +from ..element import ( CData, Comment, Declaration, Doctype, ProcessingInstruction, ) -from bs4.dammit import EntitySubstitution, UnicodeDammit +from ..dammit import EntitySubstitution, UnicodeDammit -from bs4.builder import ( +from . import ( DetectsXMLParsedAsHTML, ParserRejectedMarkup, HTML,
lib/bb/_vendor/bs4/builder/_lxml.py renamed from lib/bs4/builder/_lxml.py +3 -3
@@ -14,14 +14,14 @@ except ImportError as e: from io import BytesIO from io import StringIO from lxml import etree -from bs4.element import ( +from ..element import ( Comment, Doctype, NamespacedAttribute, ProcessingInstruction, XMLProcessingInstruction, ) -from bs4.builder import ( +from . import ( DetectsXMLParsedAsHTML, FAST, HTML,
@@ -30,7 +30,7 @@ from bs4.builder import ( ParserRejectedMarkup, TreeBuilder, XML) -from bs4.dammit import EncodingDetector +from ..dammit import EncodingDetector LXML = 'lxml'
lib/bb/_vendor/bs4/css.py renamed from lib/bs4/css.py +1 -1
@@ -68,7 +68,7 @@ class CSS(object): result (a common mistake). """ # Import here to avoid circular import - from bs4.element import ResultSet + from .element import ResultSet return ResultSet(None, results) def compile(self, select, namespaces=None, flags=0, **kwargs):
lib/bb/_vendor/bs4/dammit.py renamed from lib/bs4/dammit.py +0 -0
lib/bb/_vendor/bs4/diagnose.py renamed from lib/bs4/diagnose.py +4 -5
@@ -6,9 +6,8 @@ __license__ = "MIT" import cProfile from io import BytesIO from html.parser import HTMLParser -import bs4 -from bs4 import BeautifulSoup, __version__ -from bs4.builder import builder_registry +from . import BeautifulSoup, __version__ +from .builder import builder_registry import os import pstats
@@ -219,8 +218,8 @@ def profile(num_elements=100000, parser="lxml"): filename = filehandle.name data = rdoc(num_elements) - vars = dict(bs4=bs4, data=data, parser=parser) - cProfile.runctx('bs4.BeautifulSoup(data, parser)' , vars, vars, filename) + vars = dict(BeautifulSoup=BeautifulSoup, data=data, parser=parser) + cProfile.runctx('BeautifulSoup(data, parser)' , vars, vars, filename) stats = pstats.Stats(filename) # stats.strip_dirs()
lib/bb/_vendor/bs4/element.py renamed from lib/bs4/element.py +3 -3
@@ -9,8 +9,8 @@ import re import sys import warnings -from bs4.css import CSS -from bs4.formatter import ( +from .css import CSS +from .formatter import ( Formatter, HTMLFormatter, XMLFormatter,
@@ -420,7 +420,7 @@ class PageElement(object): and not isinstance(new_child, NavigableString)): new_child = NavigableString(new_child) - from bs4 import BeautifulSoup + from . import BeautifulSoup if isinstance(new_child, BeautifulSoup): # We don't want to end up with a situation where one BeautifulSoup # object contains another. Insert the children one at a time.
lib/bb/_vendor/bs4/formatter.py renamed from lib/bs4/formatter.py +1 -1
@@ -1,4 +1,4 @@ -from bs4.dammit import EntitySubstitution +from .dammit import EntitySubstitution class Formatter(EntitySubstitution): """Describes a strategy to use when outputting a parse tree to a string.
lib/bb/_vendor/ply/__init__.py renamed from lib/ply/__init__.py +0 -0
lib/bb/_vendor/ply/lex.py renamed from lib/ply/lex.py +0 -0
lib/bb/_vendor/ply/yacc.py renamed from lib/ply/yacc.py +1 -5
@@ -100,12 +100,8 @@ try: except AttributeError: MAXINT = sys.maxsize -# Python 2.x/3.0 compatibility. def load_ply_lex(): - if sys.version_info[0] < 3: - import lex - else: - import ply.lex as lex + from . import lex return lex # This object is a stand-in for a logging object created by the
lib/bb/_vendor/progressbar/LICENSE.txt renamed from lib/progressbar/LICENSE.txt +0 -0
lib/bb/_vendor/progressbar/__init__.py renamed from lib/progressbar/__init__.py +0 -0
lib/bb/_vendor/progressbar/compat.py renamed from lib/progressbar/compat.py +0 -0
lib/bb/_vendor/progressbar/progressbar.py renamed from lib/progressbar/progressbar.py +0 -0
lib/bb/_vendor/progressbar/widgets.py renamed from lib/progressbar/widgets.py +0 -0
lib/bb/_vendor/simplediff/LICENSE renamed from lib/simplediff/LICENSE +0 -0
lib/bb/_vendor/simplediff/__init__.py renamed from lib/simplediff/__init__.py +0 -0
lib/bb/fetch2/wget.py +2 -2
@@ -27,8 +27,8 @@ from bb.fetch2 import FetchMethod from bb.fetch2 import FetchError from bb.fetch2 import logger from bb.fetch2 import runfetchcmd -from bs4 import BeautifulSoup -from bs4 import SoupStrainer +from bb._vendor.bs4 import BeautifulSoup +from bb._vendor.bs4 import SoupStrainer class WgetProgressHandler(bb.progress.LineFilterProgressHandler): """
lib/bb/pysh/pyshlex.py +1 -1
@@ -14,7 +14,7 @@ # that hard to enable pull mode. import re -from ply import lex +from bb._vendor.ply import lex from bb.pysh.sherrors import * class NeedMore(Exception):
lib/bb/pysh/pyshyacc.py +1 -1
@@ -13,7 +13,7 @@ import sys import bb.pysh.pyshlex as pyshlex tokens = pyshlex.tokens -from ply import yacc +from bb._vendor.ply import yacc import bb.pysh.sherrors as sherrors class IORedirect:
lib/bb/siggen.py +1 -1
@@ -12,7 +12,7 @@ import tempfile import pickle import bb.data import difflib -import simplediff +from bb._vendor import simplediff import json import types from contextlib import contextmanager
lib/bb/ui/knotty.py +1 -1
@@ -14,7 +14,7 @@ import io import os import sys import logging -import progressbar +from bb._vendor import progressbar import signal import bb.msg import time
lib/toaster/tests/views/test_views.py +1 -1
@@ -27,7 +27,7 @@ import toastergui from toastergui.tables import SoftwareRecipesTable import json -from bs4 import BeautifulSoup +from bb._vendor.bs4 import BeautifulSoup import string PROJECT_NAME = "test project"
Signature · 1 line
2.49.0
PATCH v2 2/13 bitbake-setup: Fix ambiguous variable names
In reply to Rob WoolleyThe ruff lint tool detected use of ambiguous variables that were named with a single letter:
E741 Ambiguous variable name: l
E741 Ambiguous variable name: f
This replaces the variables with a descriptive variable to add clarity.
--- bin/bitbake-setup | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
bin/bitbake-setup +16 -16
@@ -248,11 +248,11 @@ bitbake-setup init -L {} /path/to/repo/checkout""".format( if oesetupbuild: links = {'setup-build': oesetupbuild, 'oe-scripts': os.path.dirname(oesetupbuild), 'oe-init-build-env-dir': oeinitbuildenvdir} - for l,t in links.items(): - symlink = os.path.join(layerdir, l) + for link,item in links.items(): + symlink = os.path.join(layerdir, link) if os.path.lexists(symlink): os.remove(symlink) - os.symlink(os.path.relpath(t,layerdir),symlink) + os.symlink(os.path.relpath(item,layerdir),symlink) return layers_fixed_revisions
@@ -261,19 +261,19 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c os.makedirs(build_conf_dir) layers_s = [] - for l in layers: - l = os.path.join(layerdir, l) - layers_s.append(" {} \\".format(l)) + for layer in layers: + layer = os.path.join(layerdir, layer) + layers_s.append(" {} \\".format(layer)) - for l in filerelative_layers: + for layer in filerelative_layers: if thisdir: - l = os.path.join(thisdir, l) + layer = os.path.join(thisdir, layer) else: raise Exception("Configuration is using bb-layers-file-relative to specify " \ "a layer path relative to itself. This can be done only " \ "when the configuration is specified by its path on local " \ "disk, not when it's in a registry or is fetched over http.") - layers_s.append(" {} \\".format(l)) + layers_s.append(" {} \\".format(layer)) layers_s = "\n".join(layers_s) bblayers_conf = """BBLAYERS ?= " \\
@@ -446,9 +446,9 @@ The bitbake configuration files (local.conf, bblayers.conf and more) can be foun def get_registry_config(registry_path, id): for root, _dirs, files in os.walk(registry_path): - for f in files: - if f.endswith('.conf.json') and id == get_config_name(f): - return os.path.join(root, f) + for file in files: + if file.endswith('.conf.json') and id == get_config_name(file): + return os.path.join(root, file) raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id)) def merge_overrides_into_sources(sources, overrides):
@@ -997,10 +997,10 @@ def list_registry(registry_path, with_expired): json_data = {} for root, _dirs, files in os.walk(registry_path): - for f in files: - if f.endswith('.conf.json'): - config_name = get_config_name(f) - config_data = json.load(open(os.path.join(root, f))) + for file in files: + if file.endswith('.conf.json'): + config_name = get_config_name(file) + config_data = json.load(open(os.path.join(root, file))) config_desc = config_data["description"] expiry_date = config_data.get("expires", None) if expiry_date:
Signature · 1 line
2.49.0
PATCH v2 6/13 bitbake-setup: Add the conditional script stanza
In reply to Rob WoolleyThis ensures that the main function is only executed if the module is executed in the top-level environment.
--- bin/bitbake-setup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
bin/bitbake-setup +2 -1
@@ -1403,4 +1403,5 @@ def main(): else: parser.print_help() -main() +if __name__ == '__main__': + main()
Signature · 1 line
2.49.0
PATCH v2 7/13 bitbake-setup: Add version check and catch exceptions
In reply to Rob WoolleyThis modifies the conditional script stanza to match bitbake.
It adds a version check to ensure that the correct bb module version has been found. It also catches any exceptions thrown during execution.
--- bin/bitbake-setup | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
bin/bitbake-setup +8 -1
@@ -1404,4 +1404,11 @@ def main(): parser.print_help() if __name__ == '__main__': - main() + if __version__ != bb.__version__: + sys.exit("Bitbake core version and program version mismatch!") + try: + sys.exit(main()) + except Exception: + import traceback + traceback.print_exc() + sys.exit(1)
Signature · 1 line
2.49.0
PATCH v2 10/13 pypi: Add packaging documentation for developers
In reply to Rob Woolley--- contrib/pypi/BUILD.md | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 contrib/pypi/BUILD.md
contrib/pypi/BUILD.md new file +50 -0
@@ -0,0 +1,50 @@ +# Development Instructions + +## Requirements + +- Python >= 3.9 +- pip >= 19 (for installation) + +## Testing + +To lint the `bitbake-setup` pypi packaging, run the ruff tool. +```bash +ruff check bin/bitbake-setup contrib/pypi +``` + +The steps to build and test the `bitbake-setup` pypi packaging have been automated with the `bitbake-selftest` tool. This tool automatically creates a Python virtual environment for you. + +Run the bitbake-selftest +```bash +BB_SKIP_PYPI_TESTS=no bin/bitbake-selftest -v bb.tests.setup.PyPIPackagingTest +``` + +## Packaging + +### Create the development sandbox + +To create the development sandbox run: +```bash +contrib/pypi/package-bitbake-setup.py +cd packaging_workshop +``` + +### Building the package + +To install the development tools manually run: +```bash +python3 -m pip install -e '.[dev]' +``` + +To build a wheel (.whl) then use: +```bash +python3 -m build +``` + +This produces a wheel (.whl) file in the dist directory. This may be installed using pip. + +### Installing the package + +```bash +python3 -m pip install dist/bitbake_setup-*-py3-none-any.whl +```
Signature · 1 line
2.49.0
PATCH v2 11/13 gitignore: Ignore temporary staging directory
In reply to Rob WoolleyThis directory gets created automatically by package-bitbake-setup.py when packaging bitbake-setup for PyPI.
It is a temporary staging directory and should not be added to git.
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -17,3 +17,4 @@ lib/toaster/contrib/tts/backlog.txt lib/toaster/contrib/tts/log/* lib/toaster/contrib/tts/.cache/* lib/bb/tests/runqueue-tests/bitbake-cookerdaemon.log +packaging_workspace/
Signature · 1 line
2.49.0
PATCH v2 13/13 bb: Move codegen.py inside module
In reply to Rob WoolleyCodegen is used exclusively by bb.codeparser.PythonParser.
Move it inside the bb module to avoid exposing it externally when installing bb as a package.
---
lib/{ => bb}/codegen.py | 0
lib/bb/codeparser.py | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename lib/{ => bb}/codegen.py (100%)lib/bb/codegen.py renamed from lib/codegen.py +0 -0
lib/bb/codeparser.py +1 -1
@@ -25,9 +25,9 @@ recipe caches don't trigger "Taskhash mismatch" errors. import ast import sys -import codegen import logging import inspect +import bb.codegen import bb.pysh as pysh import bb.utils, bb.data import hashlib
Signature · 1 line
2.49.0
Re: [bitbake-devel] [PATCH v2 03/13] bitbake-setup: Set function default to None
In reply to Rob WoolleyQuoted 21 lines · Rob Woolley via lists.openembedded.org
The function defaults are evaluated once and use across calls can lead to unexpected behaviour.
Set the value to none and let the function initialize the value in the case when the value is not set.
Resolves B006 from flake8-bugbear
Signed-off-by Rob Woolley <[email protected]>---
bin/bitbake-setup | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)bin/bitbake-setup +0
-0@@ -46,7 +46,7 @@ def color_enabled() -> bool:def
get_diff_color_param()-> str:
return "--color=always" ifcolor_enabled()else "--color=never"
bin/bitbake-setup def color_enabled() -> bool: · line 49
Quoted 2 lines
bin/bitbake-setup +1
-1-def print_configs(prompt: str, choices: list[str], descriptions: list[str] = []): +def print_configs(prompt: str, choices: list[str], descriptions: list[str] = None):
This breaks the typing as None is not a list. Adrian then patched it to fix that but that caused it's own set of problems as it required python 3.10.
Whilst I agree there is a problem, I cannot take this patch in this form, we need to find a different solution.
Cheers,
Richard
Re: [bitbake-devel] [PATCH v2 01/13] bitbake-setup: Resolve unused loop control variables
In reply to Rob WoolleyQuoted 17 lines · Rob Woolley via lists.openembedded.org
The ruff lint tool reported loop control variables that were not being used:
B007 Loop control variabledirsnot used within loop bodyAdding underscore as a prefix helps indicate that it is not being used inside the loop.
Signed-off-by Rob Woolley <[email protected]>---
bin/bitbake-setup | 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)bin/bitbake-setup +0
-0@@ -134,7 +134,7 @@ def commit_config(config_dir):
Quoted 8 lines
def
_write_layer_list(dest, repodirs):
layers = []
for r in repodirs:
- for root, dirs, files in os.walk(os.path.join(dest,r)):
+ for root,_dirs, files in os.walk(os.path.join(dest,r)):
ifos.path.basename(root)== 'conf' and 'layer.conf' in files:
layers.append(os.path.relpath(os.path.dirname(root), dest))layers_f=os.path.join(dest, ".oe-layers.json")
I'd suggest just using "_" alone as the name as that is how we do it everywhere else.
Cheers,
Richard