From: Simon Glass Date: Sat, 18 Apr 2020 00:09:03 +0000 (-0600) Subject: binman: Move to absolute imports X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=16287933a852bab2ac4985a770e08c9aa69d21b1;p=u-boot.git binman: Move to absolute imports At present binman sets the python path on startup so that it can access the libraries it needs. If we convert to use absolute imports this is not necessary. Move binman to use absolute imports. This enables removable of the path adjusting in Entry also. Signed-off-by: Simon Glass --- diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py index 34c5116688..f7c3cd0d0e 100644 --- a/tools/binman/cbfs_util.py +++ b/tools/binman/cbfs_util.py @@ -20,8 +20,8 @@ import io import struct import sys +from binman import elf import command -import elf import tools # Set to True to enable printing output while working diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py index 4aa2494fee..a929612b19 100755 --- a/tools/binman/cbfs_util_test.py +++ b/tools/binman/cbfs_util_test.py @@ -16,9 +16,9 @@ import struct import tempfile import unittest -import cbfs_util -from cbfs_util import CbfsWriter -import elf +from binman import cbfs_util +from binman.cbfs_util import CbfsWriter +from binman import elf import test_util import tools diff --git a/tools/binman/control.py b/tools/binman/control.py index 82bc90d802..d715b601b9 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -10,9 +10,9 @@ import os import sys import tools -import cbfs_util +from binman import cbfs_util +from binman import elf import command -import elf import tout # List of images we plan to create @@ -60,7 +60,7 @@ def WriteEntryDocs(modules, test_missing=None): to show as missing even if it is present. Should be set to None in normal use. """ - from entry import Entry + from binman.entry import Entry Entry.WriteDocs(modules, test_missing) @@ -334,8 +334,8 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt): """ # Import these here in case libfdt.py is not available, in which case # the above help option still works. - import fdt - import fdt_util + from dtoc import fdt + from dtoc import fdt_util global images # Get the device tree ready by compiling it and copying the compiled @@ -473,7 +473,7 @@ def Binman(args): # Put these here so that we can import this module without libfdt from image import Image - import state + from binman import state if args.cmd in ['ls', 'extract', 'replace']: try: diff --git a/tools/binman/elf.py b/tools/binman/elf.py index 29fdac1b8f..335d411303 100644 --- a/tools/binman/elf.py +++ b/tools/binman/elf.py @@ -6,7 +6,6 @@ # from collections import namedtuple, OrderedDict -import command import io import os import re @@ -14,6 +13,7 @@ import shutil import struct import tempfile +import command import tools import tout diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index ac26fd51e4..e4497f30fc 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -10,8 +10,8 @@ import sys import tempfile import unittest +from binman import elf import command -import elf import test_util import tools import tout diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 1244d36c20..9f62322bed 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -9,9 +9,9 @@ import importlib import os import sys -import fdt_util +from dtoc import fdt_util import tools -from tools import ToHex, ToHexSize +from patman.tools import ToHex, ToHexSize import tout modules = {} @@ -63,7 +63,7 @@ class Entry(object): def __init__(self, section, etype, node, name_prefix=''): # Put this here to allow entry-docs and help to work without libfdt global state - import state + from binman import state self.section = section self.etype = etype @@ -108,15 +108,11 @@ class Entry(object): # Import the module if we have not already done so. if not module: - old_path = sys.path - sys.path.insert(0, os.path.join(our_path, 'etype')) try: - module = importlib.import_module(module_name) + module = importlib.import_module('binman.etype.' + module_name) except ImportError as e: raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" % (etype, node_path, module_name, e)) - finally: - sys.path = old_path modules[module_name] = module # Look up the expected class name @@ -590,9 +586,7 @@ features to produce new behaviours. modules.remove('_testing') missing = [] for name in modules: - if name.startswith('__'): - continue - module = Entry.Lookup(name, name) + module = Entry.Lookup('WriteDocs', name) docs = getattr(module, '__doc__') if test_missing == name: docs = None diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 277e10b585..ca5bb0fe1b 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -9,9 +9,9 @@ import os import sys import unittest -import entry -import fdt -import fdt_util +from binman import entry +from dtoc import fdt +from dtoc import fdt_util import tools class TestEntry(unittest.TestCase): @@ -37,11 +37,11 @@ class TestEntry(unittest.TestCase): else: reload(entry) else: - import entry + from binman import entry def testEntryContents(self): """Test the Entry bass class""" - import entry + from binman import entry base_entry = entry.Entry(None, None, None) self.assertEqual(True, base_entry.ObtainContents()) diff --git a/tools/binman/etype/__init__.py b/tools/binman/etype/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index 25a6206bf3..4cde8df6f5 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -7,8 +7,8 @@ from collections import OrderedDict -from entry import Entry, EntryArg -import fdt_util +from binman.entry import Entry, EntryArg +from dtoc import fdt_util import tools diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py index d34c7b51bf..409beaadcc 100644 --- a/tools/binman/etype/blob.py +++ b/tools/binman/etype/blob.py @@ -5,8 +5,8 @@ # Entry-type module for blobs, which are binary objects read from files # -from entry import Entry -import fdt_util +from binman.entry import Entry +from dtoc import fdt_util import tools import tout diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py index b2afa064c1..6c06943763 100644 --- a/tools/binman/etype/blob_dtb.py +++ b/tools/binman/etype/blob_dtb.py @@ -5,8 +5,8 @@ # Entry-type module for U-Boot device tree files # -from entry import Entry -from blob import Entry_blob +from binman.entry import Entry +from binman.etype.blob import Entry_blob class Entry_blob_dtb(Entry_blob): """A blob that holds a device tree @@ -18,7 +18,7 @@ class Entry_blob_dtb(Entry_blob): def __init__(self, section, etype, node): # Put this here to allow entry-docs and help to work without libfdt global state - import state + from binman import state Entry_blob.__init__(self, section, etype, node) diff --git a/tools/binman/etype/blob_named_by_arg.py b/tools/binman/etype/blob_named_by_arg.py index 344112bc42..3b4593f071 100644 --- a/tools/binman/etype/blob_named_by_arg.py +++ b/tools/binman/etype/blob_named_by_arg.py @@ -8,8 +8,8 @@ from collections import OrderedDict -from blob import Entry_blob -from entry import EntryArg +from binman.etype.blob import Entry_blob +from binman.entry import EntryArg class Entry_blob_named_by_arg(Entry_blob): diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index 35b78370b2..e9aed8310c 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -7,10 +7,10 @@ from collections import OrderedDict -import cbfs_util -from cbfs_util import CbfsWriter -from entry import Entry -import fdt_util +from binman import cbfs_util +from binman.cbfs_util import CbfsWriter +from binman.entry import Entry +from dtoc import fdt_util class Entry_cbfs(Entry): """Entry containing a Coreboot Filesystem (CBFS) @@ -165,7 +165,7 @@ class Entry_cbfs(Entry): def __init__(self, section, etype, node): # Put this here to allow entry-docs and help to work without libfdt global state - import state + from binman import state Entry.__init__(self, section, etype, node) self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86') diff --git a/tools/binman/etype/cros_ec_rw.py b/tools/binman/etype/cros_ec_rw.py index 261f8657a6..0dbe14b342 100644 --- a/tools/binman/etype/cros_ec_rw.py +++ b/tools/binman/etype/cros_ec_rw.py @@ -5,7 +5,7 @@ # Entry-type module for a Chromium OS EC image (read-write section) # -from blob_named_by_arg import Entry_blob_named_by_arg +from binman.etype.blob_named_by_arg import Entry_blob_named_by_arg class Entry_cros_ec_rw(Entry_blob_named_by_arg): diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index 5dc08b8289..820f34515a 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -8,7 +8,7 @@ This handles putting an FDT into the image with just the information about the image. """ -from entry import Entry +from binman.entry import Entry import tools import tout @@ -82,8 +82,8 @@ class Entry_fdtmap(Entry): global Fdt import libfdt - import state - from fdt import Fdt + from binman import state + from dtoc.fdt import Fdt Entry.__init__(self, section, etype, node) diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py index 3473a2b1ef..7b4fc7db91 100644 --- a/tools/binman/etype/files.py +++ b/tools/binman/etype/files.py @@ -9,8 +9,8 @@ import glob import os -from section import Entry_section -import fdt_util +from binman.etype.section import Entry_section +from dtoc import fdt_util import tools @@ -30,7 +30,7 @@ class Entry_files(Entry_section): def __init__(self, section, etype, node): # Put this here to allow entry-docs and help to work without libfdt global state - import state + from binman import state Entry_section.__init__(self, section, etype, node) self._pattern = fdt_util.GetString(self._node, 'pattern') diff --git a/tools/binman/etype/fill.py b/tools/binman/etype/fill.py index 623b7f4e95..1124ef26ea 100644 --- a/tools/binman/etype/fill.py +++ b/tools/binman/etype/fill.py @@ -3,8 +3,8 @@ # Written by Simon Glass # -from entry import Entry -import fdt_util +from binman.entry import Entry +from dtoc import fdt_util import tools class Entry_fill(Entry): diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py index 835ba5012e..a155beb617 100644 --- a/tools/binman/etype/fmap.py +++ b/tools/binman/etype/fmap.py @@ -5,10 +5,10 @@ # Entry-type module for a Flash map, as used by the flashrom SPI flash tool # -from entry import Entry -import fmap_util +from binman.entry import Entry +from binman import fmap_util import tools -from tools import ToHexSize +from patman.tools import ToHexSize import tout diff --git a/tools/binman/etype/gbb.py b/tools/binman/etype/gbb.py index a94c0fca9d..0fc7667908 100644 --- a/tools/binman/etype/gbb.py +++ b/tools/binman/etype/gbb.py @@ -9,9 +9,9 @@ from collections import OrderedDict import command -from entry import Entry, EntryArg +from binman.entry import Entry, EntryArg -import fdt_util +from dtoc import fdt_util import tools # Build GBB flags. diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index b9327dd799..176bdeb29b 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -11,8 +11,8 @@ image. import struct -from entry import Entry -import fdt_util +from binman.entry import Entry +from dtoc import fdt_util IMAGE_HEADER_MAGIC = b'BinM' IMAGE_HEADER_LEN = 8 diff --git a/tools/binman/etype/intel_cmc.py b/tools/binman/etype/intel_cmc.py index fa6f7793c6..5e6edbe4df 100644 --- a/tools/binman/etype/intel_cmc.py +++ b/tools/binman/etype/intel_cmc.py @@ -5,8 +5,8 @@ # Entry-type module for Intel Chip Microcode binary blob # -from entry import Entry -from blob import Entry_blob +from binman.entry import Entry +from binman.etype.blob import Entry_blob class Entry_intel_cmc(Entry_blob): """Entry containing an Intel Chipset Micro Code (CMC) file diff --git a/tools/binman/etype/intel_descriptor.py b/tools/binman/etype/intel_descriptor.py index b6477931d6..d4d7a26901 100644 --- a/tools/binman/etype/intel_descriptor.py +++ b/tools/binman/etype/intel_descriptor.py @@ -7,8 +7,8 @@ import struct -from entry import Entry -from blob import Entry_blob +from binman.entry import Entry +from binman.etype.blob import Entry_blob FD_SIGNATURE = struct.pack('