diff mbox series

[v2,14/14] patman: Tidy up sys.path changes

Message ID 20200417180829.v2.14.I2693dacc2e966daeffcfd811d177558c86945ada@changeid
State Accepted
Commit b4fa94959db039c7eca4531a5b9a41baffa8b4c8
Headers show
Series tools: patman: Convert Python tools to use absolute imports | expand

Commit Message

Simon Glass April 18, 2020, 12:09 a.m. UTC
Now that we are using absolute paths we can remove some of the sys.path
mangling that appears in the tools.

We only need to add the path to 'tools/' so that everything can find
modules relative to that directory.

The special paths for finding pylibfdt remain.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 tools/binman/main.py   | 5 +++--
 tools/buildman/main.py | 3 +--
 tools/buildman/test.py | 1 -
 tools/dtoc/main.py     | 1 -
 tools/dtoc/test_fdt.py | 3 +--
 tools/genboardscfg.py  | 3 +--
 tools/moveconfig.py    | 2 --
 tools/patman/main.py   | 2 +-
 tools/rmboard.py       | 1 -
 9 files changed, 7 insertions(+), 14 deletions(-)

Comments

Simon Glass April 27, 2020, 3:06 a.m. UTC | #1
Now that we are using absolute paths we can remove some of the sys.path
mangling that appears in the tools.

We only need to add the path to 'tools/' so that everything can find
modules relative to that directory.

The special paths for finding pylibfdt remain.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 tools/binman/main.py   | 5 +++--
 tools/buildman/main.py | 3 +--
 tools/buildman/test.py | 1 -
 tools/dtoc/main.py     | 1 -
 tools/dtoc/test_fdt.py | 3 +--
 tools/genboardscfg.py  | 3 +--
 tools/moveconfig.py    | 2 --
 tools/patman/main.py   | 2 +-
 tools/rmboard.py       | 1 -
 9 files changed, 7 insertions(+), 14 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/main.py b/tools/binman/main.py
index 97a8a02034..efa7fa8386 100755
--- a/tools/binman/main.py
+++ b/tools/binman/main.py
@@ -20,8 +20,9 @@  import unittest
 # Bring in the patman and dtoc libraries (but don't override the first path
 # in PYTHONPATH)
 our_path = os.path.dirname(os.path.realpath(__file__))
-for dirname in ['../patman', '../dtoc', '../concurrencytest', '..']:
-    sys.path.insert(2, os.path.realpath(os.path.join(our_path, dirname)))
+sys.path.insert(2, os.path.join(our_path, '..'))
+
+from patman import test_util
 
 # Bring in the libfdt module
 sys.path.insert(2, 'scripts/dtc/pylibfdt')
diff --git a/tools/buildman/main.py b/tools/buildman/main.py
index 52a83fce7d..2b714739a2 100755
--- a/tools/buildman/main.py
+++ b/tools/buildman/main.py
@@ -16,7 +16,6 @@  import unittest
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
 sys.path.insert(1, os.path.join(our_path, '..'))
-sys.path.insert(2, os.path.join(our_path, '../patman'))
 
 # Our modules
 from buildman import board
@@ -35,7 +34,7 @@  def RunTests(skip_net_tests):
     import doctest
 
     result = unittest.TestResult()
-    for module in ['toolchain', 'gitutil']:
+    for module in ['buildman.toolchain', 'patman.gitutil']:
         suite = doctest.DocTestSuite(module)
         suite.run(result)
 
diff --git a/tools/buildman/test.py b/tools/buildman/test.py
index b37c37b2fa..40811ba9f9 100644
--- a/tools/buildman/test.py
+++ b/tools/buildman/test.py
@@ -11,7 +11,6 @@  import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../patman'))
 
 from buildman import board
 from buildman import bsettings
diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py
index 8f3ec1deef..5a33c57ffd 100755
--- a/tools/dtoc/main.py
+++ b/tools/dtoc/main.py
@@ -32,7 +32,6 @@  import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../patman'))
 sys.path.append(os.path.join(our_path, '..'))
 
 # Bring in the libfdt module
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index d68230713e..375e906424 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -14,8 +14,7 @@  import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-for dirname in ['../patman', '..']:
-    sys.path.insert(0, os.path.join(our_path, dirname))
+sys.path.insert(1, os.path.join(our_path, '..'))
 
 from dtoc import fdt
 from dtoc import fdt_util
diff --git a/tools/genboardscfg.py b/tools/genboardscfg.py
index 4f6382bc7c..4ee7aa1f89 100755
--- a/tools/genboardscfg.py
+++ b/tools/genboardscfg.py
@@ -22,8 +22,7 @@  import sys
 import tempfile
 import time
 
-sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'buildman'))
-import kconfiglib
+from buildman import kconfiglib
 
 ### constant variables ###
 OUTPUT_FILE = 'boards.cfg'
diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 0dd8670403..36361f9ed1 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -314,8 +314,6 @@  import tempfile
 import threading
 import time
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
-sys.path.append(os.path.join(os.path.dirname(__file__), 'patman'))
 from buildman import bsettings
 from buildman import kconfiglib
 from buildman import toolchain
diff --git a/tools/patman/main.py b/tools/patman/main.py
index f59367fafb..f3d9c0c434 100755
--- a/tools/patman/main.py
+++ b/tools/patman/main.py
@@ -13,7 +13,7 @@  import sys
 import unittest
 
 if __name__ == "__main__":
-    # Allow 'import xxx to work'
+    # Allow 'from patman import xxx to work'
     our_path = os.path.dirname(os.path.realpath(__file__))
     sys.path.append(os.path.join(our_path, '..'))
 
diff --git a/tools/rmboard.py b/tools/rmboard.py
index 1ed2527d0e..06c3562ad8 100755
--- a/tools/rmboard.py
+++ b/tools/rmboard.py
@@ -30,7 +30,6 @@  import sys
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(our_path, '../tools/patman'))
 
 from patman import command