python: Format trivial files where only newlines were missing

Apply formatting on files that only needed adding newlines.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
Pieter De Gendt 2024-11-21 11:49:59 +01:00 committed by Henrik Brix Andersen
commit f05deb1aa4
24 changed files with 63 additions and 24 deletions

View file

@ -2089,7 +2089,6 @@ exclude = [
"./samples/modules/tflite-micro/magic_wand/train/train.py",
"./samples/modules/tflite-micro/magic_wand/train/train_test.py",
"./samples/modules/thrift/hello/client/hello_client.py",
"./samples/net/cellular_modem/server/te.py",
"./samples/net/cellular_modem/server/te_udp_echo.py",
"./samples/net/cellular_modem/server/te_udp_receive.py",
"./samples/net/cloud/aws_iot_mqtt/src/creds/convert_keys.py",
@ -2100,7 +2099,6 @@ exclude = [
"./samples/subsys/zbus/remote_mock/remote_mock.py",
"./scripts/build/check_init_priorities.py",
"./scripts/build/check_init_priorities_test.py",
"./scripts/build/dir_is_writeable.py",
"./scripts/build/elf_parser.py",
"./scripts/build/file2hex.py",
"./scripts/build/gen_app_partitions.py",
@ -2120,13 +2118,11 @@ exclude = [
"./scripts/build/gen_syscalls.py",
"./scripts/build/llext_inject_slids.py",
"./scripts/build/llext_prepare_exptab.py",
"./scripts/build/llext_slidlib.py",
"./scripts/build/mergehex.py",
"./scripts/build/parse_syscalls.py",
"./scripts/build/process_gperf.py",
"./scripts/build/subfolder_list.py",
"./scripts/build/uf2conv.py",
"./scripts/build/user_wordsize.py",
"./scripts/check_maintainers.py",
"./scripts/ci/check_compliance.py",
"./scripts/ci/coverage/coverage_analysis.py",
@ -2140,7 +2136,6 @@ exclude = [
"./scripts/coredump/coredump_parser/elf_parser.py",
"./scripts/coredump/coredump_parser/log_parser.py",
"./scripts/coredump/coredump_serial_log_parser.py",
"./scripts/coredump/gdbstubs/__init__.py",
"./scripts/coredump/gdbstubs/arch/arm64.py",
"./scripts/coredump/gdbstubs/arch/arm_cortex_m.py",
"./scripts/coredump/gdbstubs/arch/risc_v.py",
@ -2152,7 +2147,6 @@ exclude = [
"./scripts/dts/gen_driver_kconfig_dts.py",
"./scripts/dts/gen_dts_cmake.py",
"./scripts/dts/gen_edt.py",
"./scripts/dts/python-devicetree/setup.py",
"./scripts/dts/python-devicetree/src/devicetree/_private.py",
"./scripts/dts/python-devicetree/src/devicetree/dtlib.py",
"./scripts/dts/python-devicetree/src/devicetree/edtlib.py",
@ -2189,7 +2183,6 @@ exclude = [
"./scripts/logging/dictionary/dictionary_parser/utils.py",
"./scripts/logging/dictionary/log_parser.py",
"./scripts/logging/dictionary/log_parser_uart.py",
"./scripts/logging/dictionary/parserlib.py",
"./scripts/make_bugs_pickle.py",
"./scripts/net/enumerate_http_status.py",
"./scripts/profiling/stackcollapse.py",
@ -2210,8 +2203,6 @@ exclude = [
"./scripts/pylib/pytest-twister-harness/tests/device/qemu_adapter_test.py",
"./scripts/pylib/pytest-twister-harness/tests/helpers/shell_test.py",
"./scripts/pylib/pytest-twister-harness/tests/plugin_test.py",
"./scripts/pylib/pytest-twister-harness/tests/resources/mock_script.py",
"./scripts/pylib/pytest-twister-harness/tests/resources/shell_simulator.py",
"./scripts/pylib/twister/expr_parser.py",
"./scripts/pylib/twister/scl.py",
"./scripts/pylib/twister/twisterlib/cmakecache.py",
@ -2224,7 +2215,6 @@ exclude = [
"./scripts/pylib/twister/twisterlib/harness.py",
"./scripts/pylib/twister/twisterlib/jobserver.py",
"./scripts/pylib/twister/twisterlib/log_helper.py",
"./scripts/pylib/twister/twisterlib/mixins.py",
"./scripts/pylib/twister/twisterlib/package.py",
"./scripts/pylib/twister/twisterlib/platform.py",
"./scripts/pylib/twister/twisterlib/quarantine.py",
@ -2247,7 +2237,6 @@ exclude = [
"./scripts/tests/twister/pytest_integration/test_harness_pytest.py",
"./scripts/tests/twister/test_cmakecache.py",
"./scripts/tests/twister/test_config_parser.py",
"./scripts/tests/twister/test_data/mixins/test_to_ignore.py",
"./scripts/tests/twister/test_environment.py",
"./scripts/tests/twister/test_errors.py",
"./scripts/tests/twister/test_handlers.py",
@ -2373,20 +2362,12 @@ exclude = [
"./scripts/west_commands/tests/test_stm32cubeprogrammer.py",
"./scripts/west_commands/tests/test_stm32flash.py",
"./scripts/west_commands/tests/test_twister.py",
"./scripts/west_commands/tests/test_xsdb.py",
"./scripts/west_commands/twister_cmd.py",
"./scripts/west_commands/zcmake.py",
"./scripts/west_commands/zephyr_ext_common.py",
"./scripts/west_commands/zspdx/cmakecache.py",
"./scripts/west_commands/zspdx/cmakefileapi.py",
"./scripts/west_commands/zspdx/cmakefileapijson.py",
"./scripts/west_commands/zspdx/datatypes.py",
"./scripts/west_commands/zspdx/getincludes.py",
"./scripts/west_commands/zspdx/licenses.py",
"./scripts/west_commands/zspdx/sbom.py",
"./scripts/west_commands/zspdx/scanner.py",
"./scripts/west_commands/zspdx/spdxids.py",
"./scripts/west_commands/zspdx/util.py",
"./scripts/west_commands/zspdx/walker.py",
"./scripts/west_commands/zspdx/writer.py",
"./scripts/zephyr_module.py",
@ -2409,7 +2390,6 @@ exclude = [
"./tests/drivers/can/host/pytest/can_shell.py",
"./tests/drivers/can/host/pytest/conftest.py",
"./tests/drivers/can/host/pytest/test_can.py",
"./tests/kernel/timer/timer_behavior/pytest/conftest.py",
"./tests/kernel/timer/timer_behavior/pytest/saleae_logic2.py",
"./tests/kernel/timer/timer_behavior/pytest/test_timer.py",
"./tests/misc/check_init_priorities/validate_check_init_priorities_output.py",
@ -2421,12 +2401,9 @@ exclude = [
"./tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py",
"./tests/net/lib/lwm2m/interop/pytest/test_nosec.py",
"./tests/net/lib/lwm2m/interop/pytest/test_portfolio.py",
"./tests/net/socket/tls_configurations/pytest/conftest.py",
"./tests/net/socket/tls_configurations/pytest/test_app_vs_openssl.py",
"./tests/net/socket/udp/generate-c-string.py",
"./tests/subsys/debug/gdbstub/pytest/conftest.py",
"./tests/subsys/debug/gdbstub/pytest/test_gdbstub.py",
"./tests/subsys/logging/dictionary/pytest/conftest.py",
"./tests/subsys/logging/dictionary/pytest/test_logging_dictionary.py",
"./tests/ztest/ztest_param/pytest/test_parameters.py",
]

View file

@ -13,10 +13,12 @@ udp_receive.start()
print("started")
def terminate_handler(a, b):
udp_echo.stop()
udp_receive.stop()
print("stopped")
signal.signal(signal.SIGTERM, terminate_handler)
signal.signal(signal.SIGINT, terminate_handler)

View file

@ -2,10 +2,12 @@
import os
import sys
def main():
is_writeable = os.access(sys.argv[1], os.W_OK)
return_code = int(not is_writeable)
sys.exit(return_code)
if __name__ == "__main__":
main()

View file

@ -25,6 +25,7 @@ IMPLEMENTATION NOTES:
from hashlib import sha256
def generate_slid(symbol_name: str, slid_size: int) -> int:
"""
Generates the Symbol Link Identifier (SLID) for a symbol.
@ -40,6 +41,7 @@ def generate_slid(symbol_name: str, slid_size: int) -> int:
hash = m.digest()
return int.from_bytes(hash[0:slid_size], byteorder='big', signed=False)
def format_slid(slid: int, slid_size: int) -> str:
if slid_size == 4:
fmt = f"0x{slid:08X}"
@ -47,6 +49,7 @@ def format_slid(slid: int, slid_size: int) -> str:
fmt = f"0x{slid:016X}"
return fmt
def repl():
while True:
sym_name = input("Symbol name? ")
@ -56,6 +59,7 @@ def repl():
print(f" 64-bit SLID for '{sym_name}': {format_slid(slid64, 8)}")
print()
if __name__ == "__main__":
print("LLEXT SLID calculation REPL")
print("Press ^C to exit.")

View file

@ -4,9 +4,11 @@
import struct
import sys
def main():
print(struct.calcsize("P") * 8)
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -11,6 +11,7 @@ from gdbstubs.arch.risc_v import GdbStub_RISC_V
from gdbstubs.arch.xtensa import GdbStub_Xtensa
from gdbstubs.arch.arm64 import GdbStub_ARM64
class TgtCode:
UNKNOWN = 0
X86 = 1
@ -20,6 +21,7 @@ class TgtCode:
XTENSA = 5
ARM64 = 6
def get_gdbstub(logfile, elffile):
stub = None

View file

@ -18,7 +18,6 @@ setuptools.setup(
# TBD, just use these for now.
author='Zephyr Project',
author_email='devel@lists.zephyrproject.org',
name='devicetree',
version=version,
description='Python libraries for devicetree',

View file

@ -11,12 +11,14 @@ Parser library for Dictionary-based Logging
This library along with dictionary_parser converts the
input binary data to the log using log database.
"""
import sys
import logging
import dictionary_parser
from dictionary_parser.log_database import LogDatabase
def parser(logdata, dbfile, logger):
"""function of serial parser"""
# Read from database file

View file

@ -6,6 +6,7 @@
"""
Simply mock for bash script to use with unit tests.
"""
import sys
import time
from argparse import ArgumentParser

View file

@ -5,6 +5,7 @@
"""
Simple shell simulator.
"""
import sys
from zen_of_python import zen_of_python

View file

@ -3,5 +3,6 @@
# Copyright (c) 2018 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
class DisablePyTestCollectionMixin(object):
__test__ = False

View file

@ -1,5 +1,6 @@
from twisterlib.mixins import DisablePyTestCollectionMixin
class TestClassToIgnore(DisablePyTestCollectionMixin):
def test_to_ignore(self):
assert False

View file

@ -41,6 +41,7 @@ TEST_CASES = [
},
]
@pytest.mark.parametrize("tc", TEST_CASES)
@patch("runners.xsdb.os.path.exists", return_value=True)
@patch("runners.xsdb.XSDBBinaryRunner.check_call")
@ -59,6 +60,7 @@ def test_xsdbbinaryrunner_init(check_call, path_exists, tc, runner_config):
assert check_call.call_args_list == [call(tc["expected_cmd"])]
@pytest.mark.parametrize("tc", TEST_CASES)
@patch("runners.xsdb.os.path.exists", return_value=True)
@patch("runners.xsdb.XSDBBinaryRunner.check_call")

View file

@ -4,6 +4,7 @@
from west import log
# Parse a CMakeCache file and return a dict of key:value (discarding
# type hints).
def parseCMakeCacheFile(filePath):

View file

@ -4,6 +4,7 @@
from enum import Enum
# DocumentConfig contains settings used to configure how the SPDX Document
# should be built.
class DocumentConfig:
@ -20,6 +21,7 @@ class DocumentConfig:
# docs will use to refer to this one
self.docRefID = ""
# Document contains the data assembled by the SBOM builder, to be used to
# create the actual SPDX Document.
class Document:
@ -56,6 +58,7 @@ class Document:
# written to disk, so that others can refer to it
self.myDocSHA1 = ""
# PackageConfig contains settings used to configure how an SPDX Package should
# be built.
class PackageConfig:
@ -95,6 +98,7 @@ class PackageConfig:
# may want to note this in a Package comment field
self.relativeBaseDir = ""
# Package contains the data assembled by the SBOM builder, to be used to
# create the actual SPDX Package.
class Package:
@ -131,6 +135,7 @@ class Package:
# If this Package was a target, which File was its main build product?
self.targetBuildFile = None
# RelationshipDataElementType defines whether a RelationshipData element
# (e.g., the "owner" or the "other" element) is a File, a target Package,
# a Package's ID (as other only, and only where owner type is DOCUMENT),
@ -142,6 +147,7 @@ class RelationshipDataElementType(Enum):
PACKAGEID = 3
DOCUMENT = 4
# RelationshipData contains the pre-analysis data about a relationship between
# Files and/or Packages/targets. It is eventually parsed into a corresponding
# Relationship after we have organized the SPDX Package and File data.
@ -179,6 +185,7 @@ class RelationshipData:
# from table 68 in section 11.1 of SPDX spec v2.3
self.rlnType = ""
# Relationship contains the post-analysis, processed data about a relationship
# in a form suitable for creating the actual SPDX Relationship in a particular
# Document's context.
@ -198,6 +205,7 @@ class Relationship:
# from table 68 in section 11.1 of SPDX spec v2.3
self.rlnType = ""
# File contains the data needed to create a File element in the context of a
# particular SPDX Document and Package.
class File:

View file

@ -6,6 +6,7 @@ from subprocess import run, PIPE
from west import log
# Given a path to the applicable C compiler, a C source file, and the
# corresponding TargetCompileGroup, determine which include files would
# be used.
@ -37,6 +38,7 @@ def getCIncludes(compilerPath, srcFile, tcg):
# response will be in cp.stderr, not cp.stdout
return extractIncludes(cp.stderr)
# Parse the response from the CC -E -H call, to extract the include file paths
def extractIncludes(resp):
includes = set()

View file

@ -10,6 +10,7 @@ from zspdx.walker import WalkerConfig, Walker
from zspdx.scanner import ScannerConfig, scanDocument
from zspdx.writer import writeSPDX
# SBOMConfig contains settings that will be passed along to the various
# SBOM maker subcomponents.
class SBOMConfig:
@ -31,6 +32,7 @@ class SBOMConfig:
# should also add an SPDX document for the SDK?
self.includeSDK = False
# create Cmake file-based API directories and query file
# Arguments:
# 1) build_dir: build directory
@ -60,6 +62,7 @@ def setupCmakeQuery(build_dir):
cm_fd.close()
return True
# main entry point for SBOM maker
# Arguments:
# 1) cfg: SBOMConfig

View file

@ -11,6 +11,7 @@ from west import log
from zspdx.licenses import LICENSES
from zspdx.util import getHashes
# ScannerConfig contains settings used to configure how the SPDX
# Document scanning should occur.
class ScannerConfig:
@ -36,6 +37,7 @@ class ScannerConfig:
# should we calculate MD5 hashes for each Package's Files?
self.doMD5 = False
def parseLineForExpression(line):
"""Return parsed SPDX expression if tag found in line, or None otherwise."""
p = line.partition("SPDX-License-Identifier:")
@ -47,6 +49,7 @@ def parseLineForExpression(line):
expression = expression.strip()
return expression
def getExpressionData(filePath, numLines):
"""
Scans the specified file for the first SPDX-License-Identifier:
@ -77,6 +80,7 @@ def getExpressionData(filePath, numLines):
# if we get here, we didn't find an expression
return None
def splitExpression(expression):
"""
Parse a license expression into its constituent identifiers.
@ -96,6 +100,7 @@ def splitExpression(expression):
return sorted(e4)
def calculateVerificationCode(pkg):
"""
Calculate the SPDX Package Verification Code for all files in the package.
@ -114,6 +119,7 @@ def calculateVerificationCode(pkg):
hSHA1.update(filelist.encode('utf-8'))
return hSHA1.hexdigest()
def checkLicenseValid(lic, doc):
"""
Check whether this license ID is a valid SPDX license ID, and add it
@ -126,6 +132,7 @@ def checkLicenseValid(lic, doc):
if lic not in LICENSES:
doc.customLicenseIDs.add(lic)
def getPackageLicenses(pkg):
"""
Extract lists of all concluded and infoInFile licenses seen.
@ -143,6 +150,7 @@ def getPackageLicenses(pkg):
licsFromFiles.add(licInfo)
return sorted(list(licsConcluded)), sorted(list(licsFromFiles))
def normalizeExpression(licsConcluded):
"""
Combine array of license expressions into one AND'd expression,
@ -170,6 +178,7 @@ def normalizeExpression(licsConcluded):
revised.append(lic)
return " AND ".join(revised)
def scanDocument(cfg, doc):
"""
Scan for licenses and calculate hashes for all Files and Packages

View file

@ -4,6 +4,7 @@
import re
def getSPDXIDSafeCharacter(c):
"""
Converts a character to an SPDX-ID-safe character.
@ -17,6 +18,7 @@ def getSPDXIDSafeCharacter(c):
return c
return "-"
def convertToSPDXIDSafe(s):
"""
Converts a filename or other string to only SPDX-ID-safe characters.
@ -30,6 +32,7 @@ def convertToSPDXIDSafe(s):
"""
return "".join([getSPDXIDSafeCharacter(c) for c in s])
def getUniqueFileID(filenameOnly, timesSeen):
"""
Find an SPDX ID that is unique among others seen so far.

View file

@ -6,6 +6,7 @@ import hashlib
from west import log
def getHashes(filePath):
"""
Scan for and return hashes.

View file

@ -6,19 +6,23 @@ import pytest
from pathlib import Path
def pytest_addoption(parser):
parser.addoption('--tool')
parser.addoption('--tool-options')
parser.addoption('--sys-clock-hw-cycles-per-sec', default=None)
@pytest.fixture()
def tool(request):
return request.config.getoption('--tool')
@pytest.fixture()
def tool_options(request):
return request.config.getoption('--tool-options')
@pytest.fixture()
def config(request):
build_dir = Path(request.config.getoption('--build-dir'))
@ -33,6 +37,7 @@ def config(request):
return cfgs
@pytest.fixture()
def sys_clock_hw_cycles_per_sec(request, config):
if request.config.getoption('--sys-clock-hw-cycles-per-sec'):

View file

@ -4,14 +4,17 @@
import pytest
def pytest_addoption(parser):
parser.addoption('--server-type')
parser.addoption('--port')
@pytest.fixture()
def server_type(request):
return request.config.getoption('--server-type')
@pytest.fixture()
def port(request):
return request.config.getoption('--port')

View file

@ -6,20 +6,26 @@
import pytest
def pytest_addoption(parser):
parser.addoption('--gdb_target_remote')
parser.addoption('--gdb_timeout')
parser.addoption('--gdb_script')
@pytest.fixture()
def gdb_script(request):
return request.config.getoption('--gdb_script')
@pytest.fixture()
def gdb_timeout(request):
return int(request.config.getoption('--gdb_timeout', default=60))
@pytest.fixture()
def gdb_target_remote(request):
return request.config.getoption('--gdb_target_remote', default=":5678")
#

View file

@ -6,9 +6,11 @@
import pytest
def pytest_addoption(parser):
parser.addoption('--fpu', action="store_true")
@pytest.fixture()
def is_fpu_build(request):
return request.config.getoption('--fpu')