More pylibfdt updates
cover More pylibfdt updates
Another batch of pylibfdt updates. This series updates the README for installing, adds metadata for packaging, and reworks the tests to be able to run standalone using python test programs (pytest and tox).
A test package is uploaded here: https://test.pypi.org/project/libfdt/
Rob
Rob Herring (6):
README: Update pylibfdt install instructions
pylibfdt: Add packaging metadata
pylibfdt_tests: Don't depend on built dtbs
tests: rename pylibfdt_tests.py to test_pylibfdt.py
pylibfdt: Include tests and test data in packaging
pylibfdt: Add tox support
MANIFEST.in | 7 ++++++
README | 24 ++++++++++++-------
setup.py | 17 +++++++++++++
tests/run_tests.sh | 3 +--
tests/{pylibfdt_tests.py => test_pylibfdt.py} | 22 ++++++++++-------
tox.ini | 6 +++++
6 files changed, 60 insertions(+), 19 deletions(-)
rename tests/{pylibfdt_tests.py => test_pylibfdt.py} (97%)
create mode 100644 tox.iniSignature · 1 line
2.32.0
PATCH 1/6 README: Update pylibfdt install instructions
In reply to a message not in the archiveNow that pip is supported for installs, update the install instructions to use it. Using pip over setup.py is generally recommended and simpler.
Also, drop 'SETUP_PREFIX' as it doesn't exist anywhere.
--- README | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
README +13 -7
@@ -48,18 +48,24 @@ If you add new features, please check code coverage: # Open 'htmlcov/index.html' in your browser -To install the library via the normal setup.py method, use: +The library can be installed with pip from a local source tree: - ./pylibfdt/setup.py install [--prefix=/path/to/install_dir] + pip install . [--user|--prefix=/path/to/install_dir] -If --prefix is not provided, the default prefix is used, typically '/usr' -or '/usr/local'. See Python's distutils documentation for details. You can -also install via the Makefile if you like, but the above is more common. +Or directly from a remote git repo: + + pip install git+git://git.kernel.org/pub/scm/utils/dtc/dtc.git@main + +The install depends on libfdt shared library being installed on the host system +first. Generally, using --user or --prefix is not necessary and pip will use the +default location for the Python installation which varies if the user is root or +not. + +You can also install everything via make if you like, but pip is recommended. To install both libfdt and pylibfdt you can use: - make install [SETUP_PREFIX=/path/to/install_dir] \ - [PREFIX=/path/to/install_dir] + make install [PREFIX=/path/to/install_dir] To disable building the python library, even if swig and Python are available, use:
Signature · 1 line
2.32.0
PATCH 2/6 pylibfdt: Add packaging metadata
In reply to a message not in the archivePyPI expects to have various package metadata including long description, license, and classifiers. Add them.
---
A test package is here: https://test.pypi.org/project/libfdt/
--- MANIFEST.in | 3 +++ setup.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+)
MANIFEST.in +3 -0
@@ -1,6 +1,9 @@ # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) global-exclude * +include README +include GPL +include BSD-2-Clause include setup.py include pylibfdt/libfdt.i include pylibfdt/*.py
setup.py +17 -0
@@ -17,6 +17,9 @@ import sys srcdir = os.path.dirname(__file__) +with open("README", "r") as fh: + long_description = fh.read() + def get_top_builddir(): if '--top-builddir' in sys.argv: index = sys.argv.index('--top-builddir')
@@ -49,4 +52,18 @@ setup( ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')}, py_modules=['libfdt'], + + long_description=long_description, + long_description_content_type="text/plain", + url="https://git.kernel.org/pub/scm/utils/dtc/dtc.git", + license="BSD", + license_files=["GPL", "BSD-2-Clause"], + + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: BSD License", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", + "Operating System :: OS Independent", + ], + )
Signature · 1 line
2.32.0
PATCH 3/6 pylibfdt_tests: Don't depend on built dtbs
In reply to a message not in the archiveThe pylibfdt tests depend on the rest of the tests to build dtbs, but are otherwise independent. Modify the test to build dtbs itself so the python tests can run standalone.
This also fixes an intermittent problem with the DT strings section size varying depending on how the dtb was built. The test assumed the dtb was built with '-H both' option which is pretty much impossible to tell from run_tests.sh.
--- tests/pylibfdt_tests.py | 22 ++++++++++++++-------- tests/run_tests.sh | 1 - 2 files changed, 14 insertions(+), 9 deletions(-)
tests/pylibfdt_tests.py +14 -8
@@ -4,10 +4,14 @@ # Written by Simon Glass <[email protected]> # +import os import struct import sys import types import unittest +import subprocess + +testsrc = os.path.dirname(__file__) sys.path.insert(0, '../pylibfdt') import libfdt
@@ -64,8 +68,9 @@ def _ReadFdt(fname): Returns: Fdt bytearray suitable for passing to libfdt functions """ - with open(fname, mode='rb') as f: - return libfdt.Fdt(f.read()) + + dtb = subprocess.run(['dtc', '-O', 'dtb', fname], stdout=subprocess.PIPE) + return libfdt.Fdt(dtb.stdout) class PyLibfdtBasicTests(unittest.TestCase): """Test class for basic pylibfdt access functions
@@ -76,9 +81,9 @@ class PyLibfdtBasicTests(unittest.TestCase): def setUp(self): """Read in the device tree we use for testing""" - self.fdt = _ReadFdt('test_tree1.dtb') - self.fdt2 = _ReadFdt('test_props.dtb') - self.fdt3 = _ReadFdt('aliases.dtb') + self.fdt = _ReadFdt(os.path.join(testsrc, 'test_tree1.dts')) + self.fdt2 = _ReadFdt(os.path.join(testsrc, 'test_props.dts')) + self.fdt3 = _ReadFdt(os.path.join(testsrc, 'aliases.dts')) def GetPropList(self, node_path): """Read a list of properties from a node
@@ -291,7 +296,7 @@ class PyLibfdtBasicTests(unittest.TestCase): self.assertEqual(self.fdt.version(), 17) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) - self.assertEqual(self.fdt.size_dt_strings(), 105) + self.assertEqual(self.fdt.size_dt_strings(), 97) self.assertEqual(self.fdt.size_dt_struct(), 564) def testPack(self):
@@ -575,8 +580,9 @@ class PyLibfdtRoTests(unittest.TestCase): def setUp(self): """Read in the device tree we use for testing""" - with open('test_tree1.dtb', mode='rb') as f: - self.fdt = libfdt.FdtRo(f.read()) + dtb = subprocess.run(['dtc', '-O', 'dtb', os.path.join(testsrc, 'test_tree1.dts')], + stdout=subprocess.PIPE) + self.fdt = libfdt.FdtRo(dtb.stdout) def testAccess(self): """Basic sanity check for the FdtRo class"""
tests/run_tests.sh +0 -1
@@ -1012,7 +1012,6 @@ fdtoverlay_tests() { } pylibfdt_tests () { - run_dtc_test -I dts -O dtb -o test_props.dtb "$SRCDIR/test_props.dts" TMP=/tmp/tests.stderr.$$ $PYTHON "$SRCDIR/pylibfdt_tests.py" -v 2> $TMP
Signature · 1 line
2.32.0
PATCH 4/6 tests: rename pylibfdt_tests.py to test_pylibfdt.py
In reply to a message not in the archiveThis follows the normal Python test_*.py naming convention. With this change, pytest can automatically find and run the tests.
---
README | 4 ++--
tests/run_tests.sh | 2 +-
tests/{pylibfdt_tests.py => test_pylibfdt.py} | 0
3 files changed, 3 insertions(+), 3 deletions(-)
rename tests/{pylibfdt_tests.py => test_pylibfdt.py} (100%)README +2 -2
@@ -32,7 +32,7 @@ compatible=subnode1 >>> print(fdt.getprop(node2, 'compatible').as_str()) test_tree1 -You will find tests in tests/pylibfdt_tests.py showing how to use each +You will find tests in tests/test_pylibfdt.py showing how to use each method. Help is available using the Python help command, e.g.: $ cd pylibfdt
@@ -43,7 +43,7 @@ If you add new features, please check code coverage: $ sudo apt-get install python3-coverage $ cd tests # It's just 'coverage' on most other distributions - $ python3-coverage run pylibfdt_tests.py + $ python3-coverage run test_pylibfdt.py $ python3-coverage html # Open 'htmlcov/index.html' in your browser
tests/run_tests.sh +1 -1
@@ -1013,7 +1013,7 @@ fdtoverlay_tests() { pylibfdt_tests () { TMP=/tmp/tests.stderr.$$ - $PYTHON "$SRCDIR/pylibfdt_tests.py" -v 2> $TMP + $PYTHON "$SRCDIR/test_pylibfdt.py" -v 2> $TMP # Use the 'ok' message meaning the test passed, 'ERROR' meaning it failed # and the summary line for total tests (e.g. 'Ran 17 tests in 0.002s').
tests/test_pylibfdt.py renamed from tests/pylibfdt_tests.py +0 -0
Signature · 1 line
2.32.0
PATCH 5/6 pylibfdt: Include tests and test data in packaging
In reply to a message not in the archivePackaging the tests is necessary for tox to work.
--- MANIFEST.in | 4 ++++ 1 file changed, 4 insertions(+)
MANIFEST.in +4 -0
@@ -10,3 +10,7 @@ include pylibfdt/*.py include libfdt/libfdt.h include libfdt/fdt.h include libfdt/libfdt_env.h +include tests/test_pylibfdt.py +include tests/test_tree1.dts +include tests/test_props.dts +include tests/aliases.dts
Signature · 1 line
2.32.0
PATCH 6/6 pylibfdt: Add tox support
In reply to a message not in the archive'tox' allows running python tests under multiple environments.
Note that installing python versions is outside the scope of tox.
--- tox.ini | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tox.ini
tox.ini new file +6 -0
@@ -0,0 +1,6 @@ +[tox] +envlist = py36,py37,py38,py39,py310 + +[testenv] +deps = pytest +commands = pytest
Signature · 1 line
2.32.0
Re: [PATCH 3/6] pylibfdt_tests: Don't depend on built dtbs
In reply to a message not in the archiveQuoted 10 lines · Rob Herring
The pylibfdt tests depend on the rest of the tests to build dtbs, but are otherwise independent. Modify the test to build dtbs itself so the python tests can run standalone.
This also fixes an intermittent problem with the DT strings section size varying depending on how the dtb was built. The test assumed the dtb was built with '-H both' option which is pretty much impossible to tell from
run_tests.sh.Signed-off-by Rob Herring <[email protected]>
This breaks "make check" for me. I think it's relying on there being an already built dtc in the path, rather than specifically running the dtc built from the source tree.
======================================================================
ERROR: testAccess (__main__.PyLibfdtRoTests)
Basic sanity check for the FdtRo class
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/dwg/src/dtc/tests/./pylibfdt_tests.py", line 583, in setUp
dtb = subprocess.run(['dtc', '-O', 'dtb', os.path.join(testsrc, 'test_tree1.dts')],
File "/usr/lib64/python3.10/subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib64/python3.10/subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib64/python3.10/subprocess.py", line 1842, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dtc'
----------------------------------------------------------------------
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 6 lines · Rob Herring
Another batch of pylibfdt updates. This series updates the README for installing, adds metadata for packaging, and reworks the tests to be able to run standalone using python test programs (pytest and tox).
A test package is uploaded here:
https://test.pypi.org/project/libfdt/
1..2 applied. I have some questions about 3.
Quoted 21 lines
Rob
Rob Herring (6):
README: Update pylibfdt install instructions
pylibfdt: Add packaging metadata
pylibfdt_tests: Don't depend on built dtbs
tests: renamepylibfdt_tests.pytotest_pylibfdt.py
pylibfdt: Include tests and test data in packaging
pylibfdt: Add tox supportMANIFEST.in | 7 ++++++ README | 24 ++++++++++++------- setup.py | 17 +++++++++++++ tests/run_tests.sh | 3 +-- tests/{pylibfdt_tests.py => test_pylibfdt.py} | 22 ++++++++++------- tox.ini | 6 +++++ 6 files changed, 60 insertions(+), 19 deletions(-) rename tests/{pylibfdt_tests.py => test_pylibfdt.py} (97%) create mode 100644 tox.ini
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson