catalyst: use a more pythonic method to import modules
authorDylan Baker <baker.dylan.c@gmail.com>
Sun, 13 Oct 2013 09:07:36 +0000 (02:07 -0700)
committerMatt Turner <mattst88@gmail.com>
Sat, 26 Oct 2013 17:22:39 +0000 (10:22 -0700)
Rather than appending a directory to the system path, this patch adds a
__init__.py file to modules, which allows python to search it, and it's
children for python modules. This also requires changes to a few of the
module files to make them happy.

Reviewed-by: Matt Turner <mattst88@gmail.com>
catalyst
modules/__init__.py [new file with mode: 0644]
modules/catalyst/config.py

index 11560fb4f9dc5d21f85e3467c29f0df222c706bd..2378a8727ca47877afd41f6f5bbd0f80cc66c2d7 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -11,12 +11,8 @@ import os, sys, imp, string, getopt
 import pdb
 import os.path
 
-__selfpath__ = os.path.abspath(os.path.dirname(__file__))
-
-sys.path.append(__selfpath__ + "/modules")
-
-import catalyst.config
-import catalyst.util
+import modules.catalyst.config
+import modules.catalyst.util
 
 __maintainer__="Catalyst <catalyst@gentoo.org>"
 __version__="2.0.14"
@@ -91,7 +87,7 @@ def parse_config(myconfig):
        # now, try and parse the config file "config_file"
        try:
 #              execfile(config_file, myconf, myconf)
-               myconfig = catalyst.config.ConfigParser(config_file)
+               myconfig = modules.catalyst.config.ConfigParser(config_file)
                myconf.update(myconfig.get_values())
 
        except:
@@ -226,7 +222,7 @@ def build_target(addlargs, targetmap):
                mytarget.run()
 
        except:
-               catalyst.util.print_traceback()
+               modules.catalyst.util.print_traceback()
                print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
                sys.exit(1)
 
@@ -379,12 +375,12 @@ if __name__ == "__main__":
        addlargs={}
 
        if myspecfile:
-               spec = catalyst.config.SpecParser(myspecfile)
+               spec = modules.catalyst.config.SpecParser(myspecfile)
                addlargs.update(spec.get_values())
 
        if mycmdline:
                try:
-                       cmdline = catalyst.config.ConfigParser()
+                       cmdline = modules.catalyst.config.ConfigParser()
                        cmdline.parse_lines(mycmdline)
                        addlargs.update(cmdline.get_values())
                except CatalystError:
diff --git a/modules/__init__.py b/modules/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 00da3439738ce46a349cc589693061a2b8946663..726bf7472c6427f09f625358ea9f93b9081c0d13 100644 (file)
@@ -1,5 +1,5 @@
 import re
-from catalyst_support import *
+from modules.catalyst_support import *
 
 class ParserBase: