summaryrefslogtreecommitdiff
path: root/plac/plac.py
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2010-06-18 07:35:04 +0200
committerMichele Simionato <michele.simionato@gmail.com>2010-06-18 07:35:04 +0200
commit00b953f00515c154dc982cd572f96eedd57558bf (patch)
tree0322d15231bd6baa8837f9c201b934a9b3f0e1da /plac/plac.py
parentd3675126815e3f134f97357c7eae245097ee2a79 (diff)
downloadmicheles-00b953f00515c154dc982cd572f96eedd57558bf.tar.gz
Gigantic commit with the improvements of plac 0.5
Diffstat (limited to 'plac/plac.py')
-rw-r--r--plac/plac.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/plac/plac.py b/plac/plac.py
index 31bc89b..361522e 100644
--- a/plac/plac.py
+++ b/plac/plac.py
@@ -30,8 +30,26 @@ See doc/plac.pdf for the documentation.
__version__ = '0.5.0'
-import sys
+import imp, os, sys
from plac_core import *
-
if sys.version >= '2.5':
- from plac_ext import Interpreter
+ from plac_ext import Interpreter, cmd_interface
+
+try:
+ PLACDIRS = os.environ.get('PLACPATH', '.').split(':')
+except:
+ raise ValueError('Ill-formed PLACPATH: got %PLACPATHs' % os.environ)
+
+def import_main(path):
+ "An utility to import the main function of a plac tool"
+ if not os.path.isabs(path): # relative path, look at PLACDIRS
+ for placdir in PLACDIRS:
+ fullpath = os.path.join(placdir, path)
+ if os.path.exists(fullpath):
+ break
+ else: # no break
+ raise ImportError('Cannot find %s', path)
+ else:
+ fullpath = path
+ name, ext = os.path.splitext(os.path.basename(fullpath))
+ return imp.load_module(name, open(fullpath), fullpath, (ext, 'U', 1)).main