diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-09-17 17:09:09 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-09-17 22:47:22 +0200 |
commit | a356306cfffcc12897c1ba377bfd1d911175033f (patch) | |
tree | 5b1abda2c74970626b583cf64794a8a281e56bc9 | |
parent | 8893d1439b4bb01f2e9c1463633461efab36693a (diff) | |
download | clufter-a356306cfffcc12897c1ba377bfd1d911175033f.tar.gz clufter-a356306cfffcc12897c1ba377bfd1d911175033f.tar.xz clufter-a356306cfffcc12897c1ba377bfd1d911175033f.zip |
Allow for convenient interactive/exploratory use
+ mention it in doc/HACKING (Interactive/exploratory use: IPython...)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r-- | __root__/doc/HACKING | 17 | ||||
-rw-r--r-- | tests/_bootstrap.py | 10 |
2 files changed, 25 insertions, 2 deletions
diff --git a/__root__/doc/HACKING b/__root__/doc/HACKING index c2e051f..058dc0b 100644 --- a/__root__/doc/HACKING +++ b/__root__/doc/HACKING @@ -149,6 +149,23 @@ x. to ease the perception of embedded XSLT snippets in the Python files, [2] http://fedorapeople.org/cgit/jpokorny/public_git/vim4projects.git +Interactive/exploratory use: IPython and friends +------------------------------------------------ + +For top-level modules, following prologue can be used: + + import os.path as op; execfile(op.join('tests', '_bootstrap.py')) + +or alternatively add this command-line option to ipython invocation: + + ipython --InteractiveShellApp.exec_files='["tests/_bootstrap.py"]' + +and from now on, one can use relative imports conveniently: + + from .utils_prog import which + + + Common problems run into (just for self-reference) -------------------------------------------------- diff --git a/tests/_bootstrap.py b/tests/_bootstrap.py index 67cd99a..70b95bc 100644 --- a/tests/_bootstrap.py +++ b/tests/_bootstrap.py @@ -6,6 +6,7 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" from sys import modules, path +from os import getcwd from os.path import basename, dirname, abspath @@ -18,8 +19,13 @@ if __name__ != 'main_bootstrap': logging.basicConfig() logging.getLogger().setLevel(environ.get('LOGLEVEL') or logging.DEBUG) -# inject PYTHONPATH we are to use -root = reduce(lambda x, y: dirname(x), xrange(2), abspath(__file__)) +# in interactive run, we have no __file__ +__file__ = str(globals().get('__file__', '')) # convert from possibly unicode +if __file__: + # inject PYTHONPATH we are to use + root = reduce(lambda x, y: dirname(x), xrange(2), abspath(__file__)) +else: + root = getcwd() path.insert(0, dirname(root)) # set the correct __package__ for relative imports |