diff mbox series

[v2,01/14] patman: Rename the main module

Message ID 20200417180829.v2.1.I70aabada9b68784b60f1025c68623d58ab484717@changeid
State Accepted
Commit 0d7a8c40333a018e6e7c4dcf64cf6ca3d7ea4ff6
Headers show
Series tools: patman: Convert Python tools to use absolute imports | expand

Commit Message

Simon Glass April 18, 2020, 12:08 a.m. UTC
Python does not like the module name being the same as the module
directory. To allow patman modules to be used from other tools, rename
it.

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

Changes in v2: None

 tools/patman/{patman.py => main.py} | 27 ++++++++++++++-------------
 tools/patman/patman                 |  2 +-
 2 files changed, 15 insertions(+), 14 deletions(-)
 rename tools/patman/{patman.py => main.py} (93%)

Comments

Simon Glass April 27, 2020, 3:06 a.m. UTC | #1
Python does not like the module name being the same as the module
directory. To allow patman modules to be used from other tools, rename
it.

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

Changes in v2: None

 tools/patman/{patman.py => main.py} | 27 ++++++++++++++-------------
 tools/patman/patman                 |  2 +-
 2 files changed, 15 insertions(+), 14 deletions(-)
 rename tools/patman/{patman.py => main.py} (93%)

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

Patch

diff --git a/tools/patman/patman.py b/tools/patman/main.py
similarity index 93%
rename from tools/patman/patman.py
rename to tools/patman/main.py
index 7f4ac9aef4..f3d9c0c434 100755
--- a/tools/patman/patman.py
+++ b/tools/patman/main.py
@@ -12,19 +12,20 @@  import re
 import sys
 import unittest
 
+if __name__ == "__main__":
+    # Allow 'from patman import xxx to work'
+    our_path = os.path.dirname(os.path.realpath(__file__))
+    sys.path.append(os.path.join(our_path, '..'))
+
 # Our modules
-try:
-    from patman import checkpatch, command, gitutil, patchstream, \
-        project, settings, terminal, test
-except ImportError:
-    import checkpatch
-    import command
-    import gitutil
-    import patchstream
-    import project
-    import settings
-    import terminal
-    import test
+from patman import checkpatch
+from patman import command
+from patman import gitutil
+from patman import patchstream
+from patman import project
+from patman import settings
+from patman import terminal
+from patman import test
 
 
 parser = OptionParser()
@@ -85,7 +86,7 @@  if __name__ != "__main__":
 # Run our meagre tests
 elif options.test:
     import doctest
-    import func_test
+    from patman import func_test
 
     sys.argv = [sys.argv[0]]
     result = unittest.TestResult()
diff --git a/tools/patman/patman b/tools/patman/patman
index 6cc3d7a56a..11a5d8e18a 120000
--- a/tools/patman/patman
+++ b/tools/patman/patman
@@ -1 +1 @@ 
-patman.py
\ No newline at end of file
+main.py
\ No newline at end of file