Merge lp:~fdo.perez/ipython/trunk-dev into lp:ipython/0.11
- trunk-dev
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~fdo.perez/ipython/trunk-dev |
Merge into: | lp:ipython/0.11 |
Diff against target: |
12304 lines (+6035/-2557) 88 files modified
IPython/__init__.py (+12/-9) IPython/config/loader.py (+66/-25) IPython/config/tests/test_loader.py (+9/-10) IPython/core/application.py (+206/-81) IPython/core/completer.py (+89/-73) IPython/core/crashhandler.py (+41/-47) IPython/core/debugger.py (+33/-0) IPython/core/history.py (+47/-25) IPython/core/hooks.py (+1/-2) IPython/core/ipapp.py (+295/-184) IPython/core/iplib.py (+240/-179) IPython/core/magic.py (+96/-60) IPython/core/prefilter.py (+72/-15) IPython/core/prompts.py (+20/-8) IPython/core/pylabtools.py (+145/-0) IPython/core/quitter.py (+12/-7) IPython/core/release.py (+1/-1) IPython/core/tests/obj_del.py (+0/-35) IPython/core/tests/simpleerr.py (+32/-0) IPython/core/tests/tclass.py (+14/-10) IPython/core/tests/test_completer.py (+35/-0) IPython/core/tests/test_iplib.py (+216/-28) IPython/core/tests/test_magic.py (+137/-190) IPython/core/tests/test_prefilter.py (+34/-0) IPython/core/tests/test_run.py (+174/-0) IPython/core/ultratb.py (+60/-21) IPython/core/usage.py (+34/-325) IPython/extensions/parallelmagic.py (+4/-0) IPython/extensions/pretty.py (+3/-58) IPython/extensions/tests/test_pretty.py (+51/-6) IPython/external/_numpy_testing_utils.py (+120/-0) IPython/external/argparse.py (+89/-38) IPython/external/decorators.py (+245/-51) IPython/frontend/prefilterfrontend.py (+17/-37) IPython/frontend/tests/test_prefilterfrontend.py (+9/-6) IPython/gui/wx/ipshell_nonblocking.py (+15/-14) IPython/kernel/__init__.py (+1/-1) IPython/kernel/clusterdir.py (+53/-65) IPython/kernel/core/interpreter.py (+3/-4) IPython/kernel/core/tests/test_redirectors.py (+6/-6) IPython/kernel/engineservice.py (+3/-3) IPython/kernel/error.py (+2/-2) IPython/kernel/ipclusterapp.py (+8/-19) IPython/kernel/ipcontrollerapp.py (+14/-34) IPython/kernel/ipengineapp.py (+8/-27) IPython/kernel/tests/test_multienginefc.py (+9/-1) IPython/kernel/tests/test_taskfc.py (+9/-1) IPython/lib/inputhook.py (+49/-3) IPython/quarantine/InterpreterPasteInput.py (+0/-124) IPython/scripts/iptest (+19/-3) IPython/testing/__init__.py (+18/-0) IPython/testing/_doctest26.py (+110/-0) IPython/testing/_paramtestpy2.py (+89/-0) IPython/testing/_paramtestpy3.py (+62/-0) IPython/testing/decorators.py (+84/-14) IPython/testing/decorators_trial.py (+0/-132) IPython/testing/globalipapp.py (+168/-0) IPython/testing/iptest.py (+349/-185) IPython/testing/ipunittest.py (+189/-0) IPython/testing/nosepatch.py (+53/-0) IPython/testing/parametric.py (+3/-0) IPython/testing/plugin/ipdoctest.py (+27/-180) IPython/testing/plugin/test_ipdoctest.py (+0/-19) IPython/testing/tests/test_decorators.py (+71/-13) IPython/testing/tests/test_decorators_trial.py (+9/-4) IPython/testing/tests/test_ipunittest.py (+122/-0) IPython/testing/tests/test_tools.py (+31/-9) IPython/testing/tools.py (+255/-7) IPython/utils/baseutils.py (+51/-0) IPython/utils/genutils.py (+129/-41) IPython/utils/platutils.py (+1/-1) IPython/utils/platutils_posix.py (+14/-1) IPython/utils/tests/test_genutils.py (+71/-51) IPython/utils/tests/test_imports.py (+0/-1) IPython/utils/tests/test_platutils.py (+19/-6) MANIFEST.in (+1/-0) README.txt (+22/-4) docs/emacs/ipython.el (+1/-1) docs/source/development/coding_guide.txt (+34/-0) docs/source/development/index.txt (+1/-0) docs/source/development/magic_blueprint.txt (+103/-0) docs/source/development/testing.txt (+366/-32) docs/sphinxext/ipython_directive.py (+641/-0) iptest.py (+26/-0) ipython.py (+6/-2) setup.py (+44/-3) setupegg.py (+1/-7) tools/build_release (+6/-6) |
To merge this branch: | bzr merge lp:~fdo.perez/ipython/trunk-dev |
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Granger | overview | Needs Fixing | |
Review via email: mp+16695@code.launchpad.net |
Commit message
Description of the change
Fernando Perez (fdo.perez) wrote : | # |
Fernando Perez (fdo.perez) wrote : | # |
Last revision fixes %magic tab completion, bringing us closer to 0.10 everyday functionality...
- 1230. By Fernando Perez
-
Small fix to info message when pylab starts.
- 1231. By Fernando Perez
-
Fix tab-completion for magics, other completion cleanup and fixes.
Mostly simplifying the code and updating it, no major functionality changes
other than fixing magic completion, which had broken in the 0.11 refactor.Also added a small test file for completion-specific tests.
- 1232. By Fernando Perez
-
Remove redundant decorators and unify into decorators.py
- 1233. By Fernando Perez
-
Added test support for better parametric tests and nose fixes.
These are the underlying support files needed by the rest.
- 1234. By Fernando Perez
-
Add new testing support machinery with better parametric tests.
Also included are new tools for doctests with ipython syntax.
- 1235. By Fernando Perez
-
Update numpy's decorators.py from upstream.
- 1236. By Fernando Perez
-
Fix quitting: now, typing bare 'exit' or 'quit' unconditionally quits.
We still ask for confirmation by default with C-d (EOF), since that can
happen accidentally quite easily (though users can always disble that safety
if desired). - 1237. By Fernando Perez
-
Fix auto-quoting via ',' as the first character, which had broken in refactor.
- 1238. By Fernando Perez
-
Fix debugging with breakpoints.
- 1239. By Fernando Perez
-
Fix bugs when readline is absent (pdb and quitting would crash badly)
- 1240. By Fernando Perez
-
Fix bug where output prompts were coming *after* output values.
This means that on exit/quit, we'll see something, so I added a simple 'bye'
to those. Not pretty, but easier than messing with the prompt logic. - 1241. By Fernando Perez
-
Better handling of no-readline.
- 1242. By Fernando Perez
-
Fix broken multiline input - ugly fix, needs cleanup later.
See comment in code, my fix is nasty and should be cleaned up later, but
right now I can't do it (no time to understand the component tree machinery
well enough for a clean fix). - 1243. By Fernando Perez
-
Minor fix to exit/quit
- 1244. By Fernando Perez
-
Update argparse to current SVN.
This fixes a few small bugs from upstream, but more importantly, syncs us so
we can add some local changes (see next commit) - 1245. By Fernando Perez
-
Small improvements to argparse.
I've submitted these fixes upstream, let's hope they get included:
http://
groups. google. com/group/ argparse- devs/browse_ thread/ thread/ 2c03e4b3d28a320 3 - 1246. By Fernando Perez
-
Cleaner access to log call.
At least now we're not walking the component tree manually... A bigger
refactor is still needed here, but this code is less brittle than multiple
.parent access. - 1247. By Fernando Perez
-
Simpler/cleaner version of %who_ls.
Functionally equivalent but with simpler and faster code (I was fixing up
pylab support and saw this old code, fixed it up to more modern standards). - 1248. By Fernando Perez
-
Testing '#:' attribute docstrings for sphinx.
This is supposed to work and give us class/instance docstrings, but it's not
yet. I have a question on the sphinx list about it, let's leave it in the
code until we figure out what we need to do to sphinx for it to work (it
doesn't hurt otherwise). - 1249. By Fernando Perez
-
Added --gui to match %gui use, better docs and behavior for %pylab code.
Now both %gui and %pylab have identical syntax if used at startup as --gui
and --pylab. This can be useful to people setting up aliases or other
shell-based support.Also cleaned up %pylab so it doesn't pollute the output of %who with all
loaded symbols. - 1250. By Fernando Perez
-
Equivalent but simpler/faster code in loader.py.
- 1251. By Fernando Perez
-
Deactivate stray debug print statement.
- 1252. By Fernando Perez
-
Manage and propagate argv correctly.
All Application objects should take argv in their constructor, akin to how
the standard signature of C programs is "main(int argc, char *argv)". This
makes it possible to initialize them from code with different command-line
options (otherwise, they end up directly accessing sys.argv[1:] via
argparse). - 1253. By Fernando Perez
-
Progress towards getting the test suite in shape again.
Work all over the place to get more tests to pass.
- 1254. By Fernando Perez
-
Close https:/
/bugs.launchpad .net/ipython/ +bug/503729 Removed stale tests that do not apply anymore.
- 1255. By Fernando Perez
-
Fix failing config test: https:/
/bugs.launchpad .net/ipython/ +bug/503731 Thanks to Brian for the fix!
Fernando Perez (fdo.perez) wrote : | # |
OK, this is in pretty good shape now: except for the twisted problem (which I suspect is tiny, I just don't know what to fix) we have again a usable test suite. Ready for review.
- 1256. By Fernando Perez
-
Make testing easier by exposing a top-level test() function.
- 1257. By Fernando Perez
-
Work in multiple places to improve state of the test suite.
With these changes, on my system now all the test sub-suites pass except
for the Twisted one (see https://bugs.launchpad .net/ipython/ +bug/504515 for
details on that one). - 1258. By Fernando Perez
-
Improve test suite robustness by cleaning up stale processes when possible.
- 1259. By Fernando Perez
-
A few small fixes so ipythonx works, and PEP-8 cleanups I found along the way.
- 1260. By Fernando Perez
-
Minimal fixes so ipython-wx runs.
I've only done the most basic checks that it starts and simple things work,
this probably needs much more work in the future. - 1261. By Fernando Perez
-
Cleaner error message in crash handler.
- 1262. By Fernando Perez
-
Move crash handling to the application level and simplify class structure.
Starting to try to take real advantage of the refactoring, to have generic
crash handling. This also lets us initialize the app without needing all
the self.attempt() wrappers, since now there's a good system-wide crash
handler at the app level (not inside the shell instance). I didn't yet
remove the attempt() method because we may have occasional uses for it (we
still do, but in one place only).I also removed some extra class layers that weren't quite needed. Creating
classes solely for the purpose of passing parameters makes the code (IMO)
harder to understand, I kept getting lost in parts of the class hierarchy.
I think these changes provide the same flexibility but with easier to follow
code (less things to remember, basically). What I tried to do was to use
argument passing instead of inheritance for all cases I saw where the
inheritance wasn't really adding new functionality. In some cases, this
actually allowed me to remove methods that were effectively duplicated in
the subclasses. - 1263. By Fernando Perez
-
Merging with upstream trunk.
- 1264. By Fernando Perez
-
Make IPython work if a recent numpy is not available.
I updated the numpy testing decorators module and didn't notice they
recently introduced dependencies that make it use the rest of numpy. We may
later want to revisit this, as my solution is ugly, but I simply hacked it
to load locally the code they added, which we now carry as
_numpy_testing_ utils. Ultimately the solution to this should be taken up with upstream numpy, so
that we all agree on a common set of testing decorators with no other
dependencies aside from the stdlib. But for now, this will let us move
forward as that discussion could take a while. - 1265. By Fernando Perez
-
Make setupegg.py work on Windows.
- 1266. By Fernando Perez
-
Fix deprecation warning from os.popen3.
Patch provided by Pim Schellart <p.schellart-
AT-gmail. com>, slightly
modified to fix missing supbrocess references. - 1267. By Fernando Perez
-
Fix broken %time magic.
- 1268. By Fernando Perez
-
Remove dead code accidentally left over in prior refactor.
- 1269. By Fernando Perez
-
Update version requirement to 2.5, since that's what we're using anyway.
- 1270. By Fernando Perez
-
Massive amount of work to improve the test suite, restores doctests.
After Brian's comments, I realized that our test machinery was NOT in
reality running all the ipython-syntax doctests we have. This is now fixed.
The test suite isn't completely passing, but this commit is for the
underlying machinery. I will now work on fixing as many broken tests as I
can. - 1271. By Fernando Perez
-
Fix extensions test suite (small, but now it runs and passes!)
- 1272. By Fernando Perez
-
Fix test I broke when moving a file.
- 1273. By Fernando Perez
-
Fix config part of the test suite.
- 1274. By Fernando Perez
-
Fix failing doctest in utils.
- 1275. By Fernando Perez
-
Make all non-twisted tests pass.
Removed a test (builtins) that was already being done in test_run, fixed
broken doctest and fixed prefilter handling for empty buffers.The only remaining failing test is now in twisted.
- 1276. By Fernando Perez
-
Disable completely two sets of Twisted tests so the suite runs.
The problem is that these tests are not just failing, they hang (even
ignoring Ctrl-C), so they prevent the suite from running at all. But I
don't know how to fix them, so I disabled them; this way others can at least
run the test suite, and hopefully Brian can pitch in with a fix. - 1277. By Fernando Perez
-
Fix %history magics.
- 1278. By Fernando Perez
-
Improve setuptools support.
Many thanks to Gael for the code/idea for the solution, see bug page for
details. - 1279. By Fernando Perez
-
Add file I forgot! Thanks to J. Hunter for report.
- 1280. By Fernando Perez
-
Patch by Beni Cherniavsky to improve tab-completion in emacs with 2.6.
- 1281. By Fernando Perez
-
Add transformers to understand code pasted with >>> or IPython prompts.
Now the following all work out of the box:
In [8]: In [6]: for i in range(5):
...: ...: print i,
...: ...:
...:
0 1 2 3 4In [10]: >>> width = 20
In [11]: >>> height = 5*9
In [12]: >>> width * height
Out[12]: 900And the history is still clean:
In [13]: %hist -n
[snipped]
for i in range(5):
print i,get_ipython(
).magic( "hist -n")
width = 20
height = 5*9
width * heightThis will be extremely useful when copy/pasting from interactive tutorials,
doctests and examples.Also fixes %doctest_mode: https:/
/bugs.launchpad .net/ipython/ +bug/505404 - 1282. By Fernando Perez
-
Unify command-line usage information in one place.
- 1283. By Fernando Perez
-
Simplify options handling code by using argparse argument_default.
The argparse.
ArgumentParser class supports an instance-wide default, so we
can set that once instead of having every argument configured with the same
default always. - 1284. By Fernando Perez
-
Apply argparse code simplification to all kernel scripts.
- 1285. By Fernando Perez
-
Update public revnum to make test installers for wider use.
At this point, all scripts, tests and doc build work on linux.
- 1286. By Fernando Perez
-
Update release tool to always produce zip file.
- 1287. By Fernando Perez
-
Fixes for python2.5 compatibility.
- 1288. By Fernando Perez
-
Minor fixes to build scripts.
build_rpm failing, don't know why; we may just stop providing rpms as those
are normally the distributor's problem. - 1289. By Fernando Perez
-
Fix bug with autocall and multiline input recalled from readline buffer.
Reported by John Hunter on list.
- 1290. By Fernando Perez
-
Added new Tee class, that works much like Unix's 'tee' command.
I needed it to debug the IPython sphinx directive (next commit).
Also fixed some typos along the way.
- 1291. By Fernando Perez
-
Added ability to invoke pdb on IPython crashes.
For now it has to be turned on manually in the code, will add a flag later.
But very useful for debugging apps that use/extend IPython itself and can
possibly crash it. - 1292. By Fernando Perez
-
Fix minor error that I saw in some odd cases, not sure how to test for it.
Unfortunately I don't have a reliable test case for this, it's deep in
traceback handling. But I did see a few times ultratb itself crash. - 1293. By Fernando Perez
-
Ported the IPython Sphinx directive to 0.11.
This was originally written by John Hunter for the 0.10 API, now it works
with 0.11. We still need to automate its test suite, but at least now it
runs and the script itself can be executed as a test that produces screen
output and figures in a subdir. - 1294. By Fernando Perez
-
Lots of work on exception handling, including tests for traceback printing.
We finally have some tests for various exception mode printing, via doctests
that exercise all three modes!Also changed handling of sys.exit(X) to only print the summary message, as
SystemExit is most often a 'handled' exception. It can still be 100%
silenced via '%run -e', but now it's much less intrusive.Added a new %tb magic to print the last available traceback with the current
xmode. One can then re-print the last traceback with more detail if
desired, without having to cause it again. - 1295. By Fernando Perez
-
Changed %hist to default to NOT printing numbers, added -p and -o options.
-p: print python prompts before inputs
-o: print output as wellTogether, these two make '%hist -op' an easy way to get doctest-valid
sessions generated from prior input. - 1296. By Fernando Perez
-
Remove accidentally introduced runtime nose dependencies.
- 1297. By Fernando Perez
-
Fix bug with aliases, exposed by windows test suite.
- 1298. By Fernando Perez
-
Clean up and document better starting process of global IPython in tests.
- 1299. By Fernando Perez
-
Fix subtle bug in doctests (ipython namespace was being destroyed).
Exposed by windows test suite.
- 1300. By Fernando Perez
-
Various fixes for IPython.core tests to pass under win32.
- 1301. By Fernando Perez
-
Various fixes for test_genutils under win32, now all tests pass.
- 1302. By Fernando Perez
-
Remove executable bit, this is a module.
- 1303. By Fernando Perez
-
More fixes for win32 test suite.
- 1304. By Fernando Perez
-
Fix argument parsing bug in win32, clean up temp files in %hist doctest.
- 1305. By Fernando Perez
-
More win32 test fixes and a new test.
Mostly handling escaping of filenames across platforms.
- 1306. By Fernando Perez
-
Add new @onlyif decorator, the reverse of @skipif.
It's trivial, but it makes certain conditions much cleaner to express.
- 1307. By Fernando Perez
-
More win32 fixes and refinements to test suite.
- 1308. By Fernando Perez
-
Fix test suite when Twisted not available, cleanups to iptest for clarity.
- 1309. By Fernando Perez
-
Fix test failure when pexpect not available
- 1310. By Fernando Perez
-
Fix another win32 test failure.
As of this commit, the entire test suite passes on a system that only has:
- Python 2.6.4 from Python.org
- Pyreadline 1.5
- IPython (this branch)
- nose 0.11.1Tests that require Twisted, graphics or other machinery get skipped, but
everything else runs and passes.The glaring remaining problem on win32 is that right now, colored output is
broken for some reason (though prompts are OK). I'll try to fix that next. - 1311. By Fernando Perez
-
Remove leftover print statement.
- 1312. By Fernando Perez
-
Add writeln convenience method to Term streams.
- 1313. By Fernando Perez
-
Fix exception color problems in win32.
In all the recent work to have the test suite play nice with doctest of full
ipython sessions, I inadvertedly started sending exceptions directly to
sys.stderr. On windows we MUST go via Term.cerr, which uses pyreadline to
handle color escapes, while sys.stderr just shows garbage on screen.As of this revision, the test suite passes fully on win32 and linux, and
interactive use also seems OK on all fronts.We're getting closer to RC status...
- 1314. By Fernando Perez
-
Move cleanup to main setup.py, where it belongs.
Distutils now generates .egg-info stuff even without setuptools, so we
should do the cleanup in the main script. - 1315. By Fernando Perez
-
Fixes for test suite in win32 when all dependencies (esp. Twisted) are
installed.Also activated testing.tools to be picked up by the test suite (was
excluded), this gives us a few more tests.Status:
- On Linux, the full suite passes like before.
- On Win32, now that we have Twisted, we're seeing a few failures, because I
don't have the WinHPC server stuff. These should be easy for Brian to fix.
There are also two tests where the Skip nose exception isn't recognized by
Twisted, should also be easy. I'll file tickets for those. - 1316. By Fernando Perez
-
Fix the two Twisted trial errors under win32.
I had incorrectly used a nose decorator instead of the twisted approach.
- 1317. By Fernando Perez
-
Changed trial skip to be a simple flag, now that I know this works.
I thought it needed to be a method, apparently not, use the simplest thing
that works. - 1318. By Fernando Perez
-
Include 'kernel' in the nose tests as well; it picks up doctests that trial
doesn't. - 1319. By Fernando Perez
-
Fix bug where python -c "import IPython; IPython.test()" could fail.
Depending on where one was located when typing it, it could fail. Made all
necessary paths absolute so this doesn't happen. - 1320. By Fernando Perez
-
Added notes with ideas about new design for %magics.
- 1321. By Fernando Perez
-
Wrote up description with examples of our testing system.
- 1322. By Fernando Perez
-
Update revnum; ready for testing, will upload and send to the dev list.
Docs have been added, this is close to a reasonable RC for 0.11.
As of this revision, we're down to 0 errors on linux and 1 on windows (that
appears twice). The windows error is tracked here: - 1323. By Fernando Perez
-
Clean up output of %who
- 1324. By Fernando Perez
-
Make an error message a bit easier to understand.
- 1325. By Fernando Perez
-
Fix %history to stop printing last line.
This was triggering a recursive calling of %hist in doctests, resulting in
spurious output from the test suite.Closes https:/
/bugs.launchpad .net/ipython/ +bug/507705 Also minor pep-8 formatting cleanups.
- 1326. By Fernando Perez
-
Fix test I'd broken with change of reporting in %who.
- 1327. By Fernando Perez
-
Fix warning on startup if user didn't have personal copies of cluster config.
We use the builtin defaults in this case, we were just missing searching in
our own paths.Also suppress deprecation warnings from Twisted.
- 1328. By Fernando Perez
-
Minimize stdout side effects in testing instances.
- 1329. By Fernando Perez
-
Fix frontend tests so they obtain the right global test IPython object.
- 1330. By Fernando Perez
-
Fix names so these doctests pass correctly when run in bare 'iptest IPython'
- 1331. By Fernando Perez
-
Let iptest pass arguments correctly to nose (in-process or in subprocess).
Fixes https:/
/bugs.launchpad .net/ipython/ +bug/507079 Also, remove relative imports from the iptest.py module so it can be run as
a script as well under 2.5 or 2.6. - 1332. By Fernando Perez
-
Make it possible to run the tests from the source dir without installation.
Also clean up the handling of command-line options for iptest, so that all
options given at the top-level are correctly passed to nose. - 1333. By Fernando Perez
-
Moved twisted import into a function, so base exception classes in kernel
can be imported without twisted present. - 1334. By Fernando Perez
-
Fixes to make test suite more robust on Fedora.
I fond some spurious warnings on Fedora, extra noise on stdout and other
small problems this commit fixes.The test suite now runs cleanly on Fedora11 without Twisted available.
- 1335. By Fernando Perez
-
Do not call %run with quotes, since on Windows quotes aren't stripped.
On Posix, shlex strips quotes from filenames, but not on Windows. So if we
call %run "somefilename" on Win32, we get a 'file not found' error. This
problem was appearing for the test suite on win32. - 1336. By Fernando Perez
-
Ensure that __builtin__ is always available and compute prompts from it.
__builtins__ (note the s) can change from module to dict somewhat at random,
see this for details:http://
mail.python. org/pipermail/ python- dev/2001- April/014068. html If this happened, our prompt computations could go out of whack in bizarre
ways, I saw it happen for continuation prompts after loading pylab, for
example. This change fixes it. - 1337. By Fernando Perez
-
Comment out accidentally left over 'raise'.
This function promises NEVER to raise an exception, I was propagating it out
while debugging some odd behavior with __builtins__ and left it accidentally
in place. - 1338. By Fernando Perez
-
Fix tests to return consistent results regardless of how they are called.
Now, calling:
- 'python iptest.py' from source dir or from src/IPython/testing should give
the same results- 'python iptest.py IPython.SOMETHING' from either place should also give
the same results. - 1339. By Fernando Perez
-
Make the test suite runnable without X11 connections.
This fix makes the test suite work in settings like a screen session that
can import but not initialize GTK. - 1340. By Fernando Perez
-
Added %exit, %quit and %Quit as magics for consistency.
- 1341. By Fernando Perez
-
Doc updates to testing to reflect recent changes.
Updated revnumber to push an updated testing release out for this branch.
- 1342. By Fernando Perez
-
Include iptest.py in MANIFEST so it gets shipped.
- 1343. By Fernando Perez
-
Give good error message when starting tests if nose is missing.
- 1344. By Fernando Perez
-
Inform user at install time of minimal python requirements if not met.
- 1345. By Fernando Perez
-
Robustness fixes in test suite machinery.
Added a module-level INSTALLED flag, which can be set to false if the test
suite is being run in-place (without ipython having been installed at all).
This is because how we call and import things must be done differently
depending on whether the code is installed or is being run in-place. The
only ones that can know this reliably are the entry-point scripts, so those
are responsible for setting this flag.Also made the code that validates ipython in subprocesses report errors
better, by checking stderr for errors before validating stdout output, as
anything on stderr will be likely informative of the real problem. - 1346. By Fernando Perez
-
Moved system info into its own utility, so we can use in in test suite too.
- 1347. By Fernando Perez
-
Added diagnostics printout at the end of the test suite.
This will make it easier for us to understand problem reports from users.
Brian Granger (ellisonbg) wrote : | # |
Here are my comments for the first 50 commits.
1223
====
application.py: Why are profile_name, ipython_dir set to None in class
definition?
1224
====
magic.py
(80,10): Really wierd problem with making Magic a new style class!
(1571,7): Why self.shell instead of self?
I think you move some of this to another file later on.
1225
====
Maybe this explains why profile_name and ipython_dir are set to None
in r1223. I think this makes sense.
1226, 1227, 1228
================
1229
====
ipapp.py
I like how the pylab enabling has been implemented in ipapp and iplib.
(540,12): The call to InteractiveTB.
be moved into a method of iplib.Interacti
InteractiveShel
that instantiates the InteractiveTB instance. The self.shell.xmode attribute
should already be set by the config system.
pylabtools.py:
This should probably be moved to IPython/lib like inputhook.py. The idea of
the lib subpackage is to help us keep core as small as possible. Eventually
core should not depend on the terminal or on anything outside of the stdlib.
The way I think of it is that maybe someday, core would make it into the std
lib itself. So lib is for non-optional things (optional things go into extensions)
that add additional functionality to IPython beyond the core.
1230
====
1231
====
completer.py
In protect_filename maybe a note on why it is needed to protect () on win32.
1232
====
Where did the decorators_trial.py go? I thought we were still using these
to give a single interface for skipping tests in nose/trial. Maybe a later
commit will explain this...
1233
====
Why is _paramtestpy2.py and _paramtestpy3.py named with a leading underscore?
I am guessing that they are imported in a way that is python version
dependent?
Include the standard headers (copyright, etc.) in these files.
1234
====
Yeh, 1, 2, 3, 4!
In test_decorators.py it looks like there is a reference to the twisted
testing decorators that vanished. How are we handling that now?
1235, 1236
==========
1237
====
In prefilter near line 158, why ip.shell._ofind, rather than ip._ofind?
1238, 1239
==========
1240
====
quitter.py, line 36, do we want to print "Bye" on exit. Seems a bit verbose.
1241
====
Great.
1242
====
I think the self.parent.parent can be replaced by self.shell.
1243
====
Can we return an empty string instead of 'Bye'?
1244, 1245
==========
1246
====
OK, this fixes issue with r1242.
1247
====
Great.
1248
====
Should we start using this on all attributes?
1249
====
Can we renamed user_config_ns to something that reflects how it is used by
%who? Like user_ns_exclude? Eventually, when magics are components, the who
magic itself should track this namespace and provide a simple API for adding
things to it.
1250
====
Is this the code that enables you to get rid of the default=
all over the place? If so that is great. It is important that most command
line options use NoConfigDefault as the default value.
1251
====
1252
====
Very nice!!!
1253
====
application.py:
Anytime things change in application.py, we need t...
Brian Granger (ellisonbg) wrote : | # |
Here are my next 50 commit reviews:
1274, 1275
==========
1276
====
Brian needs to look at this. Create a ticket for this.
1277, 1278
==========
1279
====
I really don't like that we have to do this stuff to run out test suite.
Putting get_ipython in __builtin__ is a bad idea as it suggest that
get_ipython is a global function which is can't be (it always needs to be
attached to a particular InteractiveShell). I worry that with our test suite
having this global, people will start to write their code expecting this (see
above comments on how the pretty extension calls the global get_ipython).
Also, this code is where we are creating an IPythonApp, but we should
probably be creating a raw InteractiveShell.
....the code smell of this is still bad...
1280
====
1281
====
Oooohh, I love this!
1282
====
1283
====
I see you are deleting all the NoConfigDefault keywords arguments. It is
important that the default is set to this. The config system won't work
otherwise. How is this being handled? If it is not handled properly,
the command line options won't be able to override those of the command line.
Also, the parallel computing apps also rely on this particular handling of
NoConfigDefault. Those need to be updated if there is a new way of this
working.
1284
====
The defaults are not set to NoConfigDefaults, so it is not clear the config
system is working properly.
In ipclusterapp.py it looks like this is handled by the argument_default
argument to ArgumentParser.
In ipclusterapp.py 364,365, these should capture the deferreds (d, d2) even
though we are not using them. This is to emphasize that these functions
return deferreds. This code is super subtle to debug and it helps to
show which functions return deferreds. Either that or make a comment about
these functions returning a deferred.
Same issues about NoConfigDefault in ipcontrollerapp
1285, 1286, 1287, 1288, 1289
=======
1290
====
Let put new utilities (like teee) in their own modules rather than genutils.
This will at least prevent the genutils situation from getting worse. Also,
new things tend to get lost in genutils.
1291, 1292
==========
1293
====
application.py:
The logic in Application is already extremely complex. I think that adding the
new constructor_config and override_config logic takes the complexity over the
top.
The main goals of an Application are to manage the complex logic of building
a config from the command line and config files. The new constructor_config
and override_config logic seems like it is simply trying to get around
what Application is doing. This basically makes Application *more* complex
in order to get it doing less.
I think this is a perfect case where we should simply directly instantiate
an InteractiveShell class directly. All options can be passed by creating
a single config object and setting its attributes as needed.
This approach will limit the complexity in Application and provide a simpler
way of simply instantiating the object you want.
I think it may be just the old habit of thinking of Application as the
refactored make_ipython function. In reality, the parts of the old
mak...
Brian Granger (ellisonbg) wrote : | # |
Final 50 commits...
1319-1320
=========
1321
====
On line 214, "betwee"
1322-1325
=========
1327
====
I don't think that the config/default dir should be added to the default
search path for the cluster config files. The reason is that all of the
cluster apps *require* a cluster directory that can be written to
(the log and security subdirs have to be created.). All of the cluster
apps should automatically handle the copying of the default config files
to the users cluster directory. If this is not happening, it is a bug.
Thus, I think this change should be reverted and tested to make sure it is
behaving properly.
The changes to silence warnings related to Twisted and sets are fine though.
1328
====
tools.py:
I think that these command line options should be made into a config object
when the testing machinery stops creating an IPythonApp and creates an
InteractiveShell instead.
But what is ipexec used for? It might need the command line options.
1329
====
Again, the global get_ipython is scary. Maybe we should just rename it to
something like get_testing_ipython to emphasize the difference between it and
the get_ipython that appears in the user's namespace?
1330-1331
=========
1332
====
This commit allows iptest to be run from the source dir. I am 50/50 on keeping
this feature. The reason is that part of what we want users to test is if
IPython *can* actually be installed.
The top-level ipython.py is great though.
1333
====
Moving the twisted import in error.py inside a function is fine, but why was
this needed? I thought the idea is that things in kernel can depend on
twisted.
1334
====
iptest.py:
I see you removed kernel from the list of packages that nose will test. But
you also removed kernel from the trial_packages. Is it being tested?
OK, later in the diff I see you add kernel to both nose_pkg_names and
trial_pkg_names. I am pretty sure that it *MUST* be removed from the
nose_pkg_names lis (see above comments about testing twisted using code with
nose).
baseutils.py:
baseutils sounds like another genutils disaster waiting to happen. While
the docstring makes it perfectly clear why it is called baseutils, we need
to get into the habit of organizing functions and classes in utils into
logic modules. For example all functions and classes from genutils that handle
external command execution, should be in a single module.
There can be dependencies between such modules in IPython/utils, but *nothing*
in utils should import anything from the rest of IPython (outside of utils).
Summary, let's get rid of baseutils and start to break genutils up into logical
modules that focus on one thing.
1335
====
I am suspicious of this fix. As I recall, the problem was much deeper than
this. Let's make sure we look through the tickets. I think R. Kern helped
us figure out what was going on.
1336-1344
=========
1345
====
iptest.py: This type of thing (INSTALLED) makes me want to get rid of the
ability to run the top-level iptest without installing IPython. It just
makes the test suite more fragile and harder to debug.
tools.py/iptest.py: Same thought about INSTALLED and the top-level iptest.py.
1346
====
I like ha...
Brian Granger (ellisonbg) wrote : | # |
I have submitted my comments in three batches. Overall, this is a fantastic bit of coding!
It might be useful to talk about my comments so I can summarize the main points. After you
make changes I will begin to install, run the test suite and test the parallel computing stuff.
Cheers,
Brian
Preview Diff
1 | === modified file 'IPython/__init__.py' (properties changed: -x to +x) | |||
2 | --- IPython/__init__.py 2009-08-26 20:54:07 +0000 | |||
3 | +++ IPython/__init__.py 2010-01-18 01:17:11 +0000 | |||
4 | @@ -16,18 +16,17 @@ | |||
5 | 16 | #----------------------------------------------------------------------------- | 16 | #----------------------------------------------------------------------------- |
6 | 17 | # Imports | 17 | # Imports |
7 | 18 | #----------------------------------------------------------------------------- | 18 | #----------------------------------------------------------------------------- |
8 | 19 | from __future__ import absolute_import | ||
9 | 19 | 20 | ||
10 | 20 | import os | 21 | import os |
11 | 21 | import sys | 22 | import sys |
12 | 22 | from IPython.core import release | ||
13 | 23 | 23 | ||
14 | 24 | #----------------------------------------------------------------------------- | 24 | #----------------------------------------------------------------------------- |
15 | 25 | # Setup everything | 25 | # Setup everything |
16 | 26 | #----------------------------------------------------------------------------- | 26 | #----------------------------------------------------------------------------- |
17 | 27 | 27 | ||
21 | 28 | 28 | if sys.version[0:3] < '2.5': | |
22 | 29 | if sys.version[0:3] < '2.4': | 29 | raise ImportError('Python Version 2.5 or above is required for IPython.') |
20 | 30 | raise ImportError('Python Version 2.4 or above is required for IPython.') | ||
23 | 31 | 30 | ||
24 | 32 | 31 | ||
25 | 33 | # Make it easy to import extensions - they are always directly on pythonpath. | 32 | # Make it easy to import extensions - they are always directly on pythonpath. |
26 | @@ -39,11 +38,16 @@ | |||
27 | 39 | #----------------------------------------------------------------------------- | 38 | #----------------------------------------------------------------------------- |
28 | 40 | 39 | ||
29 | 41 | # In some cases, these are causing circular imports. | 40 | # In some cases, these are causing circular imports. |
33 | 42 | from IPython.core.iplib import InteractiveShell | 41 | from .config.loader import Config |
34 | 43 | from IPython.core.embed import embed | 42 | from .core import release |
35 | 44 | from IPython.core.error import TryNext | 43 | from .core.application import Application |
36 | 44 | from .core.ipapp import IPythonApp | ||
37 | 45 | from .core.embed import embed | ||
38 | 46 | from .core.error import TryNext | ||
39 | 47 | from .core.iplib import InteractiveShell | ||
40 | 48 | from .testing import test | ||
41 | 45 | 49 | ||
43 | 46 | from IPython.lib import ( | 50 | from .lib import ( |
44 | 47 | enable_wx, disable_wx, | 51 | enable_wx, disable_wx, |
45 | 48 | enable_gtk, disable_gtk, | 52 | enable_gtk, disable_gtk, |
46 | 49 | enable_qt4, disable_qt4, | 53 | enable_qt4, disable_qt4, |
47 | @@ -61,4 +65,3 @@ | |||
48 | 61 | __license__ = release.license | 65 | __license__ = release.license |
49 | 62 | __version__ = release.version | 66 | __version__ = release.version |
50 | 63 | __revision__ = release.revision | 67 | __revision__ = release.revision |
51 | 64 | |||
52 | 65 | 68 | ||
53 | === modified file 'IPython/config/loader.py' | |||
54 | --- IPython/config/loader.py 2010-01-08 22:28:30 +0000 | |||
55 | +++ IPython/config/loader.py 2010-01-18 01:17:11 +0000 | |||
56 | @@ -1,10 +1,10 @@ | |||
59 | 1 | #!/usr/bin/env python | 1 | # coding: utf-8 |
58 | 2 | # encoding: utf-8 | ||
60 | 3 | """A simple configuration system. | 2 | """A simple configuration system. |
61 | 4 | 3 | ||
64 | 5 | Authors: | 4 | Authors |
65 | 6 | 5 | ------- | |
66 | 7 | * Brian Granger | 6 | * Brian Granger |
67 | 7 | * Fernando Perez | ||
68 | 8 | """ | 8 | """ |
69 | 9 | 9 | ||
70 | 10 | #----------------------------------------------------------------------------- | 10 | #----------------------------------------------------------------------------- |
71 | @@ -37,7 +37,25 @@ | |||
72 | 37 | class ConfigLoaderError(ConfigError): | 37 | class ConfigLoaderError(ConfigError): |
73 | 38 | pass | 38 | pass |
74 | 39 | 39 | ||
75 | 40 | #----------------------------------------------------------------------------- | ||
76 | 41 | # Argparse fix | ||
77 | 42 | #----------------------------------------------------------------------------- | ||
78 | 43 | # Unfortunately argparse by default prints help messages to stderr instead of | ||
79 | 44 | # stdout. This makes it annoying to capture long help screens at the command | ||
80 | 45 | # line, since one must know how to pipe stderr, which many users don't know how | ||
81 | 46 | # to do. So we override the print_help method with one that defaults to | ||
82 | 47 | # stdout and use our class instead. | ||
83 | 40 | 48 | ||
84 | 49 | class ArgumentParser(argparse.ArgumentParser): | ||
85 | 50 | """Simple argparse subclass that prints help to stdout by default.""" | ||
86 | 51 | |||
87 | 52 | def print_help(self, file=None): | ||
88 | 53 | if file is None: | ||
89 | 54 | file = sys.stdout | ||
90 | 55 | return super(ArgumentParser, self).print_help(file) | ||
91 | 56 | |||
92 | 57 | print_help.__doc__ = argparse.ArgumentParser.print_help.__doc__ | ||
93 | 58 | |||
94 | 41 | #----------------------------------------------------------------------------- | 59 | #----------------------------------------------------------------------------- |
95 | 42 | # Config class for holding config information | 60 | # Config class for holding config information |
96 | 43 | #----------------------------------------------------------------------------- | 61 | #----------------------------------------------------------------------------- |
97 | @@ -279,22 +297,50 @@ | |||
98 | 279 | 297 | ||
99 | 280 | 298 | ||
100 | 281 | class ArgParseConfigLoader(CommandLineConfigLoader): | 299 | class ArgParseConfigLoader(CommandLineConfigLoader): |
101 | 300 | #: Global default for arguments (see argparse docs for details) | ||
102 | 301 | argument_default = NoConfigDefault | ||
103 | 282 | 302 | ||
108 | 283 | # arguments = [(('-f','--file'),dict(type=str,dest='file'))] | 303 | def __init__(self, argv=None, arguments=(), *args, **kw): |
105 | 284 | arguments = () | ||
106 | 285 | |||
107 | 286 | def __init__(self, *args, **kw): | ||
109 | 287 | """Create a config loader for use with argparse. | 304 | """Create a config loader for use with argparse. |
110 | 288 | 305 | ||
113 | 289 | The args and kwargs arguments here are passed onto the constructor | 306 | With the exception of ``argv`` and ``arguments``, other args and kwargs |
114 | 290 | of :class:`argparse.ArgumentParser`. | 307 | arguments here are passed onto the constructor of |
115 | 308 | :class:`argparse.ArgumentParser`. | ||
116 | 309 | |||
117 | 310 | Parameters | ||
118 | 311 | ---------- | ||
119 | 312 | |||
120 | 313 | argv : optional, list | ||
121 | 314 | If given, used to read command-line arguments from, otherwise | ||
122 | 315 | sys.argv[1:] is used. | ||
123 | 316 | |||
124 | 317 | arguments : optional, tuple | ||
125 | 318 | Description of valid command-line arguments, to be called in sequence | ||
126 | 319 | with parser.add_argument() to configure the parser. | ||
127 | 291 | """ | 320 | """ |
128 | 292 | super(CommandLineConfigLoader, self).__init__() | 321 | super(CommandLineConfigLoader, self).__init__() |
129 | 322 | if argv == None: | ||
130 | 323 | argv = sys.argv[1:] | ||
131 | 324 | self.argv = argv | ||
132 | 325 | self.arguments = arguments | ||
133 | 293 | self.args = args | 326 | self.args = args |
135 | 294 | self.kw = kw | 327 | kwargs = dict(argument_default=self.argument_default) |
136 | 328 | kwargs.update(kw) | ||
137 | 329 | self.kw = kwargs | ||
138 | 295 | 330 | ||
139 | 296 | def load_config(self, args=None): | 331 | def load_config(self, args=None): |
141 | 297 | """Parse command line arguments and return as a Struct.""" | 332 | """Parse command line arguments and return as a Struct. |
142 | 333 | |||
143 | 334 | Parameters | ||
144 | 335 | ---------- | ||
145 | 336 | |||
146 | 337 | args : optional, list | ||
147 | 338 | If given, a list with the structure of sys.argv[1:] to parse arguments | ||
148 | 339 | from. If not given, the instance's self.argv attribute (given at | ||
149 | 340 | construction time) is used.""" | ||
150 | 341 | |||
151 | 342 | if args is None: | ||
152 | 343 | args = self.argv | ||
153 | 298 | self._create_parser() | 344 | self._create_parser() |
154 | 299 | self._parse_args(args) | 345 | self._parse_args(args) |
155 | 300 | self._convert_to_config() | 346 | self._convert_to_config() |
156 | @@ -307,25 +353,21 @@ | |||
157 | 307 | return [] | 353 | return [] |
158 | 308 | 354 | ||
159 | 309 | def _create_parser(self): | 355 | def _create_parser(self): |
161 | 310 | self.parser = argparse.ArgumentParser(*self.args, **self.kw) | 356 | self.parser = ArgumentParser(*self.args, **self.kw) |
162 | 311 | self._add_arguments() | 357 | self._add_arguments() |
163 | 312 | self._add_other_arguments() | 358 | self._add_other_arguments() |
164 | 313 | 359 | ||
165 | 314 | def _add_other_arguments(self): | ||
166 | 315 | pass | ||
167 | 316 | |||
168 | 317 | def _add_arguments(self): | 360 | def _add_arguments(self): |
169 | 318 | for argument in self.arguments: | 361 | for argument in self.arguments: |
170 | 319 | if not argument[1].has_key('default'): | ||
171 | 320 | argument[1]['default'] = NoConfigDefault | ||
172 | 321 | self.parser.add_argument(*argument[0],**argument[1]) | 362 | self.parser.add_argument(*argument[0],**argument[1]) |
173 | 322 | 363 | ||
180 | 323 | def _parse_args(self, args=None): | 364 | def _add_other_arguments(self): |
181 | 324 | """self.parser->self.parsed_data""" | 365 | """Meant for subclasses to add their own arguments.""" |
182 | 325 | if args is None: | 366 | pass |
183 | 326 | self.parsed_data, self.extra_args = self.parser.parse_known_args() | 367 | |
184 | 327 | else: | 368 | def _parse_args(self, args): |
185 | 328 | self.parsed_data, self.extra_args = self.parser.parse_known_args(args) | 369 | """self.parser->self.parsed_data""" |
186 | 370 | self.parsed_data, self.extra_args = self.parser.parse_known_args(args) | ||
187 | 329 | 371 | ||
188 | 330 | def _convert_to_config(self): | 372 | def _convert_to_config(self): |
189 | 331 | """self.parsed_data->self.config""" | 373 | """self.parsed_data->self.config""" |
190 | @@ -333,4 +375,3 @@ | |||
191 | 333 | if v is not NoConfigDefault: | 375 | if v is not NoConfigDefault: |
192 | 334 | exec_str = 'self.config.' + k + '= v' | 376 | exec_str = 'self.config.' + k + '= v' |
193 | 335 | exec exec_str in locals(), globals() | 377 | exec exec_str in locals(), globals() |
194 | 336 | |||
195 | 337 | 378 | ||
196 | === modified file 'IPython/config/tests/test_loader.py' (properties changed: -x to +x) | |||
197 | --- IPython/config/tests/test_loader.py 2009-09-12 15:58:55 +0000 | |||
198 | +++ IPython/config/tests/test_loader.py 2010-01-18 01:17:11 +0000 | |||
199 | @@ -37,17 +37,18 @@ | |||
200 | 37 | 37 | ||
201 | 38 | 38 | ||
202 | 39 | pyfile = """ | 39 | pyfile = """ |
208 | 40 | a = 10 | 40 | c = get_config() |
209 | 41 | b = 20 | 41 | c.a = 10 |
210 | 42 | Foo.Bar.value = 10 | 42 | c.b = 20 |
211 | 43 | Foo.Bam.value = range(10) | 43 | c.Foo.Bar.value = 10 |
212 | 44 | D.C.value = 'hi there' | 44 | c.Foo.Bam.value = range(10) |
213 | 45 | c.D.C.value = 'hi there' | ||
214 | 45 | """ | 46 | """ |
215 | 46 | 47 | ||
216 | 47 | class TestPyFileCL(TestCase): | 48 | class TestPyFileCL(TestCase): |
217 | 48 | 49 | ||
218 | 49 | def test_basic(self): | 50 | def test_basic(self): |
220 | 50 | fd, fname = mkstemp() | 51 | fd, fname = mkstemp('.py') |
221 | 51 | f = os.fdopen(fd, 'w') | 52 | f = os.fdopen(fd, 'w') |
222 | 52 | f.write(pyfile) | 53 | f.write(pyfile) |
223 | 53 | f.close() | 54 | f.close() |
224 | @@ -65,15 +66,13 @@ | |||
225 | 65 | 66 | ||
226 | 66 | def test_basic(self): | 67 | def test_basic(self): |
227 | 67 | 68 | ||
230 | 68 | class MyLoader(ArgParseConfigLoader): | 69 | arguments = ( |
229 | 69 | arguments = ( | ||
231 | 70 | (('-f','--foo'), dict(dest='Global.foo', type=str)), | 70 | (('-f','--foo'), dict(dest='Global.foo', type=str)), |
232 | 71 | (('-b',), dict(dest='MyClass.bar', type=int)), | 71 | (('-b',), dict(dest='MyClass.bar', type=int)), |
233 | 72 | (('-n',), dict(dest='n', action='store_true')), | 72 | (('-n',), dict(dest='n', action='store_true')), |
234 | 73 | (('Global.bam',), dict(type=str)) | 73 | (('Global.bam',), dict(type=str)) |
235 | 74 | ) | 74 | ) |
238 | 75 | 75 | cl = ArgParseConfigLoader(arguments=arguments) | |
237 | 76 | cl = MyLoader() | ||
239 | 77 | config = cl.load_config('-f hi -b 10 -n wow'.split()) | 76 | config = cl.load_config('-f hi -b 10 -n wow'.split()) |
240 | 78 | self.assertEquals(config.Global.foo, 'hi') | 77 | self.assertEquals(config.Global.foo, 'hi') |
241 | 79 | self.assertEquals(config.MyClass.bar, 10) | 78 | self.assertEquals(config.MyClass.bar, 10) |
242 | 80 | 79 | ||
243 | === modified file 'IPython/core/application.py' | |||
244 | --- IPython/core/application.py 2009-11-12 00:41:52 +0000 | |||
245 | +++ IPython/core/application.py 2010-01-18 01:17:11 +0000 | |||
246 | @@ -1,4 +1,3 @@ | |||
247 | 1 | #!/usr/bin/env python | ||
248 | 2 | # encoding: utf-8 | 1 | # encoding: utf-8 |
249 | 3 | """ | 2 | """ |
250 | 4 | An application for IPython. | 3 | An application for IPython. |
251 | @@ -33,64 +32,125 @@ | |||
252 | 33 | import os | 32 | import os |
253 | 34 | import sys | 33 | import sys |
254 | 35 | 34 | ||
257 | 36 | from IPython.core import release | 35 | from IPython.core import release, crashhandler |
258 | 37 | from IPython.utils.genutils import get_ipython_dir | 36 | from IPython.utils.genutils import get_ipython_dir, get_ipython_package_dir |
259 | 38 | from IPython.config.loader import ( | 37 | from IPython.config.loader import ( |
260 | 39 | PyFileConfigLoader, | 38 | PyFileConfigLoader, |
261 | 40 | ArgParseConfigLoader, | 39 | ArgParseConfigLoader, |
262 | 41 | Config, | 40 | Config, |
263 | 42 | NoConfigDefault | ||
264 | 43 | ) | 41 | ) |
265 | 44 | 42 | ||
266 | 45 | #----------------------------------------------------------------------------- | 43 | #----------------------------------------------------------------------------- |
267 | 46 | # Classes and functions | 44 | # Classes and functions |
268 | 47 | #----------------------------------------------------------------------------- | 45 | #----------------------------------------------------------------------------- |
269 | 48 | 46 | ||
270 | 49 | |||
271 | 50 | class BaseAppArgParseConfigLoader(ArgParseConfigLoader): | ||
272 | 51 | """Default command line options for IPython based applications.""" | ||
273 | 52 | |||
274 | 53 | def _add_other_arguments(self): | ||
275 | 54 | self.parser.add_argument('--ipython-dir', | ||
276 | 55 | dest='Global.ipython_dir',type=unicode, | ||
277 | 56 | help='Set to override default location of Global.ipython_dir.', | ||
278 | 57 | default=NoConfigDefault, | ||
279 | 58 | metavar='Global.ipython_dir') | ||
280 | 59 | self.parser.add_argument('-p', '--profile', | ||
281 | 60 | dest='Global.profile',type=unicode, | ||
282 | 61 | help='The string name of the ipython profile to be used.', | ||
283 | 62 | default=NoConfigDefault, | ||
284 | 63 | metavar='Global.profile') | ||
285 | 64 | self.parser.add_argument('--log-level', | ||
286 | 65 | dest="Global.log_level",type=int, | ||
287 | 66 | help='Set the log level (0,10,20,30,40,50). Default is 30.', | ||
288 | 67 | default=NoConfigDefault, | ||
289 | 68 | metavar='Global.log_level') | ||
290 | 69 | self.parser.add_argument('--config-file', | ||
291 | 70 | dest='Global.config_file',type=unicode, | ||
292 | 71 | help='Set the config file name to override default.', | ||
293 | 72 | default=NoConfigDefault, | ||
294 | 73 | metavar='Global.config_file') | ||
295 | 74 | |||
296 | 75 | |||
297 | 76 | class ApplicationError(Exception): | 47 | class ApplicationError(Exception): |
298 | 77 | pass | 48 | pass |
299 | 78 | 49 | ||
300 | 79 | 50 | ||
301 | 51 | app_cl_args = ( | ||
302 | 52 | (('--ipython-dir', ), dict( | ||
303 | 53 | dest='Global.ipython_dir',type=unicode, | ||
304 | 54 | help= | ||
305 | 55 | """Set to override default location of the IPython directory | ||
306 | 56 | IPYTHON_DIR, stored as Global.ipython_dir. This can also be specified | ||
307 | 57 | through the environment variable IPYTHON_DIR.""", | ||
308 | 58 | metavar='Global.ipython_dir') ), | ||
309 | 59 | (('-p', '--profile',), dict( | ||
310 | 60 | dest='Global.profile',type=unicode, | ||
311 | 61 | help= | ||
312 | 62 | """The string name of the ipython profile to be used. Assume that your | ||
313 | 63 | config file is ipython_config-<name>.py (looks in current dir first, | ||
314 | 64 | then in IPYTHON_DIR). This is a quick way to keep and load multiple | ||
315 | 65 | config files for different tasks, especially if include your basic one | ||
316 | 66 | in your more specialized ones. You can keep a basic | ||
317 | 67 | IPYTHON_DIR/ipython_config.py file and then have other 'profiles' which | ||
318 | 68 | include this one and load extra things for particular tasks.""", | ||
319 | 69 | metavar='Global.profile') ), | ||
320 | 70 | (('--log-level',), dict( | ||
321 | 71 | dest="Global.log_level",type=int, | ||
322 | 72 | help='Set the log level (0,10,20,30,40,50). Default is 30.', | ||
323 | 73 | metavar='Global.log_level')), | ||
324 | 74 | (('--config-file',), dict( | ||
325 | 75 | dest='Global.config_file',type=unicode, | ||
326 | 76 | help= | ||
327 | 77 | """Set the config file name to override default. Normally IPython | ||
328 | 78 | loads ipython_config.py (from current directory) or | ||
329 | 79 | IPYTHON_DIR/ipython_config.py. If the loading of your config file | ||
330 | 80 | fails, IPython starts with a bare bones configuration (no modules | ||
331 | 81 | loaded at all).""", | ||
332 | 82 | metavar='Global.config_file')), | ||
333 | 83 | ) | ||
334 | 84 | |||
335 | 80 | class Application(object): | 85 | class Application(object): |
337 | 81 | """Load a config, construct components and set them running.""" | 86 | """Load a config, construct components and set them running. |
338 | 87 | |||
339 | 88 | The configuration of an application can be done via four different Config | ||
340 | 89 | objects, which are loaded and ultimately merged into a single one used from | ||
341 | 90 | that point on by the app. These are: | ||
342 | 91 | |||
343 | 92 | 1. default_config: internal defaults, implemented in code. | ||
344 | 93 | 2. file_config: read from the filesystem. | ||
345 | 94 | 3. command_line_config: read from the system's command line flags. | ||
346 | 95 | 4. constructor_config: passed parametrically to the constructor. | ||
347 | 96 | |||
348 | 97 | During initialization, 3 is actually read before 2, since at the | ||
349 | 98 | command-line one may override the location of the file to be read. But the | ||
350 | 99 | above is the order in which the merge is made. | ||
351 | 100 | |||
352 | 101 | There is a final config object can be created and passed to the | ||
353 | 102 | constructor: override_config. If it exists, this completely overrides the | ||
354 | 103 | configs 2-4 above (the default is still used to ensure that all needed | ||
355 | 104 | fields at least are created). This makes it easier to create | ||
356 | 105 | parametrically (e.g. in testing or sphinx plugins) objects with a known | ||
357 | 106 | configuration, that are unaffected by whatever arguments may be present in | ||
358 | 107 | sys.argv or files in the user's various directories. | ||
359 | 108 | """ | ||
360 | 82 | 109 | ||
361 | 83 | name = u'ipython' | 110 | name = u'ipython' |
362 | 84 | description = 'IPython: an enhanced interactive Python shell.' | 111 | description = 'IPython: an enhanced interactive Python shell.' |
363 | 112 | #: usage message printed by argparse. If None, auto-generate | ||
364 | 113 | usage = None | ||
365 | 85 | config_file_name = u'ipython_config.py' | 114 | config_file_name = u'ipython_config.py' |
366 | 115 | #: Track the default and actual separately because some messages are | ||
367 | 116 | #: only printed if we aren't using the default. | ||
368 | 117 | default_config_file_name = config_file_name | ||
369 | 86 | default_log_level = logging.WARN | 118 | default_log_level = logging.WARN |
373 | 87 | 119 | #: Set by --profile option | |
374 | 88 | def __init__(self): | 120 | profile_name = None |
375 | 89 | self._exiting = False | 121 | #: User's ipython directory, typically ~/.ipython/ |
376 | 122 | ipython_dir = None | ||
377 | 123 | #: internal defaults, implemented in code. | ||
378 | 124 | default_config = None | ||
379 | 125 | #: read from the filesystem | ||
380 | 126 | file_config = None | ||
381 | 127 | #: read from the system's command line flags | ||
382 | 128 | command_line_config = None | ||
383 | 129 | #: passed parametrically to the constructor. | ||
384 | 130 | constructor_config = None | ||
385 | 131 | #: final override, if given supercedes file/command/constructor configs | ||
386 | 132 | override_config = None | ||
387 | 133 | #: A reference to the argv to be used (typically ends up being sys.argv[1:]) | ||
388 | 134 | argv = None | ||
389 | 135 | #: Default command line arguments. Subclasses should create a new tuple | ||
390 | 136 | #: that *includes* these. | ||
391 | 137 | cl_arguments = app_cl_args | ||
392 | 138 | |||
393 | 139 | #: extra arguments computed by the command-line loader | ||
394 | 140 | extra_args = None | ||
395 | 141 | |||
396 | 142 | # Private attributes | ||
397 | 143 | _exiting = False | ||
398 | 144 | _initialized = False | ||
399 | 145 | |||
400 | 146 | # Class choices for things that will be instantiated at runtime. | ||
401 | 147 | _CrashHandler = crashhandler.CrashHandler | ||
402 | 148 | |||
403 | 149 | def __init__(self, argv=None, constructor_config=None, override_config=None): | ||
404 | 150 | self.argv = sys.argv[1:] if argv is None else argv | ||
405 | 151 | self.constructor_config = constructor_config | ||
406 | 152 | self.override_config = override_config | ||
407 | 90 | self.init_logger() | 153 | self.init_logger() |
408 | 91 | # Track the default and actual separately because some messages are | ||
409 | 92 | # only printed if we aren't using the default. | ||
410 | 93 | self.default_config_file_name = self.config_file_name | ||
411 | 94 | 154 | ||
412 | 95 | def init_logger(self): | 155 | def init_logger(self): |
413 | 96 | self.log = logging.getLogger(self.__class__.__name__) | 156 | self.log = logging.getLogger(self.__class__.__name__) |
414 | @@ -109,36 +169,80 @@ | |||
415 | 109 | 169 | ||
416 | 110 | log_level = property(_get_log_level, _set_log_level) | 170 | log_level = property(_get_log_level, _set_log_level) |
417 | 111 | 171 | ||
421 | 112 | def start(self): | 172 | def initialize(self): |
422 | 113 | """Start the application.""" | 173 | """Initialize the application. |
423 | 114 | self.attempt(self.create_default_config) | 174 | |
424 | 175 | Loads all configuration information and sets all application state, but | ||
425 | 176 | does not start any relevant processing (typically some kind of event | ||
426 | 177 | loop). | ||
427 | 178 | |||
428 | 179 | Once this method has been called, the application is flagged as | ||
429 | 180 | initialized and the method becomes a no-op.""" | ||
430 | 181 | |||
431 | 182 | if self._initialized: | ||
432 | 183 | return | ||
433 | 184 | |||
434 | 185 | # The first part is protected with an 'attempt' wrapper, that will log | ||
435 | 186 | # failures with the basic system traceback machinery. Once our crash | ||
436 | 187 | # handler is in place, we can let any subsequent exception propagate, | ||
437 | 188 | # as our handler will log it with much better detail than the default. | ||
438 | 189 | self.attempt(self.create_crash_handler) | ||
439 | 190 | |||
440 | 191 | # Configuration phase | ||
441 | 192 | # Default config (internally hardwired in application code) | ||
442 | 193 | self.create_default_config() | ||
443 | 115 | self.log_default_config() | 194 | self.log_default_config() |
444 | 116 | self.set_default_config_log_level() | 195 | self.set_default_config_log_level() |
460 | 117 | self.attempt(self.pre_load_command_line_config) | 196 | |
461 | 118 | self.attempt(self.load_command_line_config, action='abort') | 197 | if self.override_config is None: |
462 | 119 | self.set_command_line_config_log_level() | 198 | # Command-line config |
463 | 120 | self.attempt(self.post_load_command_line_config) | 199 | self.pre_load_command_line_config() |
464 | 121 | self.log_command_line_config() | 200 | self.load_command_line_config() |
465 | 122 | self.attempt(self.find_ipython_dir) | 201 | self.set_command_line_config_log_level() |
466 | 123 | self.attempt(self.find_resources) | 202 | self.post_load_command_line_config() |
467 | 124 | self.attempt(self.find_config_file_name) | 203 | self.log_command_line_config() |
468 | 125 | self.attempt(self.find_config_file_paths) | 204 | |
469 | 126 | self.attempt(self.pre_load_file_config) | 205 | # Find resources needed for filesystem access, using information from |
470 | 127 | self.attempt(self.load_file_config) | 206 | # the above two |
471 | 128 | self.set_file_config_log_level() | 207 | self.find_ipython_dir() |
472 | 129 | self.attempt(self.post_load_file_config) | 208 | self.find_resources() |
473 | 130 | self.log_file_config() | 209 | self.find_config_file_name() |
474 | 131 | self.attempt(self.merge_configs) | 210 | self.find_config_file_paths() |
475 | 211 | |||
476 | 212 | if self.override_config is None: | ||
477 | 213 | # File-based config | ||
478 | 214 | self.pre_load_file_config() | ||
479 | 215 | self.load_file_config() | ||
480 | 216 | self.set_file_config_log_level() | ||
481 | 217 | self.post_load_file_config() | ||
482 | 218 | self.log_file_config() | ||
483 | 219 | |||
484 | 220 | # Merge all config objects into a single one the app can then use | ||
485 | 221 | self.merge_configs() | ||
486 | 132 | self.log_master_config() | 222 | self.log_master_config() |
491 | 133 | self.attempt(self.pre_construct) | 223 | |
492 | 134 | self.attempt(self.construct) | 224 | # Construction phase |
493 | 135 | self.attempt(self.post_construct) | 225 | self.pre_construct() |
494 | 136 | self.attempt(self.start_app) | 226 | self.construct() |
495 | 227 | self.post_construct() | ||
496 | 228 | |||
497 | 229 | # Done, flag as such and | ||
498 | 230 | self._initialized = True | ||
499 | 231 | |||
500 | 232 | def start(self): | ||
501 | 233 | """Start the application.""" | ||
502 | 234 | self.initialize() | ||
503 | 235 | self.start_app() | ||
504 | 137 | 236 | ||
505 | 138 | #------------------------------------------------------------------------- | 237 | #------------------------------------------------------------------------- |
506 | 139 | # Various stages of Application creation | 238 | # Various stages of Application creation |
507 | 140 | #------------------------------------------------------------------------- | 239 | #------------------------------------------------------------------------- |
508 | 141 | 240 | ||
509 | 241 | def create_crash_handler(self): | ||
510 | 242 | """Create a crash handler, typically setting sys.excepthook to it.""" | ||
511 | 243 | self.crash_handler = self._CrashHandler(self, self.name) | ||
512 | 244 | sys.excepthook = self.crash_handler | ||
513 | 245 | |||
514 | 142 | def create_default_config(self): | 246 | def create_default_config(self): |
515 | 143 | """Create defaults that can't be set elsewhere. | 247 | """Create defaults that can't be set elsewhere. |
516 | 144 | 248 | ||
517 | @@ -148,9 +252,10 @@ | |||
518 | 148 | we set them here. The Global section is for variables like this that | 252 | we set them here. The Global section is for variables like this that |
519 | 149 | don't belong to a particular component. | 253 | don't belong to a particular component. |
520 | 150 | """ | 254 | """ |
524 | 151 | self.default_config = Config() | 255 | c = Config() |
525 | 152 | self.default_config.Global.ipython_dir = get_ipython_dir() | 256 | c.Global.ipython_dir = get_ipython_dir() |
526 | 153 | self.default_config.Global.log_level = self.log_level | 257 | c.Global.log_level = self.log_level |
527 | 258 | self.default_config = c | ||
528 | 154 | 259 | ||
529 | 155 | def log_default_config(self): | 260 | def log_default_config(self): |
530 | 156 | self.log.debug('Default config loaded:') | 261 | self.log.debug('Default config loaded:') |
531 | @@ -165,10 +270,11 @@ | |||
532 | 165 | 270 | ||
533 | 166 | def create_command_line_config(self): | 271 | def create_command_line_config(self): |
534 | 167 | """Create and return a command line config loader.""" | 272 | """Create and return a command line config loader.""" |
539 | 168 | return BaseAppArgParseConfigLoader( | 273 | return ArgParseConfigLoader(self.argv, self.cl_arguments, |
540 | 169 | description=self.description, | 274 | description=self.description, |
541 | 170 | version=release.version | 275 | version=release.version, |
542 | 171 | ) | 276 | usage=self.usage, |
543 | 277 | ) | ||
544 | 172 | 278 | ||
545 | 173 | def pre_load_command_line_config(self): | 279 | def pre_load_command_line_config(self): |
546 | 174 | """Do actions just before loading the command line config.""" | 280 | """Do actions just before loading the command line config.""" |
547 | @@ -197,10 +303,10 @@ | |||
548 | 197 | def find_ipython_dir(self): | 303 | def find_ipython_dir(self): |
549 | 198 | """Set the IPython directory. | 304 | """Set the IPython directory. |
550 | 199 | 305 | ||
553 | 200 | This sets ``self.ipython_dir``, but the actual value that is passed | 306 | This sets ``self.ipython_dir``, but the actual value that is passed to |
554 | 201 | to the application is kept in either ``self.default_config`` or | 307 | the application is kept in either ``self.default_config`` or |
555 | 202 | ``self.command_line_config``. This also adds ``self.ipython_dir`` to | 308 | ``self.command_line_config``. This also adds ``self.ipython_dir`` to |
557 | 203 | ``sys.path`` so config files there can be references by other config | 309 | ``sys.path`` so config files there can be referenced by other config |
558 | 204 | files. | 310 | files. |
559 | 205 | """ | 311 | """ |
560 | 206 | 312 | ||
561 | @@ -230,8 +336,7 @@ | |||
562 | 230 | config file are set in :meth:`find_config_file_paths` and then passed | 336 | config file are set in :meth:`find_config_file_paths` and then passed |
563 | 231 | to the config file loader where they are resolved to an absolute path. | 337 | to the config file loader where they are resolved to an absolute path. |
564 | 232 | 338 | ||
567 | 233 | If a profile has been set at the command line, this will resolve | 339 | If a profile has been set at the command line, this will resolve it. |
566 | 234 | it. | ||
568 | 235 | """ | 340 | """ |
569 | 236 | 341 | ||
570 | 237 | try: | 342 | try: |
571 | @@ -241,11 +346,12 @@ | |||
572 | 241 | 346 | ||
573 | 242 | try: | 347 | try: |
574 | 243 | self.profile_name = self.command_line_config.Global.profile | 348 | self.profile_name = self.command_line_config.Global.profile |
575 | 349 | except AttributeError: | ||
576 | 350 | pass | ||
577 | 351 | else: | ||
578 | 244 | name_parts = self.config_file_name.split('.') | 352 | name_parts = self.config_file_name.split('.') |
579 | 245 | name_parts.insert(1, u'_' + self.profile_name + u'.') | 353 | name_parts.insert(1, u'_' + self.profile_name + u'.') |
580 | 246 | self.config_file_name = ''.join(name_parts) | 354 | self.config_file_name = ''.join(name_parts) |
581 | 247 | except AttributeError: | ||
582 | 248 | pass | ||
583 | 249 | 355 | ||
584 | 250 | def find_config_file_paths(self): | 356 | def find_config_file_paths(self): |
585 | 251 | """Set the search paths for resolving the config file. | 357 | """Set the search paths for resolving the config file. |
586 | @@ -253,7 +359,11 @@ | |||
587 | 253 | This must set ``self.config_file_paths`` to a sequence of search | 359 | This must set ``self.config_file_paths`` to a sequence of search |
588 | 254 | paths to pass to the config file loader. | 360 | paths to pass to the config file loader. |
589 | 255 | """ | 361 | """ |
591 | 256 | self.config_file_paths = (os.getcwd(), self.ipython_dir) | 362 | # Include our own profiles directory last, so that users can still find |
592 | 363 | # our shipped copies of builtin profiles even if they don't have them | ||
593 | 364 | # in their local ipython directory. | ||
594 | 365 | prof_dir = os.path.join(get_ipython_package_dir(), 'config', 'profile') | ||
595 | 366 | self.config_file_paths = (os.getcwd(), self.ipython_dir, prof_dir) | ||
596 | 257 | 367 | ||
597 | 258 | def pre_load_file_config(self): | 368 | def pre_load_file_config(self): |
598 | 259 | """Do actions before the config file is loaded.""" | 369 | """Do actions before the config file is loaded.""" |
599 | @@ -266,7 +376,8 @@ | |||
600 | 266 | ``CONFIG_FILE`` config variable is set to the resolved config file | 376 | ``CONFIG_FILE`` config variable is set to the resolved config file |
601 | 267 | location. If not successful, an empty config is used. | 377 | location. If not successful, an empty config is used. |
602 | 268 | """ | 378 | """ |
604 | 269 | self.log.debug("Attempting to load config file: %s" % self.config_file_name) | 379 | self.log.debug("Attempting to load config file: %s" % |
605 | 380 | self.config_file_name) | ||
606 | 270 | loader = PyFileConfigLoader(self.config_file_name, | 381 | loader = PyFileConfigLoader(self.config_file_name, |
607 | 271 | path=self.config_file_paths) | 382 | path=self.config_file_paths) |
608 | 272 | try: | 383 | try: |
609 | @@ -275,11 +386,11 @@ | |||
610 | 275 | except IOError: | 386 | except IOError: |
611 | 276 | # Only warn if the default config file was NOT being used. | 387 | # Only warn if the default config file was NOT being used. |
612 | 277 | if not self.config_file_name==self.default_config_file_name: | 388 | if not self.config_file_name==self.default_config_file_name: |
614 | 278 | self.log.warn("Config file not found, skipping: %s" % \ | 389 | self.log.warn("Config file not found, skipping: %s" % |
615 | 279 | self.config_file_name, exc_info=True) | 390 | self.config_file_name, exc_info=True) |
616 | 280 | self.file_config = Config() | 391 | self.file_config = Config() |
617 | 281 | except: | 392 | except: |
619 | 282 | self.log.warn("Error loading config file: %s" % \ | 393 | self.log.warn("Error loading config file: %s" % |
620 | 283 | self.config_file_name, exc_info=True) | 394 | self.config_file_name, exc_info=True) |
621 | 284 | self.file_config = Config() | 395 | self.file_config = Config() |
622 | 285 | 396 | ||
623 | @@ -299,16 +410,27 @@ | |||
624 | 299 | 410 | ||
625 | 300 | def log_file_config(self): | 411 | def log_file_config(self): |
626 | 301 | if hasattr(self.file_config.Global, 'config_file'): | 412 | if hasattr(self.file_config.Global, 'config_file'): |
628 | 302 | self.log.debug("Config file loaded: %s" % self.file_config.Global.config_file) | 413 | self.log.debug("Config file loaded: %s" % |
629 | 414 | self.file_config.Global.config_file) | ||
630 | 303 | self.log.debug(repr(self.file_config)) | 415 | self.log.debug(repr(self.file_config)) |
631 | 304 | 416 | ||
632 | 305 | def merge_configs(self): | 417 | def merge_configs(self): |
633 | 306 | """Merge the default, command line and file config objects.""" | 418 | """Merge the default, command line and file config objects.""" |
634 | 307 | config = Config() | 419 | config = Config() |
635 | 308 | config._merge(self.default_config) | 420 | config._merge(self.default_config) |
638 | 309 | config._merge(self.file_config) | 421 | if self.override_config is None: |
639 | 310 | config._merge(self.command_line_config) | 422 | config._merge(self.file_config) |
640 | 423 | config._merge(self.command_line_config) | ||
641 | 424 | if self.constructor_config is not None: | ||
642 | 425 | config._merge(self.constructor_config) | ||
643 | 426 | else: | ||
644 | 427 | config._merge(self.override_config) | ||
645 | 428 | # XXX fperez - propose to Brian we rename master_config to simply | ||
646 | 429 | # config, I think this is going to be heavily used in examples and | ||
647 | 430 | # application code and the name is shorter/easier to find/remember. | ||
648 | 431 | # For now, just alias it... | ||
649 | 311 | self.master_config = config | 432 | self.master_config = config |
650 | 433 | self.config = config | ||
651 | 312 | 434 | ||
652 | 313 | def log_master_config(self): | 435 | def log_master_config(self): |
653 | 314 | self.log.debug("Master config created:") | 436 | self.log.debug("Master config created:") |
654 | @@ -358,7 +480,10 @@ | |||
655 | 358 | raise | 480 | raise |
656 | 359 | except: | 481 | except: |
657 | 360 | if action == 'abort': | 482 | if action == 'abort': |
658 | 483 | self.log.critical("Aborting application: %s" % self.name, | ||
659 | 484 | exc_info=True) | ||
660 | 361 | self.abort() | 485 | self.abort() |
661 | 486 | raise | ||
662 | 362 | elif action == 'exit': | 487 | elif action == 'exit': |
663 | 363 | self.exit(0) | 488 | self.exit(0) |
664 | 364 | 489 | ||
665 | 365 | 490 | ||
666 | === modified file 'IPython/core/builtin_trap.py' (properties changed: -x to +x) | |||
667 | === modified file 'IPython/core/completer.py' | |||
668 | --- IPython/core/completer.py 2009-09-12 17:45:35 +0000 | |||
669 | +++ IPython/core/completer.py 2010-01-18 01:17:11 +0000 | |||
670 | @@ -44,7 +44,6 @@ | |||
671 | 44 | 44 | ||
672 | 45 | - When the original stdin is not a tty device, GNU readline is never | 45 | - When the original stdin is not a tty device, GNU readline is never |
673 | 46 | used, and this module (and the readline module) are silently inactive. | 46 | used, and this module (and the readline module) are silently inactive. |
674 | 47 | |||
675 | 48 | """ | 47 | """ |
676 | 49 | 48 | ||
677 | 50 | #***************************************************************************** | 49 | #***************************************************************************** |
678 | @@ -54,14 +53,19 @@ | |||
679 | 54 | # proper procedure is to maintain its copyright as belonging to the Python | 53 | # proper procedure is to maintain its copyright as belonging to the Python |
680 | 55 | # Software Foundation (in addition to my own, for all new code). | 54 | # Software Foundation (in addition to my own, for all new code). |
681 | 56 | # | 55 | # |
682 | 56 | # Copyright (C) 2008-2010 IPython Development Team | ||
683 | 57 | # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu> | ||
684 | 57 | # Copyright (C) 2001 Python Software Foundation, www.python.org | 58 | # Copyright (C) 2001 Python Software Foundation, www.python.org |
685 | 58 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | ||
686 | 59 | # | 59 | # |
687 | 60 | # Distributed under the terms of the BSD License. The full license is in | 60 | # Distributed under the terms of the BSD License. The full license is in |
688 | 61 | # the file COPYING, distributed as part of this software. | 61 | # the file COPYING, distributed as part of this software. |
689 | 62 | # | 62 | # |
690 | 63 | #***************************************************************************** | 63 | #***************************************************************************** |
691 | 64 | 64 | ||
692 | 65 | #----------------------------------------------------------------------------- | ||
693 | 66 | # Imports | ||
694 | 67 | #----------------------------------------------------------------------------- | ||
695 | 68 | |||
696 | 65 | import __builtin__ | 69 | import __builtin__ |
697 | 66 | import __main__ | 70 | import __main__ |
698 | 67 | import glob | 71 | import glob |
699 | @@ -73,23 +77,57 @@ | |||
700 | 73 | import sys | 77 | import sys |
701 | 74 | import types | 78 | import types |
702 | 75 | 79 | ||
703 | 80 | import IPython.utils.rlineimpl as readline | ||
704 | 76 | from IPython.core.error import TryNext | 81 | from IPython.core.error import TryNext |
705 | 77 | from IPython.core.prefilter import ESC_MAGIC | 82 | from IPython.core.prefilter import ESC_MAGIC |
706 | 78 | |||
707 | 79 | import IPython.utils.rlineimpl as readline | ||
708 | 80 | from IPython.utils.ipstruct import Struct | ||
709 | 81 | from IPython.utils import generics | 83 | from IPython.utils import generics |
710 | 82 | |||
711 | 83 | # Python 2.4 offers sets as a builtin | ||
712 | 84 | try: | ||
713 | 85 | set() | ||
714 | 86 | except NameError: | ||
715 | 87 | from sets import Set as set | ||
716 | 88 | |||
717 | 89 | from IPython.utils.genutils import debugx, dir2 | 84 | from IPython.utils.genutils import debugx, dir2 |
718 | 90 | 85 | ||
719 | 86 | #----------------------------------------------------------------------------- | ||
720 | 87 | # Globals | ||
721 | 88 | #----------------------------------------------------------------------------- | ||
722 | 89 | |||
723 | 90 | # Public API | ||
724 | 91 | __all__ = ['Completer','IPCompleter'] | 91 | __all__ = ['Completer','IPCompleter'] |
725 | 92 | 92 | ||
726 | 93 | if sys.platform == 'win32': | ||
727 | 94 | PROTECTABLES = ' ' | ||
728 | 95 | else: | ||
729 | 96 | PROTECTABLES = ' ()' | ||
730 | 97 | |||
731 | 98 | #----------------------------------------------------------------------------- | ||
732 | 99 | # Main functions and classes | ||
733 | 100 | #----------------------------------------------------------------------------- | ||
734 | 101 | |||
735 | 102 | def protect_filename(s): | ||
736 | 103 | """Escape a string to protect certain characters.""" | ||
737 | 104 | |||
738 | 105 | return "".join([(ch in PROTECTABLES and '\\' + ch or ch) | ||
739 | 106 | for ch in s]) | ||
740 | 107 | |||
741 | 108 | |||
742 | 109 | def single_dir_expand(matches): | ||
743 | 110 | "Recursively expand match lists containing a single dir." | ||
744 | 111 | |||
745 | 112 | if len(matches) == 1 and os.path.isdir(matches[0]): | ||
746 | 113 | # Takes care of links to directories also. Use '/' | ||
747 | 114 | # explicitly, even under Windows, so that name completions | ||
748 | 115 | # don't end up escaped. | ||
749 | 116 | d = matches[0] | ||
750 | 117 | if d[-1] in ['/','\\']: | ||
751 | 118 | d = d[:-1] | ||
752 | 119 | |||
753 | 120 | subdirs = os.listdir(d) | ||
754 | 121 | if subdirs: | ||
755 | 122 | matches = [ (d + '/' + p) for p in subdirs] | ||
756 | 123 | return single_dir_expand(matches) | ||
757 | 124 | else: | ||
758 | 125 | return matches | ||
759 | 126 | else: | ||
760 | 127 | return matches | ||
761 | 128 | |||
762 | 129 | class Bunch: pass | ||
763 | 130 | |||
764 | 93 | class Completer: | 131 | class Completer: |
765 | 94 | def __init__(self,namespace=None,global_namespace=None): | 132 | def __init__(self,namespace=None,global_namespace=None): |
766 | 95 | """Create a new completer for the command line. | 133 | """Create a new completer for the command line. |
767 | @@ -152,6 +190,7 @@ | |||
768 | 152 | defined in self.namespace or self.global_namespace that match. | 190 | defined in self.namespace or self.global_namespace that match. |
769 | 153 | 191 | ||
770 | 154 | """ | 192 | """ |
771 | 193 | #print 'Completer->global_matches, txt=%r' % text # dbg | ||
772 | 155 | matches = [] | 194 | matches = [] |
773 | 156 | match_append = matches.append | 195 | match_append = matches.append |
774 | 157 | n = len(text) | 196 | n = len(text) |
775 | @@ -179,6 +218,7 @@ | |||
776 | 179 | """ | 218 | """ |
777 | 180 | import re | 219 | import re |
778 | 181 | 220 | ||
779 | 221 | #print 'Completer->attr_matches, txt=%r' % text # dbg | ||
780 | 182 | # Another option, seems to work great. Catches things like ''.<tab> | 222 | # Another option, seems to work great. Catches things like ''.<tab> |
781 | 183 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) | 223 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
782 | 184 | 224 | ||
783 | @@ -205,6 +245,7 @@ | |||
784 | 205 | res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ] | 245 | res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ] |
785 | 206 | return res | 246 | return res |
786 | 207 | 247 | ||
787 | 248 | |||
788 | 208 | class IPCompleter(Completer): | 249 | class IPCompleter(Completer): |
789 | 209 | """Extension of the completer class with IPython-specific features""" | 250 | """Extension of the completer class with IPython-specific features""" |
790 | 210 | 251 | ||
791 | @@ -235,7 +276,7 @@ | |||
792 | 235 | to complete. """ | 276 | to complete. """ |
793 | 236 | 277 | ||
794 | 237 | Completer.__init__(self,namespace,global_namespace) | 278 | Completer.__init__(self,namespace,global_namespace) |
796 | 238 | self.magic_prefix = shell.name+'.magic_' | 279 | |
797 | 239 | self.magic_escape = ESC_MAGIC | 280 | self.magic_escape = ESC_MAGIC |
798 | 240 | self.readline = readline | 281 | self.readline = readline |
799 | 241 | delims = self.readline.get_completer_delims() | 282 | delims = self.readline.get_completer_delims() |
800 | @@ -244,7 +285,8 @@ | |||
801 | 244 | self.get_line_buffer = self.readline.get_line_buffer | 285 | self.get_line_buffer = self.readline.get_line_buffer |
802 | 245 | self.get_endidx = self.readline.get_endidx | 286 | self.get_endidx = self.readline.get_endidx |
803 | 246 | self.omit__names = omit__names | 287 | self.omit__names = omit__names |
805 | 247 | self.merge_completions = shell.readline_merge_completions | 288 | self.merge_completions = shell.readline_merge_completions |
806 | 289 | self.shell = shell.shell | ||
807 | 248 | if alias_table is None: | 290 | if alias_table is None: |
808 | 249 | alias_table = {} | 291 | alias_table = {} |
809 | 250 | self.alias_table = alias_table | 292 | self.alias_table = alias_table |
810 | @@ -263,11 +305,13 @@ | |||
811 | 263 | self.clean_glob = self._clean_glob_win32 | 305 | self.clean_glob = self._clean_glob_win32 |
812 | 264 | else: | 306 | else: |
813 | 265 | self.clean_glob = self._clean_glob | 307 | self.clean_glob = self._clean_glob |
814 | 308 | |||
815 | 309 | # All active matcher routines for completion | ||
816 | 266 | self.matchers = [self.python_matches, | 310 | self.matchers = [self.python_matches, |
817 | 267 | self.file_matches, | 311 | self.file_matches, |
818 | 312 | self.magic_matches, | ||
819 | 268 | self.alias_matches, | 313 | self.alias_matches, |
820 | 269 | self.python_func_kw_matches] | 314 | self.python_func_kw_matches] |
821 | 270 | |||
822 | 271 | 315 | ||
823 | 272 | # Code contributed by Alex Schmolck, for ipython/emacs integration | 316 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
824 | 273 | def all_completions(self, text): | 317 | def all_completions(self, text): |
825 | @@ -278,9 +322,8 @@ | |||
826 | 278 | try: | 322 | try: |
827 | 279 | for i in xrange(sys.maxint): | 323 | for i in xrange(sys.maxint): |
828 | 280 | res = self.complete(text, i) | 324 | res = self.complete(text, i) |
832 | 281 | 325 | if not res: | |
833 | 282 | if not res: break | 326 | break |
831 | 283 | |||
834 | 284 | comp_append(res) | 327 | comp_append(res) |
835 | 285 | #XXX workaround for ``notDefined.<tab>`` | 328 | #XXX workaround for ``notDefined.<tab>`` |
836 | 286 | except NameError: | 329 | except NameError: |
837 | @@ -316,41 +359,12 @@ | |||
838 | 316 | # don't want to treat as delimiters in filename matching | 359 | # don't want to treat as delimiters in filename matching |
839 | 317 | # when escaped with backslash | 360 | # when escaped with backslash |
840 | 318 | 361 | ||
841 | 319 | if sys.platform == 'win32': | ||
842 | 320 | protectables = ' ' | ||
843 | 321 | else: | ||
844 | 322 | protectables = ' ()' | ||
845 | 323 | |||
846 | 324 | if text.startswith('!'): | 362 | if text.startswith('!'): |
847 | 325 | text = text[1:] | 363 | text = text[1:] |
848 | 326 | text_prefix = '!' | 364 | text_prefix = '!' |
849 | 327 | else: | 365 | else: |
850 | 328 | text_prefix = '' | 366 | text_prefix = '' |
851 | 329 | 367 | ||
852 | 330 | def protect_filename(s): | ||
853 | 331 | return "".join([(ch in protectables and '\\' + ch or ch) | ||
854 | 332 | for ch in s]) | ||
855 | 333 | |||
856 | 334 | def single_dir_expand(matches): | ||
857 | 335 | "Recursively expand match lists containing a single dir." | ||
858 | 336 | |||
859 | 337 | if len(matches) == 1 and os.path.isdir(matches[0]): | ||
860 | 338 | # Takes care of links to directories also. Use '/' | ||
861 | 339 | # explicitly, even under Windows, so that name completions | ||
862 | 340 | # don't end up escaped. | ||
863 | 341 | d = matches[0] | ||
864 | 342 | if d[-1] in ['/','\\']: | ||
865 | 343 | d = d[:-1] | ||
866 | 344 | |||
867 | 345 | subdirs = os.listdir(d) | ||
868 | 346 | if subdirs: | ||
869 | 347 | matches = [ (d + '/' + p) for p in subdirs] | ||
870 | 348 | return single_dir_expand(matches) | ||
871 | 349 | else: | ||
872 | 350 | return matches | ||
873 | 351 | else: | ||
874 | 352 | return matches | ||
875 | 353 | |||
876 | 354 | lbuf = self.lbuf | 368 | lbuf = self.lbuf |
877 | 355 | open_quotes = 0 # track strings with open quotes | 369 | open_quotes = 0 # track strings with open quotes |
878 | 356 | try: | 370 | try: |
879 | @@ -402,13 +416,24 @@ | |||
880 | 402 | #print 'mm',matches # dbg | 416 | #print 'mm',matches # dbg |
881 | 403 | return single_dir_expand(matches) | 417 | return single_dir_expand(matches) |
882 | 404 | 418 | ||
883 | 419 | def magic_matches(self, text): | ||
884 | 420 | """Match magics""" | ||
885 | 421 | #print 'Completer->magic_matches:',text,'lb',self.lbuf # dbg | ||
886 | 422 | # Get all shell magics now rather than statically, so magics loaded at | ||
887 | 423 | # runtime show up too | ||
888 | 424 | magics = self.shell.lsmagic() | ||
889 | 425 | pre = self.magic_escape | ||
890 | 426 | baretext = text.lstrip(pre) | ||
891 | 427 | return [ pre+m for m in magics if m.startswith(baretext)] | ||
892 | 428 | |||
893 | 405 | def alias_matches(self, text): | 429 | def alias_matches(self, text): |
894 | 406 | """Match internal system aliases""" | 430 | """Match internal system aliases""" |
895 | 407 | #print 'Completer->alias_matches:',text,'lb',self.lbuf # dbg | 431 | #print 'Completer->alias_matches:',text,'lb',self.lbuf # dbg |
896 | 408 | 432 | ||
897 | 409 | # if we are not in the first 'item', alias matching | 433 | # if we are not in the first 'item', alias matching |
898 | 410 | # doesn't make sense - unless we are starting with 'sudo' command. | 434 | # doesn't make sense - unless we are starting with 'sudo' command. |
900 | 411 | if ' ' in self.lbuf.lstrip() and not self.lbuf.lstrip().startswith('sudo'): | 435 | if ' ' in self.lbuf.lstrip() and \ |
901 | 436 | not self.lbuf.lstrip().startswith('sudo'): | ||
902 | 412 | return [] | 437 | return [] |
903 | 413 | text = os.path.expanduser(text) | 438 | text = os.path.expanduser(text) |
904 | 414 | aliases = self.alias_table.keys() | 439 | aliases = self.alias_table.keys() |
905 | @@ -420,7 +445,7 @@ | |||
906 | 420 | def python_matches(self,text): | 445 | def python_matches(self,text): |
907 | 421 | """Match attributes or global python names""" | 446 | """Match attributes or global python names""" |
908 | 422 | 447 | ||
910 | 423 | #print 'Completer->python_matches, txt=<%s>' % text # dbg | 448 | #print 'Completer->python_matches, txt=%r' % text # dbg |
911 | 424 | if "." in text: | 449 | if "." in text: |
912 | 425 | try: | 450 | try: |
913 | 426 | matches = self.attr_matches(text) | 451 | matches = self.attr_matches(text) |
914 | @@ -439,11 +464,7 @@ | |||
915 | 439 | matches = [] | 464 | matches = [] |
916 | 440 | else: | 465 | else: |
917 | 441 | matches = self.global_matches(text) | 466 | matches = self.global_matches(text) |
923 | 442 | # this is so completion finds magics when automagic is on: | 467 | |
919 | 443 | if (matches == [] and | ||
920 | 444 | not text.startswith(os.sep) and | ||
921 | 445 | not ' ' in self.lbuf): | ||
922 | 446 | matches = self.attr_matches(self.magic_prefix+text) | ||
924 | 447 | return matches | 468 | return matches |
925 | 448 | 469 | ||
926 | 449 | def _default_arguments(self, obj): | 470 | def _default_arguments(self, obj): |
927 | @@ -514,9 +535,11 @@ | |||
928 | 514 | callableMatches = self.attr_matches('.'.join(ids[::-1])) | 535 | callableMatches = self.attr_matches('.'.join(ids[::-1])) |
929 | 515 | argMatches = [] | 536 | argMatches = [] |
930 | 516 | for callableMatch in callableMatches: | 537 | for callableMatch in callableMatches: |
932 | 517 | try: namedArgs = self._default_arguments(eval(callableMatch, | 538 | try: |
933 | 539 | namedArgs = self._default_arguments(eval(callableMatch, | ||
934 | 518 | self.namespace)) | 540 | self.namespace)) |
936 | 519 | except: continue | 541 | except: |
937 | 542 | continue | ||
938 | 520 | for namedArg in namedArgs: | 543 | for namedArg in namedArgs: |
939 | 521 | if namedArg.startswith(text): | 544 | if namedArg.startswith(text): |
940 | 522 | argMatches.append("%s=" %namedArg) | 545 | argMatches.append("%s=" %namedArg) |
941 | @@ -528,7 +551,7 @@ | |||
942 | 528 | if not line.strip(): | 551 | if not line.strip(): |
943 | 529 | return None | 552 | return None |
944 | 530 | 553 | ||
946 | 531 | event = Struct() | 554 | event = Bunch() |
947 | 532 | event.line = line | 555 | event.line = line |
948 | 533 | event.symbol = text | 556 | event.symbol = text |
949 | 534 | cmd = line.split(None,1)[0] | 557 | cmd = line.split(None,1)[0] |
950 | @@ -540,11 +563,9 @@ | |||
951 | 540 | try_magic = self.custom_completers.s_matches( | 563 | try_magic = self.custom_completers.s_matches( |
952 | 541 | self.magic_escape + cmd) | 564 | self.magic_escape + cmd) |
953 | 542 | else: | 565 | else: |
959 | 543 | try_magic = [] | 566 | try_magic = [] |
960 | 544 | 567 | ||
961 | 545 | 568 | for c in itertools.chain(self.custom_completers.s_matches(cmd), | |
957 | 546 | for c in itertools.chain( | ||
958 | 547 | self.custom_completers.s_matches(cmd), | ||
962 | 548 | try_magic, | 569 | try_magic, |
963 | 549 | self.custom_completers.flat_matches(self.lbuf)): | 570 | self.custom_completers.flat_matches(self.lbuf)): |
964 | 550 | #print "try",c # dbg | 571 | #print "try",c # dbg |
965 | @@ -555,7 +576,8 @@ | |||
966 | 555 | if withcase: | 576 | if withcase: |
967 | 556 | return withcase | 577 | return withcase |
968 | 557 | # if none, then case insensitive ones are ok too | 578 | # if none, then case insensitive ones are ok too |
970 | 558 | return [r for r in res if r.lower().startswith(text.lower())] | 579 | text_low = text.lower() |
971 | 580 | return [r for r in res if r.lower().startswith(text_low)] | ||
972 | 559 | except TryNext: | 581 | except TryNext: |
973 | 560 | pass | 582 | pass |
974 | 561 | 583 | ||
975 | @@ -598,14 +620,11 @@ | |||
976 | 598 | return None | 620 | return None |
977 | 599 | 621 | ||
978 | 600 | magic_escape = self.magic_escape | 622 | magic_escape = self.magic_escape |
979 | 601 | magic_prefix = self.magic_prefix | ||
980 | 602 | 623 | ||
981 | 603 | self.lbuf = self.full_lbuf[:self.get_endidx()] | 624 | self.lbuf = self.full_lbuf[:self.get_endidx()] |
982 | 604 | 625 | ||
983 | 605 | try: | 626 | try: |
987 | 606 | if text.startswith(magic_escape): | 627 | if text.startswith('~'): |
985 | 607 | text = text.replace(magic_escape,magic_prefix) | ||
986 | 608 | elif text.startswith('~'): | ||
988 | 609 | text = os.path.expanduser(text) | 628 | text = os.path.expanduser(text) |
989 | 610 | if state == 0: | 629 | if state == 0: |
990 | 611 | custom_res = self.dispatch_custom_completer(text) | 630 | custom_res = self.dispatch_custom_completer(text) |
991 | @@ -625,13 +644,10 @@ | |||
992 | 625 | self.matches = matcher(text) | 644 | self.matches = matcher(text) |
993 | 626 | if self.matches: | 645 | if self.matches: |
994 | 627 | break | 646 | break |
999 | 628 | def uniq(alist): | 647 | self.matches = list(set(self.matches)) |
996 | 629 | set = {} | ||
997 | 630 | return [set.setdefault(e,e) for e in alist if e not in set] | ||
998 | 631 | self.matches = uniq(self.matches) | ||
1000 | 632 | try: | 648 | try: |
1003 | 633 | ret = self.matches[state].replace(magic_prefix,magic_escape) | 649 | #print "MATCH: %r" % self.matches[state] # dbg |
1004 | 634 | return ret | 650 | return self.matches[state] |
1005 | 635 | except IndexError: | 651 | except IndexError: |
1006 | 636 | return None | 652 | return None |
1007 | 637 | except: | 653 | except: |
1008 | 638 | 654 | ||
1009 | === modified file 'IPython/core/crashhandler.py' | |||
1010 | --- IPython/core/crashhandler.py 2009-11-09 01:49:24 +0000 | |||
1011 | +++ IPython/core/crashhandler.py 2010-01-18 01:17:11 +0000 | |||
1012 | @@ -26,12 +26,13 @@ | |||
1013 | 26 | # Our own | 26 | # Our own |
1014 | 27 | from IPython.core import release | 27 | from IPython.core import release |
1015 | 28 | from IPython.core import ultratb | 28 | from IPython.core import ultratb |
1016 | 29 | from IPython.utils.genutils import sys_info | ||
1017 | 30 | |||
1018 | 29 | from IPython.external.Itpl import itpl | 31 | from IPython.external.Itpl import itpl |
1019 | 30 | 32 | ||
1020 | 31 | from IPython.utils.genutils import * | ||
1021 | 32 | |||
1022 | 33 | #**************************************************************************** | 33 | #**************************************************************************** |
1024 | 34 | class CrashHandler: | 34 | |
1025 | 35 | class CrashHandler(object): | ||
1026 | 35 | """Customizable crash handlers for IPython-based systems. | 36 | """Customizable crash handlers for IPython-based systems. |
1027 | 36 | 37 | ||
1028 | 37 | Instances of this class provide a __call__ method which can be used as a | 38 | Instances of this class provide a __call__ method which can be used as a |
1029 | @@ -41,15 +42,15 @@ | |||
1030 | 41 | 42 | ||
1031 | 42 | """ | 43 | """ |
1032 | 43 | 44 | ||
1036 | 44 | def __init__(self,IP,app_name,contact_name,contact_email, | 45 | def __init__(self,app, app_name, contact_name=None, contact_email=None, |
1037 | 45 | bug_tracker,crash_report_fname, | 46 | bug_tracker=None, crash_report_fname='CrashReport.txt', |
1038 | 46 | show_crash_traceback=True): | 47 | show_crash_traceback=True, call_pdb=False): |
1039 | 47 | """New crash handler. | 48 | """New crash handler. |
1040 | 48 | 49 | ||
1041 | 49 | Inputs: | 50 | Inputs: |
1042 | 50 | 51 | ||
1045 | 51 | - IP: a running IPython instance, which will be queried at crash time | 52 | - app: a running application instance, which will be queried at crash |
1046 | 52 | for internal information. | 53 | time for internal information. |
1047 | 53 | 54 | ||
1048 | 54 | - app_name: a string containing the name of your application. | 55 | - app_name: a string containing the name of your application. |
1049 | 55 | 56 | ||
1050 | @@ -77,13 +78,16 @@ | |||
1051 | 77 | """ | 78 | """ |
1052 | 78 | 79 | ||
1053 | 79 | # apply args into instance | 80 | # apply args into instance |
1055 | 80 | self.IP = IP # IPython instance | 81 | self.app = app |
1056 | 81 | self.app_name = app_name | 82 | self.app_name = app_name |
1057 | 82 | self.contact_name = contact_name | 83 | self.contact_name = contact_name |
1058 | 83 | self.contact_email = contact_email | 84 | self.contact_email = contact_email |
1059 | 84 | self.bug_tracker = bug_tracker | 85 | self.bug_tracker = bug_tracker |
1060 | 85 | self.crash_report_fname = crash_report_fname | 86 | self.crash_report_fname = crash_report_fname |
1061 | 86 | self.show_crash_traceback = show_crash_traceback | 87 | self.show_crash_traceback = show_crash_traceback |
1062 | 88 | self.section_sep = '\n\n'+'*'*75+'\n\n' | ||
1063 | 89 | self.call_pdb = call_pdb | ||
1064 | 90 | #self.call_pdb = True # dbg | ||
1065 | 87 | 91 | ||
1066 | 88 | # Hardcoded defaults, which can be overridden either by subclasses or | 92 | # Hardcoded defaults, which can be overridden either by subclasses or |
1067 | 89 | # at runtime for the instance. | 93 | # at runtime for the instance. |
1068 | @@ -124,7 +128,7 @@ | |||
1069 | 124 | #color_scheme = 'Linux' # dbg | 128 | #color_scheme = 'Linux' # dbg |
1070 | 125 | 129 | ||
1071 | 126 | try: | 130 | try: |
1073 | 127 | rptdir = self.IP.ipython_dir | 131 | rptdir = self.app.ipython_dir |
1074 | 128 | except: | 132 | except: |
1075 | 129 | rptdir = os.getcwd() | 133 | rptdir = os.getcwd() |
1076 | 130 | if not os.path.isdir(rptdir): | 134 | if not os.path.isdir(rptdir): |
1077 | @@ -134,8 +138,14 @@ | |||
1078 | 134 | # properly expanded out in the user message template | 138 | # properly expanded out in the user message template |
1079 | 135 | self.crash_report_fname = report_name | 139 | self.crash_report_fname = report_name |
1080 | 136 | TBhandler = ultratb.VerboseTB(color_scheme=color_scheme, | 140 | TBhandler = ultratb.VerboseTB(color_scheme=color_scheme, |
1083 | 137 | long_header=1) | 141 | long_header=1, |
1084 | 138 | traceback = TBhandler.text(etype,evalue,etb,context=31) | 142 | call_pdb=self.call_pdb, |
1085 | 143 | ) | ||
1086 | 144 | if self.call_pdb: | ||
1087 | 145 | TBhandler(etype,evalue,etb) | ||
1088 | 146 | return | ||
1089 | 147 | else: | ||
1090 | 148 | traceback = TBhandler.text(etype,evalue,etb,context=31) | ||
1091 | 139 | 149 | ||
1092 | 140 | # print traceback to screen | 150 | # print traceback to screen |
1093 | 141 | if self.show_crash_traceback: | 151 | if self.show_crash_traceback: |
1094 | @@ -155,74 +165,58 @@ | |||
1095 | 155 | # Construct report on disk | 165 | # Construct report on disk |
1096 | 156 | report.write(self.make_report(traceback)) | 166 | report.write(self.make_report(traceback)) |
1097 | 157 | report.close() | 167 | report.close() |
1099 | 158 | raw_input("Press enter to exit:") | 168 | raw_input("Hit <Enter> to quit this message (your terminal may close):") |
1100 | 159 | 169 | ||
1101 | 160 | def make_report(self,traceback): | 170 | def make_report(self,traceback): |
1102 | 161 | """Return a string containing a crash report.""" | 171 | """Return a string containing a crash report.""" |
1107 | 162 | 172 | ||
1108 | 163 | sec_sep = '\n\n'+'*'*75+'\n\n' | 173 | sec_sep = self.section_sep |
1109 | 164 | 174 | ||
1110 | 165 | report = [] | 175 | report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n'] |
1111 | 166 | rpt_add = report.append | 176 | rpt_add = report.append |
1112 | 177 | rpt_add(sys_info()) | ||
1113 | 167 | 178 | ||
1114 | 168 | rpt_add('*'*75+'\n\n'+'IPython post-mortem report\n\n') | ||
1115 | 169 | rpt_add('IPython version: %s \n\n' % release.version) | ||
1116 | 170 | rpt_add('BZR revision : %s \n\n' % release.revision) | ||
1117 | 171 | rpt_add('Platform info : os.name -> %s, sys.platform -> %s' % | ||
1118 | 172 | (os.name,sys.platform) ) | ||
1119 | 173 | rpt_add(sec_sep+'Current user configuration structure:\n\n') | ||
1120 | 174 | rpt_add(pformat(self.IP.dict())) | ||
1121 | 175 | rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) | ||
1122 | 176 | try: | 179 | try: |
1128 | 177 | rpt_add(sec_sep+"History of session input:") | 180 | config = pformat(self.app.config) |
1129 | 178 | for line in self.IP.user_ns['_ih']: | 181 | rpt_add(sec_sep+'Current user configuration structure:\n\n') |
1130 | 179 | rpt_add(line) | 182 | rpt_add(config) |
1126 | 180 | rpt_add('\n*** Last line of input (may not be in above history):\n') | ||
1127 | 181 | rpt_add(self.IP._last_input_line+'\n') | ||
1131 | 182 | except: | 183 | except: |
1132 | 183 | pass | 184 | pass |
1133 | 185 | rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) | ||
1134 | 184 | 186 | ||
1135 | 185 | return ''.join(report) | 187 | return ''.join(report) |
1136 | 186 | 188 | ||
1137 | 189 | |||
1138 | 187 | class IPythonCrashHandler(CrashHandler): | 190 | class IPythonCrashHandler(CrashHandler): |
1139 | 188 | """sys.excepthook for IPython itself, leaves a detailed report on disk.""" | 191 | """sys.excepthook for IPython itself, leaves a detailed report on disk.""" |
1140 | 189 | 192 | ||
1142 | 190 | def __init__(self,IP): | 193 | def __init__(self, app, app_name='IPython'): |
1143 | 191 | 194 | ||
1144 | 192 | # Set here which of the IPython authors should be listed as contact | 195 | # Set here which of the IPython authors should be listed as contact |
1145 | 193 | AUTHOR_CONTACT = 'Fernando' | 196 | AUTHOR_CONTACT = 'Fernando' |
1146 | 194 | 197 | ||
1147 | 195 | # Set argument defaults | 198 | # Set argument defaults |
1148 | 196 | app_name = 'IPython' | ||
1149 | 197 | bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug' | 199 | bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug' |
1150 | 198 | contact_name,contact_email = release.authors[AUTHOR_CONTACT][:2] | 200 | contact_name,contact_email = release.authors[AUTHOR_CONTACT][:2] |
1151 | 199 | crash_report_fname = 'IPython_crash_report.txt' | 201 | crash_report_fname = 'IPython_crash_report.txt' |
1152 | 200 | # Call parent constructor | 202 | # Call parent constructor |
1154 | 201 | CrashHandler.__init__(self,IP,app_name,contact_name,contact_email, | 203 | CrashHandler.__init__(self,app,app_name,contact_name,contact_email, |
1155 | 202 | bug_tracker,crash_report_fname) | 204 | bug_tracker,crash_report_fname) |
1156 | 203 | 205 | ||
1157 | 204 | def make_report(self,traceback): | 206 | def make_report(self,traceback): |
1158 | 205 | """Return a string containing a crash report.""" | 207 | """Return a string containing a crash report.""" |
1159 | 206 | 208 | ||
1163 | 207 | sec_sep = '\n\n'+'*'*75+'\n\n' | 209 | sec_sep = self.section_sep |
1164 | 208 | 210 | # Start with parent report | |
1165 | 209 | report = [] | 211 | report = [super(IPythonCrashHandler, self).make_report(traceback)] |
1166 | 212 | # Add interactive-specific info we may have | ||
1167 | 210 | rpt_add = report.append | 213 | rpt_add = report.append |
1168 | 211 | |||
1169 | 212 | rpt_add('*'*75+'\n\n'+'IPython post-mortem report\n\n') | ||
1170 | 213 | rpt_add('IPython version: %s \n\n' % release.version) | ||
1171 | 214 | rpt_add('BZR revision : %s \n\n' % release.revision) | ||
1172 | 215 | rpt_add('Platform info : os.name -> %s, sys.platform -> %s' % | ||
1173 | 216 | (os.name,sys.platform) ) | ||
1174 | 217 | rpt_add(sec_sep+'Current user configuration structure:\n\n') | ||
1175 | 218 | # rpt_add(pformat(self.IP.dict())) | ||
1176 | 219 | rpt_add(sec_sep+'Crash traceback:\n\n' + traceback) | ||
1177 | 220 | try: | 214 | try: |
1178 | 221 | rpt_add(sec_sep+"History of session input:") | 215 | rpt_add(sec_sep+"History of session input:") |
1180 | 222 | for line in self.IP.user_ns['_ih']: | 216 | for line in self.app.shell.user_ns['_ih']: |
1181 | 223 | rpt_add(line) | 217 | rpt_add(line) |
1182 | 224 | rpt_add('\n*** Last line of input (may not be in above history):\n') | 218 | rpt_add('\n*** Last line of input (may not be in above history):\n') |
1184 | 225 | rpt_add(self.IP._last_input_line+'\n') | 219 | rpt_add(self.app.shell._last_input_line+'\n') |
1185 | 226 | except: | 220 | except: |
1186 | 227 | pass | 221 | pass |
1187 | 228 | 222 | ||
1188 | 229 | 223 | ||
1189 | === modified file 'IPython/core/debugger.py' | |||
1190 | --- IPython/core/debugger.py 2009-10-17 18:14:42 +0000 | |||
1191 | +++ IPython/core/debugger.py 2010-01-18 01:17:11 +0000 | |||
1192 | @@ -477,3 +477,36 @@ | |||
1193 | 477 | namespaces = [('Locals', self.curframe.f_locals), | 477 | namespaces = [('Locals', self.curframe.f_locals), |
1194 | 478 | ('Globals', self.curframe.f_globals)] | 478 | ('Globals', self.curframe.f_globals)] |
1195 | 479 | self.shell.magic_pinfo("pinfo %s" % arg, namespaces=namespaces) | 479 | self.shell.magic_pinfo("pinfo %s" % arg, namespaces=namespaces) |
1196 | 480 | |||
1197 | 481 | def checkline(self, filename, lineno): | ||
1198 | 482 | """Check whether specified line seems to be executable. | ||
1199 | 483 | |||
1200 | 484 | Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank | ||
1201 | 485 | line or EOF). Warning: testing is not comprehensive. | ||
1202 | 486 | """ | ||
1203 | 487 | ####################################################################### | ||
1204 | 488 | # XXX Hack! Use python-2.5 compatible code for this call, because with | ||
1205 | 489 | # all of our changes, we've drifted from the pdb api in 2.6. For now, | ||
1206 | 490 | # changing: | ||
1207 | 491 | # | ||
1208 | 492 | #line = linecache.getline(filename, lineno, self.curframe.f_globals) | ||
1209 | 493 | # to: | ||
1210 | 494 | # | ||
1211 | 495 | line = linecache.getline(filename, lineno) | ||
1212 | 496 | # | ||
1213 | 497 | # does the trick. But in reality, we need to fix this by reconciling | ||
1214 | 498 | # our updates with the new Pdb APIs in Python 2.6. | ||
1215 | 499 | # | ||
1216 | 500 | # End hack. The rest of this method is copied verbatim from 2.6 pdb.py | ||
1217 | 501 | ####################################################################### | ||
1218 | 502 | |||
1219 | 503 | if not line: | ||
1220 | 504 | print >>self.stdout, 'End of file' | ||
1221 | 505 | return 0 | ||
1222 | 506 | line = line.strip() | ||
1223 | 507 | # Don't allow setting breakpoint at a blank line | ||
1224 | 508 | if (not line or (line[0] == '#') or | ||
1225 | 509 | (line[:3] == '"""') or line[:3] == "'''"): | ||
1226 | 510 | print >>self.stdout, '*** Blank or comment' | ||
1227 | 511 | return 0 | ||
1228 | 512 | return lineno | ||
1229 | 480 | 513 | ||
1230 | === modified file 'IPython/core/history.py' | |||
1231 | --- IPython/core/history.py 2009-08-19 21:56:41 +0000 | |||
1232 | +++ IPython/core/history.py 2010-01-18 01:17:11 +0000 | |||
1233 | @@ -14,20 +14,25 @@ | |||
1234 | 14 | %history -> print at most 40 inputs (some may be multi-line)\\ | 14 | %history -> print at most 40 inputs (some may be multi-line)\\ |
1235 | 15 | %history n -> print at most n inputs\\ | 15 | %history n -> print at most n inputs\\ |
1236 | 16 | %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\ | 16 | %history n1 n2 -> print inputs between n1 and n2 (n2 not included)\\ |
1242 | 17 | 17 | ||
1243 | 18 | Each input's number <n> is shown, and is accessible as the | 18 | By default, input history is printed without line numbers so it can be |
1244 | 19 | automatically generated variable _i<n>. Multi-line statements are | 19 | directly pasted into an editor. |
1245 | 20 | printed starting at a new line for easy copy/paste. | 20 | |
1246 | 21 | 21 | With -n, each input's number <n> is shown, and is accessible as the | |
1247 | 22 | automatically generated variable _i<n> as well as In[<n>]. Multi-line | ||
1248 | 23 | statements are printed starting at a new line for easy copy/paste. | ||
1249 | 22 | 24 | ||
1250 | 23 | Options: | 25 | Options: |
1251 | 24 | 26 | ||
1256 | 25 | -n: do NOT print line numbers. This is useful if you want to get a | 27 | -n: print line numbers for each input. |
1253 | 26 | printout of many lines which can be directly pasted into a text | ||
1254 | 27 | editor. | ||
1255 | 28 | |||
1257 | 29 | This feature is only available if numbered prompts are in use. | 28 | This feature is only available if numbered prompts are in use. |
1258 | 30 | 29 | ||
1259 | 30 | -o: also print outputs for each input. | ||
1260 | 31 | |||
1261 | 32 | -p: print classic '>>>' python prompts before each input. This is useful | ||
1262 | 33 | for making documentation, and in conjunction with -o, for producing | ||
1263 | 34 | doctest-ready output. | ||
1264 | 35 | |||
1265 | 31 | -t: (default) print the 'translated' history, as IPython understands it. | 36 | -t: (default) print the 'translated' history, as IPython understands it. |
1266 | 32 | IPython filters your input and converts it all into valid Python source | 37 | IPython filters your input and converts it all into valid Python source |
1267 | 33 | before executing it (things like magics or aliases are turned into | 38 | before executing it (things like magics or aliases are turned into |
1268 | @@ -50,7 +55,7 @@ | |||
1269 | 50 | if not self.outputcache.do_full_cache: | 55 | if not self.outputcache.do_full_cache: |
1270 | 51 | print 'This feature is only available if numbered prompts are in use.' | 56 | print 'This feature is only available if numbered prompts are in use.' |
1271 | 52 | return | 57 | return |
1273 | 53 | opts,args = self.parse_options(parameter_s,'gntsrf:',mode='list') | 58 | opts,args = self.parse_options(parameter_s,'gnoptsrf:',mode='list') |
1274 | 54 | 59 | ||
1275 | 55 | # Check if output to specific file was requested. | 60 | # Check if output to specific file was requested. |
1276 | 56 | try: | 61 | try: |
1277 | @@ -80,39 +85,43 @@ | |||
1278 | 80 | if 'g' in opts: | 85 | if 'g' in opts: |
1279 | 81 | init = 1 | 86 | init = 1 |
1280 | 82 | final = len(input_hist) | 87 | final = len(input_hist) |
1282 | 83 | parts = parameter_s.split(None,1) | 88 | parts = parameter_s.split(None, 1) |
1283 | 84 | if len(parts) == 1: | 89 | if len(parts) == 1: |
1284 | 85 | parts += '*' | 90 | parts += '*' |
1285 | 86 | head, pattern = parts | 91 | head, pattern = parts |
1286 | 87 | pattern = "*" + pattern + "*" | 92 | pattern = "*" + pattern + "*" |
1287 | 88 | elif len(args) == 0: | 93 | elif len(args) == 0: |
1289 | 89 | final = len(input_hist) | 94 | final = len(input_hist)-1 |
1290 | 90 | init = max(1,final-default_length) | 95 | init = max(1,final-default_length) |
1291 | 91 | elif len(args) == 1: | 96 | elif len(args) == 1: |
1292 | 92 | final = len(input_hist) | 97 | final = len(input_hist) |
1294 | 93 | init = max(1,final-int(args[0])) | 98 | init = max(1, final-int(args[0])) |
1295 | 94 | elif len(args) == 2: | 99 | elif len(args) == 2: |
1297 | 95 | init,final = map(int,args) | 100 | init, final = map(int, args) |
1298 | 96 | else: | 101 | else: |
1299 | 97 | warn('%hist takes 0, 1 or 2 arguments separated by spaces.') | 102 | warn('%hist takes 0, 1 or 2 arguments separated by spaces.') |
1301 | 98 | print self.magic_hist.__doc__ | 103 | print >> Term.cout, self.magic_hist.__doc__ |
1302 | 99 | return | 104 | return |
1303 | 105 | |||
1304 | 100 | width = len(str(final)) | 106 | width = len(str(final)) |
1305 | 101 | line_sep = ['','\n'] | 107 | line_sep = ['','\n'] |
1307 | 102 | print_nums = not opts.has_key('n') | 108 | print_nums = 'n' in opts |
1308 | 109 | print_outputs = 'o' in opts | ||
1309 | 110 | pyprompts = 'p' in opts | ||
1310 | 103 | 111 | ||
1311 | 104 | found = False | 112 | found = False |
1312 | 105 | if pattern is not None: | 113 | if pattern is not None: |
1313 | 106 | sh = self.shadowhist.all() | 114 | sh = self.shadowhist.all() |
1314 | 107 | for idx, s in sh: | 115 | for idx, s in sh: |
1315 | 108 | if fnmatch.fnmatch(s, pattern): | 116 | if fnmatch.fnmatch(s, pattern): |
1317 | 109 | print "0%d: %s" %(idx, s) | 117 | print >> outfile, "0%d: %s" %(idx, s) |
1318 | 110 | found = True | 118 | found = True |
1319 | 111 | 119 | ||
1320 | 112 | if found: | 120 | if found: |
1324 | 113 | print "===" | 121 | print >> outfile, "===" |
1325 | 114 | print "shadow history ends, fetch by %rep <number> (must start with 0)" | 122 | print >> outfile, \ |
1326 | 115 | print "=== start of normal history ===" | 123 | "shadow history ends, fetch by %rep <number> (must start with 0)" |
1327 | 124 | print >> outfile, "=== start of normal history ===" | ||
1328 | 116 | 125 | ||
1329 | 117 | for in_num in range(init,final): | 126 | for in_num in range(init,final): |
1330 | 118 | inline = input_hist[in_num] | 127 | inline = input_hist[in_num] |
1331 | @@ -122,8 +131,21 @@ | |||
1332 | 122 | multiline = int(inline.count('\n') > 1) | 131 | multiline = int(inline.count('\n') > 1) |
1333 | 123 | if print_nums: | 132 | if print_nums: |
1334 | 124 | print >> outfile, \ | 133 | print >> outfile, \ |
1337 | 125 | '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]), | 134 | '%s:%s' % (str(in_num).ljust(width), line_sep[multiline]), |
1338 | 126 | print >> outfile, inline, | 135 | if pyprompts: |
1339 | 136 | print >> outfile, '>>>', | ||
1340 | 137 | if multiline: | ||
1341 | 138 | lines = inline.splitlines() | ||
1342 | 139 | print >> outfile, '\n... '.join(lines) | ||
1343 | 140 | print >> outfile, '... ' | ||
1344 | 141 | else: | ||
1345 | 142 | print >> outfile, inline, | ||
1346 | 143 | else: | ||
1347 | 144 | print >> outfile, inline, | ||
1348 | 145 | if print_outputs: | ||
1349 | 146 | output = self.shell.user_ns['Out'].get(in_num) | ||
1350 | 147 | if output is not None: | ||
1351 | 148 | print >> outfile, repr(output) | ||
1352 | 127 | 149 | ||
1353 | 128 | if close_at_end: | 150 | if close_at_end: |
1354 | 129 | outfile.close() | 151 | outfile.close() |
1355 | @@ -245,10 +267,10 @@ | |||
1356 | 245 | 267 | ||
1357 | 246 | 268 | ||
1358 | 247 | def init_ipython(ip): | 269 | def init_ipython(ip): |
1359 | 248 | import ipy_completers | ||
1360 | 249 | |||
1361 | 250 | ip.define_magic("rep",rep_f) | 270 | ip.define_magic("rep",rep_f) |
1362 | 251 | ip.define_magic("hist",magic_hist) | 271 | ip.define_magic("hist",magic_hist) |
1363 | 252 | ip.define_magic("history",magic_history) | 272 | ip.define_magic("history",magic_history) |
1364 | 253 | 273 | ||
1366 | 254 | ipy_completers.quick_completer('%hist' ,'-g -t -r -n') | 274 | # XXX - ipy_completers are in quarantine, need to be updated to new apis |
1367 | 275 | #import ipy_completers | ||
1368 | 276 | #ipy_completers.quick_completer('%hist' ,'-g -t -r -n') | ||
1369 | 255 | 277 | ||
1370 | === modified file 'IPython/core/hooks.py' | |||
1371 | --- IPython/core/hooks.py 2009-08-26 20:54:07 +0000 | |||
1372 | +++ IPython/core/hooks.py 2010-01-18 01:17:11 +0000 | |||
1373 | @@ -137,8 +137,7 @@ | |||
1374 | 137 | for prio,cmd in self.chain: | 137 | for prio,cmd in self.chain: |
1375 | 138 | #print "prio",prio,"cmd",cmd #dbg | 138 | #print "prio",prio,"cmd",cmd #dbg |
1376 | 139 | try: | 139 | try: |
1379 | 140 | ret = cmd(*args, **kw) | 140 | return cmd(*args, **kw) |
1378 | 141 | return ret | ||
1380 | 142 | except TryNext, exc: | 141 | except TryNext, exc: |
1381 | 143 | if exc.args or exc.kwargs: | 142 | if exc.args or exc.kwargs: |
1382 | 144 | args = exc.args | 143 | args = exc.args |
1383 | 145 | 144 | ||
1384 | === modified file 'IPython/core/ipapp.py' (properties changed: -x to +x) | |||
1385 | --- IPython/core/ipapp.py 2009-11-12 00:41:52 +0000 | |||
1386 | +++ IPython/core/ipapp.py 2010-01-18 01:17:11 +0000 | |||
1387 | @@ -4,17 +4,15 @@ | |||
1388 | 4 | The :class:`~IPython.core.application.Application` object for the command | 4 | The :class:`~IPython.core.application.Application` object for the command |
1389 | 5 | line :command:`ipython` program. | 5 | line :command:`ipython` program. |
1390 | 6 | 6 | ||
1392 | 7 | Authors: | 7 | Authors |
1393 | 8 | ------- | ||
1394 | 8 | 9 | ||
1395 | 9 | * Brian Granger | 10 | * Brian Granger |
1396 | 10 | * Fernando Perez | 11 | * Fernando Perez |
1397 | 11 | |||
1398 | 12 | Notes | ||
1399 | 13 | ----- | ||
1400 | 14 | """ | 12 | """ |
1401 | 15 | 13 | ||
1402 | 16 | #----------------------------------------------------------------------------- | 14 | #----------------------------------------------------------------------------- |
1404 | 17 | # Copyright (C) 2008-2009 The IPython Development Team | 15 | # Copyright (C) 2008-2010 The IPython Development Team |
1405 | 18 | # | 16 | # |
1406 | 19 | # Distributed under the terms of the BSD License. The full license is in | 17 | # Distributed under the terms of the BSD License. The full license is in |
1407 | 20 | # the file COPYING, distributed as part of this software. | 18 | # the file COPYING, distributed as part of this software. |
1408 | @@ -23,318 +21,405 @@ | |||
1409 | 23 | #----------------------------------------------------------------------------- | 21 | #----------------------------------------------------------------------------- |
1410 | 24 | # Imports | 22 | # Imports |
1411 | 25 | #----------------------------------------------------------------------------- | 23 | #----------------------------------------------------------------------------- |
1412 | 24 | from __future__ import absolute_import | ||
1413 | 26 | 25 | ||
1414 | 27 | import logging | 26 | import logging |
1415 | 28 | import os | 27 | import os |
1416 | 29 | import sys | 28 | import sys |
1417 | 30 | import warnings | ||
1418 | 31 | 29 | ||
1421 | 32 | from IPython.core.application import Application, BaseAppArgParseConfigLoader | 30 | from IPython.core import crashhandler |
1422 | 33 | from IPython.core import release | 31 | from IPython.core.application import Application |
1423 | 34 | from IPython.core.iplib import InteractiveShell | 32 | from IPython.core.iplib import InteractiveShell |
1424 | 35 | from IPython.config.loader import ( | 33 | from IPython.config.loader import ( |
1425 | 36 | NoConfigDefault, | ||
1426 | 37 | Config, | 34 | Config, |
1428 | 38 | PyFileConfigLoader | 35 | PyFileConfigLoader, |
1429 | 36 | # NoConfigDefault, | ||
1430 | 39 | ) | 37 | ) |
1431 | 40 | |||
1432 | 41 | from IPython.lib import inputhook | 38 | from IPython.lib import inputhook |
1433 | 42 | |||
1434 | 43 | from IPython.utils.genutils import filefind, get_ipython_dir | 39 | from IPython.utils.genutils import filefind, get_ipython_dir |
1471 | 44 | 40 | from . import usage | |
1472 | 45 | #----------------------------------------------------------------------------- | 41 | |
1473 | 46 | # Utilities and helpers | 42 | #----------------------------------------------------------------------------- |
1474 | 47 | #----------------------------------------------------------------------------- | 43 | # Globals, utilities and helpers |
1475 | 48 | 44 | #----------------------------------------------------------------------------- | |
1476 | 49 | 45 | ||
1477 | 50 | ipython_desc = """ | 46 | default_config_file_name = u'ipython_config.py' |
1442 | 51 | A Python shell with automatic history (input and output), dynamic object | ||
1443 | 52 | introspection, easier configuration, command completion, access to the system | ||
1444 | 53 | shell and more. | ||
1445 | 54 | """ | ||
1446 | 55 | |||
1447 | 56 | def pylab_warning(): | ||
1448 | 57 | msg = """ | ||
1449 | 58 | |||
1450 | 59 | IPython's -pylab mode has been disabled until matplotlib supports this version | ||
1451 | 60 | of IPython. This version of IPython has greatly improved GUI integration that | ||
1452 | 61 | matplotlib will soon be able to take advantage of. This will eventually | ||
1453 | 62 | result in greater stability and a richer API for matplotlib under IPython. | ||
1454 | 63 | However during this transition, you will either need to use an older version | ||
1455 | 64 | of IPython, or do the following to use matplotlib interactively:: | ||
1456 | 65 | |||
1457 | 66 | import matplotlib | ||
1458 | 67 | matplotlib.interactive(True) | ||
1459 | 68 | matplotlib.use('wxagg') # adjust for your backend | ||
1460 | 69 | %gui -a wx # adjust for your GUI | ||
1461 | 70 | from matplotlib import pyplot as plt | ||
1462 | 71 | |||
1463 | 72 | See the %gui magic for information on the new interface. | ||
1464 | 73 | """ | ||
1465 | 74 | warnings.warn(msg, category=DeprecationWarning, stacklevel=1) | ||
1466 | 75 | |||
1467 | 76 | |||
1468 | 77 | #----------------------------------------------------------------------------- | ||
1469 | 78 | # Main classes and functions | ||
1470 | 79 | #----------------------------------------------------------------------------- | ||
1478 | 80 | 47 | ||
1479 | 81 | cl_args = ( | 48 | cl_args = ( |
1480 | 82 | (('--autocall',), dict( | 49 | (('--autocall',), dict( |
1483 | 83 | type=int, dest='InteractiveShell.autocall', default=NoConfigDefault, | 50 | type=int, dest='InteractiveShell.autocall', |
1484 | 84 | help='Set the autocall value (0,1,2).', | 51 | help= |
1485 | 52 | """Make IPython automatically call any callable object even if you | ||
1486 | 53 | didn't type explicit parentheses. For example, 'str 43' becomes | ||
1487 | 54 | 'str(43)' automatically. The value can be '0' to disable the feature, | ||
1488 | 55 | '1' for 'smart' autocall, where it is not applied if there are no more | ||
1489 | 56 | arguments on the line, and '2' for 'full' autocall, where all callable | ||
1490 | 57 | objects are automatically called (even if no arguments are present). | ||
1491 | 58 | The default is '1'.""", | ||
1492 | 85 | metavar='InteractiveShell.autocall') | 59 | metavar='InteractiveShell.autocall') |
1493 | 86 | ), | 60 | ), |
1494 | 87 | (('--autoindent',), dict( | 61 | (('--autoindent',), dict( |
1496 | 88 | action='store_true', dest='InteractiveShell.autoindent', default=NoConfigDefault, | 62 | action='store_true', dest='InteractiveShell.autoindent', |
1497 | 89 | help='Turn on autoindenting.') | 63 | help='Turn on autoindenting.') |
1498 | 90 | ), | 64 | ), |
1499 | 91 | (('--no-autoindent',), dict( | 65 | (('--no-autoindent',), dict( |
1501 | 92 | action='store_false', dest='InteractiveShell.autoindent', default=NoConfigDefault, | 66 | action='store_false', dest='InteractiveShell.autoindent', |
1502 | 93 | help='Turn off autoindenting.') | 67 | help='Turn off autoindenting.') |
1503 | 94 | ), | 68 | ), |
1504 | 95 | (('--automagic',), dict( | 69 | (('--automagic',), dict( |
1508 | 96 | action='store_true', dest='InteractiveShell.automagic', default=NoConfigDefault, | 70 | action='store_true', dest='InteractiveShell.automagic', |
1509 | 97 | help='Turn on the auto calling of magic commands.') | 71 | help='Turn on the auto calling of magic commands.' |
1510 | 98 | ), | 72 | 'Type %%magic at the IPython prompt for more information.') |
1511 | 73 | ), | ||
1512 | 99 | (('--no-automagic',), dict( | 74 | (('--no-automagic',), dict( |
1514 | 100 | action='store_false', dest='InteractiveShell.automagic', default=NoConfigDefault, | 75 | action='store_false', dest='InteractiveShell.automagic', |
1515 | 101 | help='Turn off the auto calling of magic commands.') | 76 | help='Turn off the auto calling of magic commands.') |
1516 | 102 | ), | 77 | ), |
1517 | 103 | (('--autoedit-syntax',), dict( | 78 | (('--autoedit-syntax',), dict( |
1519 | 104 | action='store_true', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, | 79 | action='store_true', dest='InteractiveShell.autoedit_syntax', |
1520 | 105 | help='Turn on auto editing of files with syntax errors.') | 80 | help='Turn on auto editing of files with syntax errors.') |
1521 | 106 | ), | 81 | ), |
1522 | 107 | (('--no-autoedit-syntax',), dict( | 82 | (('--no-autoedit-syntax',), dict( |
1524 | 108 | action='store_false', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, | 83 | action='store_false', dest='InteractiveShell.autoedit_syntax', |
1525 | 109 | help='Turn off auto editing of files with syntax errors.') | 84 | help='Turn off auto editing of files with syntax errors.') |
1526 | 110 | ), | 85 | ), |
1527 | 111 | (('--banner',), dict( | 86 | (('--banner',), dict( |
1529 | 112 | action='store_true', dest='Global.display_banner', default=NoConfigDefault, | 87 | action='store_true', dest='Global.display_banner', |
1530 | 113 | help='Display a banner upon starting IPython.') | 88 | help='Display a banner upon starting IPython.') |
1531 | 114 | ), | 89 | ), |
1532 | 115 | (('--no-banner',), dict( | 90 | (('--no-banner',), dict( |
1534 | 116 | action='store_false', dest='Global.display_banner', default=NoConfigDefault, | 91 | action='store_false', dest='Global.display_banner', |
1535 | 117 | help="Don't display a banner upon starting IPython.") | 92 | help="Don't display a banner upon starting IPython.") |
1536 | 118 | ), | 93 | ), |
1537 | 119 | (('--cache-size',), dict( | 94 | (('--cache-size',), dict( |
1540 | 120 | type=int, dest='InteractiveShell.cache_size', default=NoConfigDefault, | 95 | type=int, dest='InteractiveShell.cache_size', |
1541 | 121 | help="Set the size of the output cache.", | 96 | help= |
1542 | 97 | """Set the size of the output cache. The default is 1000, you can | ||
1543 | 98 | change it permanently in your config file. Setting it to 0 completely | ||
1544 | 99 | disables the caching system, and the minimum value accepted is 20 (if | ||
1545 | 100 | you provide a value less than 20, it is reset to 0 and a warning is | ||
1546 | 101 | issued). This limit is defined because otherwise you'll spend more | ||
1547 | 102 | time re-flushing a too small cache than working. | ||
1548 | 103 | """, | ||
1549 | 122 | metavar='InteractiveShell.cache_size') | 104 | metavar='InteractiveShell.cache_size') |
1550 | 123 | ), | 105 | ), |
1551 | 124 | (('--classic',), dict( | 106 | (('--classic',), dict( |
1553 | 125 | action='store_true', dest='Global.classic', default=NoConfigDefault, | 107 | action='store_true', dest='Global.classic', |
1554 | 126 | help="Gives IPython a similar feel to the classic Python prompt.") | 108 | help="Gives IPython a similar feel to the classic Python prompt.") |
1555 | 127 | ), | 109 | ), |
1556 | 128 | (('--colors',), dict( | 110 | (('--colors',), dict( |
1558 | 129 | type=str, dest='InteractiveShell.colors', default=NoConfigDefault, | 111 | type=str, dest='InteractiveShell.colors', |
1559 | 130 | help="Set the color scheme (NoColor, Linux, and LightBG).", | 112 | help="Set the color scheme (NoColor, Linux, and LightBG).", |
1560 | 131 | metavar='InteractiveShell.colors') | 113 | metavar='InteractiveShell.colors') |
1561 | 132 | ), | 114 | ), |
1562 | 133 | (('--color-info',), dict( | 115 | (('--color-info',), dict( |
1565 | 134 | action='store_true', dest='InteractiveShell.color_info', default=NoConfigDefault, | 116 | action='store_true', dest='InteractiveShell.color_info', |
1566 | 135 | help="Enable using colors for info related things.") | 117 | help= |
1567 | 118 | """IPython can display information about objects via a set of func- | ||
1568 | 119 | tions, and optionally can use colors for this, syntax highlighting | ||
1569 | 120 | source code and various other elements. However, because this | ||
1570 | 121 | information is passed through a pager (like 'less') and many pagers get | ||
1571 | 122 | confused with color codes, this option is off by default. You can test | ||
1572 | 123 | it and turn it on permanently in your ipython_config.py file if it | ||
1573 | 124 | works for you. Test it and turn it on permanently if it works with | ||
1574 | 125 | your system. The magic function %%color_info allows you to toggle this | ||
1575 | 126 | inter- actively for testing.""" | ||
1576 | 127 | ) | ||
1577 | 136 | ), | 128 | ), |
1578 | 137 | (('--no-color-info',), dict( | 129 | (('--no-color-info',), dict( |
1580 | 138 | action='store_false', dest='InteractiveShell.color_info', default=NoConfigDefault, | 130 | action='store_false', dest='InteractiveShell.color_info', |
1581 | 139 | help="Disable using colors for info related things.") | 131 | help="Disable using colors for info related things.") |
1582 | 140 | ), | 132 | ), |
1583 | 141 | (('--confirm-exit',), dict( | 133 | (('--confirm-exit',), dict( |
1586 | 142 | action='store_true', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, | 134 | action='store_true', dest='InteractiveShell.confirm_exit', |
1587 | 143 | help="Prompt the user when existing.") | 135 | help= |
1588 | 136 | """Set to confirm when you try to exit IPython with an EOF (Control-D | ||
1589 | 137 | in Unix, Control-Z/Enter in Windows). By typing 'exit', 'quit' or | ||
1590 | 138 | '%%Exit', you can force a direct exit without any confirmation. | ||
1591 | 139 | """ | ||
1592 | 140 | ) | ||
1593 | 144 | ), | 141 | ), |
1594 | 145 | (('--no-confirm-exit',), dict( | 142 | (('--no-confirm-exit',), dict( |
1597 | 146 | action='store_false', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, | 143 | action='store_false', dest='InteractiveShell.confirm_exit', |
1598 | 147 | help="Don't prompt the user when existing.") | 144 | help="Don't prompt the user when exiting.") |
1599 | 148 | ), | 145 | ), |
1600 | 149 | (('--deep-reload',), dict( | 146 | (('--deep-reload',), dict( |
1603 | 150 | action='store_true', dest='InteractiveShell.deep_reload', default=NoConfigDefault, | 147 | action='store_true', dest='InteractiveShell.deep_reload', |
1604 | 151 | help="Enable deep (recursive) reloading by default.") | 148 | help= |
1605 | 149 | """Enable deep (recursive) reloading by default. IPython can use the | ||
1606 | 150 | deep_reload module which reloads changes in modules recursively (it | ||
1607 | 151 | replaces the reload() function, so you don't need to change anything to | ||
1608 | 152 | use it). deep_reload() forces a full reload of modules whose code may | ||
1609 | 153 | have changed, which the default reload() function does not. When | ||
1610 | 154 | deep_reload is off, IPython will use the normal reload(), but | ||
1611 | 155 | deep_reload will still be available as dreload(). This fea- ture is off | ||
1612 | 156 | by default [which means that you have both normal reload() and | ||
1613 | 157 | dreload()].""") | ||
1614 | 152 | ), | 158 | ), |
1615 | 153 | (('--no-deep-reload',), dict( | 159 | (('--no-deep-reload',), dict( |
1617 | 154 | action='store_false', dest='InteractiveShell.deep_reload', default=NoConfigDefault, | 160 | action='store_false', dest='InteractiveShell.deep_reload', |
1618 | 155 | help="Disable deep (recursive) reloading by default.") | 161 | help="Disable deep (recursive) reloading by default.") |
1619 | 156 | ), | 162 | ), |
1620 | 157 | (('--editor',), dict( | 163 | (('--editor',), dict( |
1622 | 158 | type=str, dest='InteractiveShell.editor', default=NoConfigDefault, | 164 | type=str, dest='InteractiveShell.editor', |
1623 | 159 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad).", | 165 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad).", |
1624 | 160 | metavar='InteractiveShell.editor') | 166 | metavar='InteractiveShell.editor') |
1625 | 161 | ), | 167 | ), |
1626 | 162 | (('--log','-l'), dict( | 168 | (('--log','-l'), dict( |
1629 | 163 | action='store_true', dest='InteractiveShell.logstart', default=NoConfigDefault, | 169 | action='store_true', dest='InteractiveShell.logstart', |
1630 | 164 | help="Start logging to the default file (./ipython_log.py).") | 170 | help="Start logging to the default log file (./ipython_log.py).") |
1631 | 165 | ), | 171 | ), |
1632 | 166 | (('--logfile','-lf'), dict( | 172 | (('--logfile','-lf'), dict( |
1635 | 167 | type=unicode, dest='InteractiveShell.logfile', default=NoConfigDefault, | 173 | type=unicode, dest='InteractiveShell.logfile', |
1636 | 168 | help="Start logging to logfile.", | 174 | help="Start logging to logfile with this name.", |
1637 | 169 | metavar='InteractiveShell.logfile') | 175 | metavar='InteractiveShell.logfile') |
1638 | 170 | ), | 176 | ), |
1639 | 171 | (('--log-append','-la'), dict( | 177 | (('--log-append','-la'), dict( |
1642 | 172 | type=unicode, dest='InteractiveShell.logappend', default=NoConfigDefault, | 178 | type=unicode, dest='InteractiveShell.logappend', |
1643 | 173 | help="Start logging to the give file in append mode.", | 179 | help="Start logging to the given file in append mode.", |
1644 | 174 | metavar='InteractiveShell.logfile') | 180 | metavar='InteractiveShell.logfile') |
1645 | 175 | ), | 181 | ), |
1646 | 176 | (('--pdb',), dict( | 182 | (('--pdb',), dict( |
1648 | 177 | action='store_true', dest='InteractiveShell.pdb', default=NoConfigDefault, | 183 | action='store_true', dest='InteractiveShell.pdb', |
1649 | 178 | help="Enable auto calling the pdb debugger after every exception.") | 184 | help="Enable auto calling the pdb debugger after every exception.") |
1650 | 179 | ), | 185 | ), |
1651 | 180 | (('--no-pdb',), dict( | 186 | (('--no-pdb',), dict( |
1653 | 181 | action='store_false', dest='InteractiveShell.pdb', default=NoConfigDefault, | 187 | action='store_false', dest='InteractiveShell.pdb', |
1654 | 182 | help="Disable auto calling the pdb debugger after every exception.") | 188 | help="Disable auto calling the pdb debugger after every exception.") |
1655 | 183 | ), | 189 | ), |
1656 | 184 | (('--pprint',), dict( | 190 | (('--pprint',), dict( |
1658 | 185 | action='store_true', dest='InteractiveShell.pprint', default=NoConfigDefault, | 191 | action='store_true', dest='InteractiveShell.pprint', |
1659 | 186 | help="Enable auto pretty printing of results.") | 192 | help="Enable auto pretty printing of results.") |
1660 | 187 | ), | 193 | ), |
1661 | 188 | (('--no-pprint',), dict( | 194 | (('--no-pprint',), dict( |
1663 | 189 | action='store_false', dest='InteractiveShell.pprint', default=NoConfigDefault, | 195 | action='store_false', dest='InteractiveShell.pprint', |
1664 | 190 | help="Disable auto auto pretty printing of results.") | 196 | help="Disable auto auto pretty printing of results.") |
1665 | 191 | ), | 197 | ), |
1666 | 192 | (('--prompt-in1','-pi1'), dict( | 198 | (('--prompt-in1','-pi1'), dict( |
1669 | 193 | type=str, dest='InteractiveShell.prompt_in1', default=NoConfigDefault, | 199 | type=str, dest='InteractiveShell.prompt_in1', |
1670 | 194 | help="Set the main input prompt ('In [\#]: ')", | 200 | help= |
1671 | 201 | """Set the main input prompt ('In [\#]: '). Note that if you are using | ||
1672 | 202 | numbered prompts, the number is represented with a '\#' in the string. | ||
1673 | 203 | Don't forget to quote strings with spaces embedded in them. Most | ||
1674 | 204 | bash-like escapes can be used to customize IPython's prompts, as well | ||
1675 | 205 | as a few additional ones which are IPython-spe- cific. All valid | ||
1676 | 206 | prompt escapes are described in detail in the Customization section of | ||
1677 | 207 | the IPython manual.""", | ||
1678 | 195 | metavar='InteractiveShell.prompt_in1') | 208 | metavar='InteractiveShell.prompt_in1') |
1679 | 196 | ), | 209 | ), |
1680 | 197 | (('--prompt-in2','-pi2'), dict( | 210 | (('--prompt-in2','-pi2'), dict( |
1683 | 198 | type=str, dest='InteractiveShell.prompt_in2', default=NoConfigDefault, | 211 | type=str, dest='InteractiveShell.prompt_in2', |
1684 | 199 | help="Set the secondary input prompt (' .\D.: ')", | 212 | help= |
1685 | 213 | """Set the secondary input prompt (' .\D.: '). Similar to the previous | ||
1686 | 214 | option, but used for the continuation prompts. The special sequence | ||
1687 | 215 | '\D' is similar to '\#', but with all digits replaced by dots (so you | ||
1688 | 216 | can have your continuation prompt aligned with your input prompt). | ||
1689 | 217 | Default: ' .\D.: ' (note three spaces at the start for alignment with | ||
1690 | 218 | 'In [\#]')""", | ||
1691 | 200 | metavar='InteractiveShell.prompt_in2') | 219 | metavar='InteractiveShell.prompt_in2') |
1692 | 201 | ), | 220 | ), |
1693 | 202 | (('--prompt-out','-po'), dict( | 221 | (('--prompt-out','-po'), dict( |
1695 | 203 | type=str, dest='InteractiveShell.prompt_out', default=NoConfigDefault, | 222 | type=str, dest='InteractiveShell.prompt_out', |
1696 | 204 | help="Set the output prompt ('Out[\#]:')", | 223 | help="Set the output prompt ('Out[\#]:')", |
1697 | 205 | metavar='InteractiveShell.prompt_out') | 224 | metavar='InteractiveShell.prompt_out') |
1698 | 206 | ), | 225 | ), |
1699 | 207 | (('--quick',), dict( | 226 | (('--quick',), dict( |
1701 | 208 | action='store_true', dest='Global.quick', default=NoConfigDefault, | 227 | action='store_true', dest='Global.quick', |
1702 | 209 | help="Enable quick startup with no config files.") | 228 | help="Enable quick startup with no config files.") |
1703 | 210 | ), | 229 | ), |
1704 | 211 | (('--readline',), dict( | 230 | (('--readline',), dict( |
1706 | 212 | action='store_true', dest='InteractiveShell.readline_use', default=NoConfigDefault, | 231 | action='store_true', dest='InteractiveShell.readline_use', |
1707 | 213 | help="Enable readline for command line usage.") | 232 | help="Enable readline for command line usage.") |
1708 | 214 | ), | 233 | ), |
1709 | 215 | (('--no-readline',), dict( | 234 | (('--no-readline',), dict( |
1711 | 216 | action='store_false', dest='InteractiveShell.readline_use', default=NoConfigDefault, | 235 | action='store_false', dest='InteractiveShell.readline_use', |
1712 | 217 | help="Disable readline for command line usage.") | 236 | help="Disable readline for command line usage.") |
1713 | 218 | ), | 237 | ), |
1714 | 219 | (('--screen-length','-sl'), dict( | 238 | (('--screen-length','-sl'), dict( |
1717 | 220 | type=int, dest='InteractiveShell.screen_length', default=NoConfigDefault, | 239 | type=int, dest='InteractiveShell.screen_length', |
1718 | 221 | help='Number of lines on screen, used to control printing of long strings.', | 240 | help= |
1719 | 241 | """Number of lines of your screen, used to control printing of very | ||
1720 | 242 | long strings. Strings longer than this number of lines will be sent | ||
1721 | 243 | through a pager instead of directly printed. The default value for | ||
1722 | 244 | this is 0, which means IPython will auto-detect your screen size every | ||
1723 | 245 | time it needs to print certain potentially long strings (this doesn't | ||
1724 | 246 | change the behavior of the 'print' keyword, it's only triggered | ||
1725 | 247 | internally). If for some reason this isn't working well (it needs | ||
1726 | 248 | curses support), specify it yourself. Otherwise don't change the | ||
1727 | 249 | default.""", | ||
1728 | 222 | metavar='InteractiveShell.screen_length') | 250 | metavar='InteractiveShell.screen_length') |
1729 | 223 | ), | 251 | ), |
1730 | 224 | (('--separate-in','-si'), dict( | 252 | (('--separate-in','-si'), dict( |
1733 | 225 | type=str, dest='InteractiveShell.separate_in', default=NoConfigDefault, | 253 | type=str, dest='InteractiveShell.separate_in', |
1734 | 226 | help="Separator before input prompts. Default '\n'.", | 254 | help="Separator before input prompts. Default '\\n'.", |
1735 | 227 | metavar='InteractiveShell.separate_in') | 255 | metavar='InteractiveShell.separate_in') |
1736 | 228 | ), | 256 | ), |
1737 | 229 | (('--separate-out','-so'), dict( | 257 | (('--separate-out','-so'), dict( |
1739 | 230 | type=str, dest='InteractiveShell.separate_out', default=NoConfigDefault, | 258 | type=str, dest='InteractiveShell.separate_out', |
1740 | 231 | help="Separator before output prompts. Default 0 (nothing).", | 259 | help="Separator before output prompts. Default 0 (nothing).", |
1741 | 232 | metavar='InteractiveShell.separate_out') | 260 | metavar='InteractiveShell.separate_out') |
1742 | 233 | ), | 261 | ), |
1743 | 234 | (('--separate-out2','-so2'), dict( | 262 | (('--separate-out2','-so2'), dict( |
1745 | 235 | type=str, dest='InteractiveShell.separate_out2', default=NoConfigDefault, | 263 | type=str, dest='InteractiveShell.separate_out2', |
1746 | 236 | help="Separator after output prompts. Default 0 (nonight).", | 264 | help="Separator after output prompts. Default 0 (nonight).", |
1747 | 237 | metavar='InteractiveShell.separate_out2') | 265 | metavar='InteractiveShell.separate_out2') |
1748 | 238 | ), | 266 | ), |
1749 | 239 | (('-no-sep',), dict( | 267 | (('-no-sep',), dict( |
1751 | 240 | action='store_true', dest='Global.nosep', default=NoConfigDefault, | 268 | action='store_true', dest='Global.nosep', |
1752 | 241 | help="Eliminate all spacing between prompts.") | 269 | help="Eliminate all spacing between prompts.") |
1753 | 242 | ), | 270 | ), |
1754 | 243 | (('--term-title',), dict( | 271 | (('--term-title',), dict( |
1756 | 244 | action='store_true', dest='InteractiveShell.term_title', default=NoConfigDefault, | 272 | action='store_true', dest='InteractiveShell.term_title', |
1757 | 245 | help="Enable auto setting the terminal title.") | 273 | help="Enable auto setting the terminal title.") |
1758 | 246 | ), | 274 | ), |
1759 | 247 | (('--no-term-title',), dict( | 275 | (('--no-term-title',), dict( |
1761 | 248 | action='store_false', dest='InteractiveShell.term_title', default=NoConfigDefault, | 276 | action='store_false', dest='InteractiveShell.term_title', |
1762 | 249 | help="Disable auto setting the terminal title.") | 277 | help="Disable auto setting the terminal title.") |
1763 | 250 | ), | 278 | ), |
1764 | 251 | (('--xmode',), dict( | 279 | (('--xmode',), dict( |
1767 | 252 | type=str, dest='InteractiveShell.xmode', default=NoConfigDefault, | 280 | type=str, dest='InteractiveShell.xmode', |
1768 | 253 | help="Exception mode ('Plain','Context','Verbose')", | 281 | help= |
1769 | 282 | """Exception reporting mode ('Plain','Context','Verbose'). Plain: | ||
1770 | 283 | similar to python's normal traceback printing. Context: prints 5 lines | ||
1771 | 284 | of context source code around each line in the traceback. Verbose: | ||
1772 | 285 | similar to Context, but additionally prints the variables currently | ||
1773 | 286 | visible where the exception happened (shortening their strings if too | ||
1774 | 287 | long). This can potentially be very slow, if you happen to have a huge | ||
1775 | 288 | data structure whose string representation is complex to compute. | ||
1776 | 289 | Your computer may appear to freeze for a while with cpu usage at 100%%. | ||
1777 | 290 | If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting | ||
1778 | 291 | it more than once). | ||
1779 | 292 | """, | ||
1780 | 254 | metavar='InteractiveShell.xmode') | 293 | metavar='InteractiveShell.xmode') |
1781 | 255 | ), | 294 | ), |
1782 | 256 | (('--ext',), dict( | 295 | (('--ext',), dict( |
1784 | 257 | type=str, dest='Global.extra_extension', default=NoConfigDefault, | 296 | type=str, dest='Global.extra_extension', |
1785 | 258 | help="The dotted module name of an IPython extension to load.", | 297 | help="The dotted module name of an IPython extension to load.", |
1786 | 259 | metavar='Global.extra_extension') | 298 | metavar='Global.extra_extension') |
1787 | 260 | ), | 299 | ), |
1788 | 261 | (('-c',), dict( | 300 | (('-c',), dict( |
1790 | 262 | type=str, dest='Global.code_to_run', default=NoConfigDefault, | 301 | type=str, dest='Global.code_to_run', |
1791 | 263 | help="Execute the given command string.", | 302 | help="Execute the given command string.", |
1792 | 264 | metavar='Global.code_to_run') | 303 | metavar='Global.code_to_run') |
1793 | 265 | ), | 304 | ), |
1794 | 266 | (('-i',), dict( | 305 | (('-i',), dict( |
1816 | 267 | action='store_true', dest='Global.force_interact', default=NoConfigDefault, | 306 | action='store_true', dest='Global.force_interact', |
1817 | 268 | help="If running code from the command line, become interactive afterwards.") | 307 | help= |
1818 | 269 | ), | 308 | "If running code from the command line, become interactive afterwards." |
1819 | 270 | (('--wthread',), dict( | 309 | ) |
1820 | 271 | action='store_true', dest='Global.wthread', default=NoConfigDefault, | 310 | ), |
1821 | 272 | help="Enable wxPython event loop integration.") | 311 | |
1822 | 273 | ), | 312 | # Options to start with GUI control enabled from the beginning |
1823 | 274 | (('--q4thread','--qthread'), dict( | 313 | (('--gui',), dict( |
1824 | 275 | action='store_true', dest='Global.q4thread', default=NoConfigDefault, | 314 | type=str, dest='Global.gui', |
1825 | 276 | help="Enable Qt4 event loop integration. Qt3 is no longer supported.") | 315 | help="Enable GUI event loop integration ('qt', 'wx', 'gtk').", |
1826 | 277 | ), | 316 | metavar='gui-mode') |
1827 | 278 | (('--gthread',), dict( | 317 | ), |
1828 | 279 | action='store_true', dest='Global.gthread', default=NoConfigDefault, | 318 | |
1829 | 280 | help="Enable GTK event loop integration.") | 319 | (('--pylab','-pylab'), dict( |
1830 | 281 | ), | 320 | type=str, dest='Global.pylab', |
1831 | 282 | # # These are only here to get the proper deprecation warnings | 321 | nargs='?', const='auto', metavar='gui-mode', |
1832 | 283 | (('--pylab',), dict( | 322 | help="Pre-load matplotlib and numpy for interactive use. "+ |
1833 | 284 | action='store_true', dest='Global.pylab', default=NoConfigDefault, | 323 | "If no value is given, the gui backend is matplotlib's, else use "+ |
1834 | 285 | help="Disabled. Pylab has been disabled until matplotlib " | 324 | "one of: ['tk', 'qt', 'wx', 'gtk'].") |
1835 | 286 | "supports this version of IPython.") | 325 | ), |
1836 | 287 | ) | 326 | |
1837 | 327 | # Legacy GUI options. Leave them in for backwards compatibility, but the | ||
1838 | 328 | # 'thread' names are really a misnomer now. | ||
1839 | 329 | (('--wthread','-wthread'), dict( | ||
1840 | 330 | action='store_true', dest='Global.wthread', | ||
1841 | 331 | help="Enable wxPython event loop integration "+ | ||
1842 | 332 | "(DEPRECATED, use --gui wx)") | ||
1843 | 333 | ), | ||
1844 | 334 | (('--q4thread','--qthread','-q4thread','-qthread'), dict( | ||
1845 | 335 | action='store_true', dest='Global.q4thread', | ||
1846 | 336 | help="Enable Qt4 event loop integration. Qt3 is no longer supported. "+ | ||
1847 | 337 | "(DEPRECATED, use --gui qt)") | ||
1848 | 338 | ), | ||
1849 | 339 | (('--gthread','-gthread'), dict( | ||
1850 | 340 | action='store_true', dest='Global.gthread', | ||
1851 | 341 | help="Enable GTK event loop integration. "+ | ||
1852 | 342 | "(DEPRECATED, use --gui gtk)") | ||
1853 | 343 | ), | ||
1854 | 288 | ) | 344 | ) |
1855 | 289 | 345 | ||
1864 | 290 | 346 | #----------------------------------------------------------------------------- | |
1865 | 291 | class IPythonAppCLConfigLoader(BaseAppArgParseConfigLoader): | 347 | # Main classes and functions |
1866 | 292 | 348 | #----------------------------------------------------------------------------- | |
1859 | 293 | arguments = cl_args | ||
1860 | 294 | |||
1861 | 295 | |||
1862 | 296 | default_config_file_name = u'ipython_config.py' | ||
1863 | 297 | |||
1867 | 298 | 349 | ||
1868 | 299 | class IPythonApp(Application): | 350 | class IPythonApp(Application): |
1869 | 300 | name = u'ipython' | 351 | name = u'ipython' |
1871 | 301 | description = 'IPython: an enhanced interactive Python shell.' | 352 | #: argparse formats better the 'usage' than the 'description' field |
1872 | 353 | description = None | ||
1873 | 354 | #: usage message printed by argparse. If None, auto-generate | ||
1874 | 355 | usage = usage.cl_usage | ||
1875 | 356 | |||
1876 | 302 | config_file_name = default_config_file_name | 357 | config_file_name = default_config_file_name |
1877 | 303 | 358 | ||
1878 | 359 | cl_arguments = Application.cl_arguments + cl_args | ||
1879 | 360 | |||
1880 | 361 | # Private and configuration attributes | ||
1881 | 362 | _CrashHandler = crashhandler.IPythonCrashHandler | ||
1882 | 363 | |||
1883 | 364 | def __init__(self, argv=None, | ||
1884 | 365 | constructor_config=None, override_config=None, | ||
1885 | 366 | **shell_params): | ||
1886 | 367 | """Create a new IPythonApp. | ||
1887 | 368 | |||
1888 | 369 | See the parent class for details on how configuration is handled. | ||
1889 | 370 | |||
1890 | 371 | Parameters | ||
1891 | 372 | ---------- | ||
1892 | 373 | argv : optional, list | ||
1893 | 374 | If given, used as the command-line argv environment to read arguments | ||
1894 | 375 | from. | ||
1895 | 376 | |||
1896 | 377 | constructor_config : optional, Config | ||
1897 | 378 | If given, additional config that is merged last, after internal | ||
1898 | 379 | defaults, command-line and file-based configs. | ||
1899 | 380 | |||
1900 | 381 | override_config : optional, Config | ||
1901 | 382 | If given, config that overrides all others unconditionally (except | ||
1902 | 383 | for internal defaults, which ensure that all parameters exist). | ||
1903 | 384 | |||
1904 | 385 | shell_params : optional, dict | ||
1905 | 386 | All other keywords are passed to the :class:`iplib.InteractiveShell` | ||
1906 | 387 | constructor. | ||
1907 | 388 | """ | ||
1908 | 389 | super(IPythonApp, self).__init__(argv, constructor_config, | ||
1909 | 390 | override_config) | ||
1910 | 391 | self.shell_params = shell_params | ||
1911 | 392 | |||
1912 | 304 | def create_default_config(self): | 393 | def create_default_config(self): |
1913 | 305 | super(IPythonApp, self).create_default_config() | 394 | super(IPythonApp, self).create_default_config() |
1915 | 306 | self.default_config.Global.display_banner = True | 395 | # Eliminate multiple lookups |
1916 | 396 | Global = self.default_config.Global | ||
1917 | 397 | |||
1918 | 398 | # Set all default values | ||
1919 | 399 | Global.display_banner = True | ||
1920 | 307 | 400 | ||
1921 | 308 | # If the -c flag is given or a file is given to run at the cmd line | 401 | # If the -c flag is given or a file is given to run at the cmd line |
1922 | 309 | # like "ipython foo.py", normally we exit without starting the main | 402 | # like "ipython foo.py", normally we exit without starting the main |
1923 | 310 | # loop. The force_interact config variable allows a user to override | 403 | # loop. The force_interact config variable allows a user to override |
1924 | 311 | # this and interact. It is also set by the -i cmd line flag, just | 404 | # this and interact. It is also set by the -i cmd line flag, just |
1925 | 312 | # like Python. | 405 | # like Python. |
1927 | 313 | self.default_config.Global.force_interact = False | 406 | Global.force_interact = False |
1928 | 314 | 407 | ||
1929 | 315 | # By default always interact by starting the IPython mainloop. | 408 | # By default always interact by starting the IPython mainloop. |
1931 | 316 | self.default_config.Global.interact = True | 409 | Global.interact = True |
1932 | 317 | 410 | ||
1933 | 318 | # No GUI integration by default | 411 | # No GUI integration by default |
1953 | 319 | self.default_config.Global.wthread = False | 412 | Global.gui = False |
1954 | 320 | self.default_config.Global.q4thread = False | 413 | # Pylab off by default |
1955 | 321 | self.default_config.Global.gthread = False | 414 | Global.pylab = False |
1956 | 322 | 415 | ||
1957 | 323 | def create_command_line_config(self): | 416 | # Deprecated versions of gui support that used threading, we support |
1958 | 324 | """Create and return a command line config loader.""" | 417 | # them just for bacwards compatibility as an alternate spelling for |
1959 | 325 | return IPythonAppCLConfigLoader( | 418 | # '--gui X' |
1960 | 326 | description=self.description, | 419 | Global.qthread = False |
1961 | 327 | version=release.version | 420 | Global.q4thread = False |
1962 | 328 | ) | 421 | Global.wthread = False |
1963 | 329 | 422 | Global.gthread = False | |
1945 | 330 | def post_load_command_line_config(self): | ||
1946 | 331 | """Do actions after loading cl config.""" | ||
1947 | 332 | clc = self.command_line_config | ||
1948 | 333 | |||
1949 | 334 | # Display the deprecation warnings about threaded shells | ||
1950 | 335 | if hasattr(clc.Global, 'pylab'): | ||
1951 | 336 | pylab_warning() | ||
1952 | 337 | del clc.Global['pylab'] | ||
1964 | 338 | 423 | ||
1965 | 339 | def load_file_config(self): | 424 | def load_file_config(self): |
1966 | 340 | if hasattr(self.command_line_config.Global, 'quick'): | 425 | if hasattr(self.command_line_config.Global, 'quick'): |
1967 | @@ -377,8 +462,7 @@ | |||
1968 | 377 | # unless the -i flag (Global.force_interact) is true. | 462 | # unless the -i flag (Global.force_interact) is true. |
1969 | 378 | code_to_run = config.Global.get('code_to_run','') | 463 | code_to_run = config.Global.get('code_to_run','') |
1970 | 379 | file_to_run = False | 464 | file_to_run = False |
1973 | 380 | if len(self.extra_args)>=1: | 465 | if self.extra_args and self.extra_args[0]: |
1972 | 381 | if self.extra_args[0]: | ||
1974 | 382 | file_to_run = True | 466 | file_to_run = True |
1975 | 383 | if file_to_run or code_to_run: | 467 | if file_to_run or code_to_run: |
1976 | 384 | if not config.Global.force_interact: | 468 | if not config.Global.force_interact: |
1977 | @@ -390,10 +474,8 @@ | |||
1978 | 390 | sys.path.insert(0, '') | 474 | sys.path.insert(0, '') |
1979 | 391 | 475 | ||
1980 | 392 | # Create an InteractiveShell instance | 476 | # Create an InteractiveShell instance |
1985 | 393 | self.shell = InteractiveShell( | 477 | self.shell = InteractiveShell(None, self.master_config, |
1986 | 394 | parent=None, | 478 | **self.shell_params ) |
1983 | 395 | config=self.master_config | ||
1984 | 396 | ) | ||
1987 | 397 | 479 | ||
1988 | 398 | def post_construct(self): | 480 | def post_construct(self): |
1989 | 399 | """Do actions after construct, but before starting the app.""" | 481 | """Do actions after construct, but before starting the app.""" |
1990 | @@ -412,29 +494,52 @@ | |||
1991 | 412 | if self.log_level <= logging.INFO: print | 494 | if self.log_level <= logging.INFO: print |
1992 | 413 | 495 | ||
1993 | 414 | # Now a variety of things that happen after the banner is printed. | 496 | # Now a variety of things that happen after the banner is printed. |
1995 | 415 | self._enable_gui() | 497 | self._enable_gui_pylab() |
1996 | 416 | self._load_extensions() | 498 | self._load_extensions() |
1997 | 417 | self._run_exec_lines() | 499 | self._run_exec_lines() |
1998 | 418 | self._run_exec_files() | 500 | self._run_exec_files() |
1999 | 419 | self._run_cmd_line_code() | 501 | self._run_cmd_line_code() |
2018 | 420 | 502 | self._configure_xmode() | |
2019 | 421 | def _enable_gui(self): | 503 | |
2020 | 422 | """Enable GUI event loop integration.""" | 504 | def _enable_gui_pylab(self): |
2021 | 423 | config = self.master_config | 505 | """Enable GUI event loop integration, taking pylab into account.""" |
2022 | 424 | try: | 506 | Global = self.master_config.Global |
2023 | 425 | # Enable GUI integration | 507 | |
2024 | 426 | if config.Global.wthread: | 508 | # Select which gui to use |
2025 | 427 | self.log.info("Enabling wx GUI event loop integration") | 509 | if Global.gui: |
2026 | 428 | inputhook.enable_wx(app=True) | 510 | gui = Global.gui |
2027 | 429 | elif config.Global.q4thread: | 511 | # The following are deprecated, but there's likely to be a lot of use |
2028 | 430 | self.log.info("Enabling Qt4 GUI event loop integration") | 512 | # of this form out there, so we might as well support it for now. But |
2029 | 431 | inputhook.enable_qt4(app=True) | 513 | # the --gui option above takes precedence. |
2030 | 432 | elif config.Global.gthread: | 514 | elif Global.wthread: |
2031 | 433 | self.log.info("Enabling GTK GUI event loop integration") | 515 | gui = inputhook.GUI_WX |
2032 | 434 | inputhook.enable_gtk(app=True) | 516 | elif Global.qthread: |
2033 | 435 | except: | 517 | gui = inputhook.GUI_QT |
2034 | 436 | self.log.warn("Error in enabling GUI event loop integration:") | 518 | elif Global.gthread: |
2035 | 437 | self.shell.showtraceback() | 519 | gui = inputhook.GUI_GTK |
2036 | 520 | else: | ||
2037 | 521 | gui = None | ||
2038 | 522 | |||
2039 | 523 | # Using --pylab will also require gui activation, though which toolkit | ||
2040 | 524 | # to use may be chosen automatically based on mpl configuration. | ||
2041 | 525 | if Global.pylab: | ||
2042 | 526 | activate = self.shell.enable_pylab | ||
2043 | 527 | if Global.pylab == 'auto': | ||
2044 | 528 | gui = None | ||
2045 | 529 | else: | ||
2046 | 530 | gui = Global.pylab | ||
2047 | 531 | else: | ||
2048 | 532 | # Enable only GUI integration, no pylab | ||
2049 | 533 | activate = inputhook.enable_gui | ||
2050 | 534 | |||
2051 | 535 | if gui or Global.pylab: | ||
2052 | 536 | try: | ||
2053 | 537 | self.log.info("Enabling GUI event loop integration, " | ||
2054 | 538 | "toolkit=%s, pylab=%s" % (gui, Global.pylab) ) | ||
2055 | 539 | activate(gui) | ||
2056 | 540 | except: | ||
2057 | 541 | self.log.warn("Error in enabling GUI event loop integration:") | ||
2058 | 542 | self.shell.showtraceback() | ||
2059 | 438 | 543 | ||
2060 | 439 | def _load_extensions(self): | 544 | def _load_extensions(self): |
2061 | 440 | """Load all IPython extensions in Global.extensions. | 545 | """Load all IPython extensions in Global.extensions. |
2062 | @@ -519,10 +624,17 @@ | |||
2063 | 519 | self.log.warn("Error in executing file in user namespace: %s" % fname) | 624 | self.log.warn("Error in executing file in user namespace: %s" % fname) |
2064 | 520 | self.shell.showtraceback() | 625 | self.shell.showtraceback() |
2065 | 521 | 626 | ||
2066 | 627 | def _configure_xmode(self): | ||
2067 | 628 | # XXX - shouldn't this be read from the config? I'm still a little | ||
2068 | 629 | # lost with all the details of handling the new config guys... | ||
2069 | 630 | self.shell.InteractiveTB.set_mode(mode=self.shell.xmode) | ||
2070 | 631 | |||
2071 | 522 | def start_app(self): | 632 | def start_app(self): |
2072 | 523 | if self.master_config.Global.interact: | 633 | if self.master_config.Global.interact: |
2073 | 524 | self.log.debug("Starting IPython's mainloop...") | 634 | self.log.debug("Starting IPython's mainloop...") |
2074 | 525 | self.shell.mainloop() | 635 | self.shell.mainloop() |
2075 | 636 | else: | ||
2076 | 637 | self.log.debug("IPython not interactive, start_app is no-op...") | ||
2077 | 526 | 638 | ||
2078 | 527 | 639 | ||
2079 | 528 | def load_default_config(ipython_dir=None): | 640 | def load_default_config(ipython_dir=None): |
2080 | @@ -541,4 +653,3 @@ | |||
2081 | 541 | """Create and run a full blown IPython instance""" | 653 | """Create and run a full blown IPython instance""" |
2082 | 542 | app = IPythonApp() | 654 | app = IPythonApp() |
2083 | 543 | app.start() | 655 | app.start() |
2084 | 544 | |||
2085 | 545 | 656 | ||
2086 | === modified file 'IPython/core/iplib.py' | |||
2087 | --- IPython/core/iplib.py 2009-11-09 01:49:24 +0000 | |||
2088 | +++ IPython/core/iplib.py 2010-01-18 01:17:11 +0000 | |||
2089 | @@ -17,6 +17,7 @@ | |||
2090 | 17 | #----------------------------------------------------------------------------- | 17 | #----------------------------------------------------------------------------- |
2091 | 18 | 18 | ||
2092 | 19 | from __future__ import with_statement | 19 | from __future__ import with_statement |
2093 | 20 | from __future__ import absolute_import | ||
2094 | 20 | 21 | ||
2095 | 21 | import __builtin__ | 22 | import __builtin__ |
2096 | 22 | import StringIO | 23 | import StringIO |
2097 | @@ -31,34 +32,37 @@ | |||
2098 | 31 | import tempfile | 32 | import tempfile |
2099 | 32 | from contextlib import nested | 33 | from contextlib import nested |
2100 | 33 | 34 | ||
2101 | 34 | from IPython.core import ultratb | ||
2102 | 35 | from IPython.core import debugger, oinspect | 35 | from IPython.core import debugger, oinspect |
2103 | 36 | from IPython.core import shadowns | ||
2104 | 37 | from IPython.core import history as ipcorehist | 36 | from IPython.core import history as ipcorehist |
2105 | 38 | from IPython.core import prefilter | 37 | from IPython.core import prefilter |
2106 | 38 | from IPython.core import shadowns | ||
2107 | 39 | from IPython.core import ultratb | ||
2108 | 39 | from IPython.core.alias import AliasManager | 40 | from IPython.core.alias import AliasManager |
2109 | 40 | from IPython.core.builtin_trap import BuiltinTrap | 41 | from IPython.core.builtin_trap import BuiltinTrap |
2110 | 42 | from IPython.core.component import Component | ||
2111 | 41 | from IPython.core.display_trap import DisplayTrap | 43 | from IPython.core.display_trap import DisplayTrap |
2112 | 44 | from IPython.core.error import TryNext, UsageError | ||
2113 | 42 | from IPython.core.fakemodule import FakeModule, init_fakemod_dict | 45 | from IPython.core.fakemodule import FakeModule, init_fakemod_dict |
2114 | 43 | from IPython.core.logger import Logger | 46 | from IPython.core.logger import Logger |
2115 | 44 | from IPython.core.magic import Magic | 47 | from IPython.core.magic import Magic |
2116 | 48 | from IPython.core.prefilter import PrefilterManager | ||
2117 | 45 | from IPython.core.prompts import CachedOutput | 49 | from IPython.core.prompts import CachedOutput |
2120 | 46 | from IPython.core.prefilter import PrefilterManager | 50 | from IPython.core.pylabtools import pylab_activate |
2119 | 47 | from IPython.core.component import Component | ||
2121 | 48 | from IPython.core.usage import interactive_usage, default_banner | 51 | from IPython.core.usage import interactive_usage, default_banner |
2122 | 49 | from IPython.core.error import TryNext, UsageError | ||
2123 | 50 | |||
2124 | 51 | from IPython.utils import pickleshare | ||
2125 | 52 | from IPython.external.Itpl import ItplNS | 52 | from IPython.external.Itpl import ItplNS |
2126 | 53 | from IPython.lib.inputhook import enable_gui | ||
2127 | 53 | from IPython.lib.backgroundjobs import BackgroundJobManager | 54 | from IPython.lib.backgroundjobs import BackgroundJobManager |
2128 | 54 | from IPython.utils.ipstruct import Struct | ||
2129 | 55 | from IPython.utils import PyColorize | 55 | from IPython.utils import PyColorize |
2131 | 56 | from IPython.utils.genutils import * | 56 | from IPython.utils import pickleshare |
2132 | 57 | from IPython.utils.genutils import get_ipython_dir | 57 | from IPython.utils.genutils import get_ipython_dir |
2133 | 58 | from IPython.utils.ipstruct import Struct | ||
2134 | 58 | from IPython.utils.platutils import toggle_set_term_title, set_term_title | 59 | from IPython.utils.platutils import toggle_set_term_title, set_term_title |
2135 | 59 | from IPython.utils.strdispatch import StrDispatch | 60 | from IPython.utils.strdispatch import StrDispatch |
2136 | 60 | from IPython.utils.syspathcontext import prepended_to_syspath | 61 | from IPython.utils.syspathcontext import prepended_to_syspath |
2137 | 61 | 62 | ||
2138 | 63 | # XXX - need to clean up this import * line | ||
2139 | 64 | from IPython.utils.genutils import * | ||
2140 | 65 | |||
2141 | 62 | # from IPython.utils import growl | 66 | # from IPython.utils import growl |
2142 | 63 | # growl.start("IPython") | 67 | # growl.start("IPython") |
2143 | 64 | 68 | ||
2144 | @@ -70,7 +74,6 @@ | |||
2145 | 70 | # Globals | 74 | # Globals |
2146 | 71 | #----------------------------------------------------------------------------- | 75 | #----------------------------------------------------------------------------- |
2147 | 72 | 76 | ||
2148 | 73 | |||
2149 | 74 | # store the builtin raw_input globally, and use this always, in case user code | 77 | # store the builtin raw_input globally, and use this always, in case user code |
2150 | 75 | # overwrites it (like wx.py.PyShell does) | 78 | # overwrites it (like wx.py.PyShell does) |
2151 | 76 | raw_input_original = raw_input | 79 | raw_input_original = raw_input |
2152 | @@ -78,12 +81,10 @@ | |||
2153 | 78 | # compiled regexps for autoindent management | 81 | # compiled regexps for autoindent management |
2154 | 79 | dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') | 82 | dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') |
2155 | 80 | 83 | ||
2156 | 81 | |||
2157 | 82 | #----------------------------------------------------------------------------- | 84 | #----------------------------------------------------------------------------- |
2158 | 83 | # Utilities | 85 | # Utilities |
2159 | 84 | #----------------------------------------------------------------------------- | 86 | #----------------------------------------------------------------------------- |
2160 | 85 | 87 | ||
2161 | 86 | |||
2162 | 87 | ini_spaces_re = re.compile(r'^(\s+)') | 88 | ini_spaces_re = re.compile(r'^(\s+)') |
2163 | 88 | 89 | ||
2164 | 89 | 90 | ||
2165 | @@ -113,6 +114,8 @@ | |||
2166 | 113 | return oldvalue | 114 | return oldvalue |
2167 | 114 | 115 | ||
2168 | 115 | 116 | ||
2169 | 117 | def no_op(*a, **kw): pass | ||
2170 | 118 | |||
2171 | 116 | class SpaceInInput(exceptions.Exception): pass | 119 | class SpaceInInput(exceptions.Exception): pass |
2172 | 117 | 120 | ||
2173 | 118 | class Bunch: pass | 121 | class Bunch: pass |
2174 | @@ -183,6 +186,64 @@ | |||
2175 | 183 | return super(SeparateStr, self).validate(obj, value) | 186 | return super(SeparateStr, self).validate(obj, value) |
2176 | 184 | 187 | ||
2177 | 185 | 188 | ||
2178 | 189 | def make_user_namespaces(user_ns=None, user_global_ns=None): | ||
2179 | 190 | """Return a valid local and global user interactive namespaces. | ||
2180 | 191 | |||
2181 | 192 | This builds a dict with the minimal information needed to operate as a | ||
2182 | 193 | valid IPython user namespace, which you can pass to the various | ||
2183 | 194 | embedding classes in ipython. The default implementation returns the | ||
2184 | 195 | same dict for both the locals and the globals to allow functions to | ||
2185 | 196 | refer to variables in the namespace. Customized implementations can | ||
2186 | 197 | return different dicts. The locals dictionary can actually be anything | ||
2187 | 198 | following the basic mapping protocol of a dict, but the globals dict | ||
2188 | 199 | must be a true dict, not even a subclass. It is recommended that any | ||
2189 | 200 | custom object for the locals namespace synchronize with the globals | ||
2190 | 201 | dict somehow. | ||
2191 | 202 | |||
2192 | 203 | Raises TypeError if the provided globals namespace is not a true dict. | ||
2193 | 204 | |||
2194 | 205 | Parameters | ||
2195 | 206 | ---------- | ||
2196 | 207 | user_ns : dict-like, optional | ||
2197 | 208 | The current user namespace. The items in this namespace should | ||
2198 | 209 | be included in the output. If None, an appropriate blank | ||
2199 | 210 | namespace should be created. | ||
2200 | 211 | user_global_ns : dict, optional | ||
2201 | 212 | The current user global namespace. The items in this namespace | ||
2202 | 213 | should be included in the output. If None, an appropriate | ||
2203 | 214 | blank namespace should be created. | ||
2204 | 215 | |||
2205 | 216 | Returns | ||
2206 | 217 | ------- | ||
2207 | 218 | A pair of dictionary-like object to be used as the local namespace | ||
2208 | 219 | of the interpreter and a dict to be used as the global namespace. | ||
2209 | 220 | """ | ||
2210 | 221 | |||
2211 | 222 | |||
2212 | 223 | # We must ensure that __builtin__ (without the final 's') is always | ||
2213 | 224 | # available and pointing to the __builtin__ *module*. For more details: | ||
2214 | 225 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html | ||
2215 | 226 | |||
2216 | 227 | if user_ns is None: | ||
2217 | 228 | # Set __name__ to __main__ to better match the behavior of the | ||
2218 | 229 | # normal interpreter. | ||
2219 | 230 | user_ns = {'__name__' :'__main__', | ||
2220 | 231 | '__builtin__' : __builtin__, | ||
2221 | 232 | '__builtins__' : __builtin__, | ||
2222 | 233 | } | ||
2223 | 234 | else: | ||
2224 | 235 | user_ns.setdefault('__name__','__main__') | ||
2225 | 236 | user_ns.setdefault('__builtin__',__builtin__) | ||
2226 | 237 | user_ns.setdefault('__builtins__',__builtin__) | ||
2227 | 238 | |||
2228 | 239 | if user_global_ns is None: | ||
2229 | 240 | user_global_ns = user_ns | ||
2230 | 241 | if type(user_global_ns) is not dict: | ||
2231 | 242 | raise TypeError("user_global_ns must be a true dict; got %r" | ||
2232 | 243 | % type(user_global_ns)) | ||
2233 | 244 | |||
2234 | 245 | return user_ns, user_global_ns | ||
2235 | 246 | |||
2236 | 186 | #----------------------------------------------------------------------------- | 247 | #----------------------------------------------------------------------------- |
2237 | 187 | # Main IPython class | 248 | # Main IPython class |
2238 | 188 | #----------------------------------------------------------------------------- | 249 | #----------------------------------------------------------------------------- |
2239 | @@ -329,6 +390,7 @@ | |||
2240 | 329 | self.hooks.late_startup_hook() | 390 | self.hooks.late_startup_hook() |
2241 | 330 | 391 | ||
2242 | 331 | def get_ipython(self): | 392 | def get_ipython(self): |
2243 | 393 | """Return the currently running IPython instance.""" | ||
2244 | 332 | return self | 394 | return self |
2245 | 333 | 395 | ||
2246 | 334 | #------------------------------------------------------------------------- | 396 | #------------------------------------------------------------------------- |
2247 | @@ -814,8 +876,7 @@ | |||
2248 | 814 | # These routines return properly built dicts as needed by the rest of | 876 | # These routines return properly built dicts as needed by the rest of |
2249 | 815 | # the code, and can also be used by extension writers to generate | 877 | # the code, and can also be used by extension writers to generate |
2250 | 816 | # properly initialized namespaces. | 878 | # properly initialized namespaces. |
2253 | 817 | user_ns, user_global_ns = self.make_user_namespaces(user_ns, | 879 | user_ns, user_global_ns = make_user_namespaces(user_ns, user_global_ns) |
2252 | 818 | user_global_ns) | ||
2254 | 819 | 880 | ||
2255 | 820 | # Assign namespaces | 881 | # Assign namespaces |
2256 | 821 | # This is the namespace where all normal user variables live | 882 | # This is the namespace where all normal user variables live |
2257 | @@ -825,7 +886,7 @@ | |||
2258 | 825 | # An auxiliary namespace that checks what parts of the user_ns were | 886 | # An auxiliary namespace that checks what parts of the user_ns were |
2259 | 826 | # loaded at startup, so we can list later only variables defined in | 887 | # loaded at startup, so we can list later only variables defined in |
2260 | 827 | # actual interactive use. Since it is always a subset of user_ns, it | 888 | # actual interactive use. Since it is always a subset of user_ns, it |
2262 | 828 | # doesn't need to be seaparately tracked in the ns_table | 889 | # doesn't need to be separately tracked in the ns_table. |
2263 | 829 | self.user_config_ns = {} | 890 | self.user_config_ns = {} |
2264 | 830 | 891 | ||
2265 | 831 | # A namespace to keep track of internal data structures to prevent | 892 | # A namespace to keep track of internal data structures to prevent |
2266 | @@ -900,55 +961,6 @@ | |||
2267 | 900 | else: | 961 | else: |
2268 | 901 | sys.modules[main_name] = FakeModule(self.user_ns) | 962 | sys.modules[main_name] = FakeModule(self.user_ns) |
2269 | 902 | 963 | ||
2270 | 903 | def make_user_namespaces(self, user_ns=None, user_global_ns=None): | ||
2271 | 904 | """Return a valid local and global user interactive namespaces. | ||
2272 | 905 | |||
2273 | 906 | This builds a dict with the minimal information needed to operate as a | ||
2274 | 907 | valid IPython user namespace, which you can pass to the various | ||
2275 | 908 | embedding classes in ipython. The default implementation returns the | ||
2276 | 909 | same dict for both the locals and the globals to allow functions to | ||
2277 | 910 | refer to variables in the namespace. Customized implementations can | ||
2278 | 911 | return different dicts. The locals dictionary can actually be anything | ||
2279 | 912 | following the basic mapping protocol of a dict, but the globals dict | ||
2280 | 913 | must be a true dict, not even a subclass. It is recommended that any | ||
2281 | 914 | custom object for the locals namespace synchronize with the globals | ||
2282 | 915 | dict somehow. | ||
2283 | 916 | |||
2284 | 917 | Raises TypeError if the provided globals namespace is not a true dict. | ||
2285 | 918 | |||
2286 | 919 | :Parameters: | ||
2287 | 920 | user_ns : dict-like, optional | ||
2288 | 921 | The current user namespace. The items in this namespace should | ||
2289 | 922 | be included in the output. If None, an appropriate blank | ||
2290 | 923 | namespace should be created. | ||
2291 | 924 | user_global_ns : dict, optional | ||
2292 | 925 | The current user global namespace. The items in this namespace | ||
2293 | 926 | should be included in the output. If None, an appropriate | ||
2294 | 927 | blank namespace should be created. | ||
2295 | 928 | |||
2296 | 929 | :Returns: | ||
2297 | 930 | A tuple pair of dictionary-like object to be used as the local namespace | ||
2298 | 931 | of the interpreter and a dict to be used as the global namespace. | ||
2299 | 932 | """ | ||
2300 | 933 | |||
2301 | 934 | if user_ns is None: | ||
2302 | 935 | # Set __name__ to __main__ to better match the behavior of the | ||
2303 | 936 | # normal interpreter. | ||
2304 | 937 | user_ns = {'__name__' :'__main__', | ||
2305 | 938 | '__builtins__' : __builtin__, | ||
2306 | 939 | } | ||
2307 | 940 | else: | ||
2308 | 941 | user_ns.setdefault('__name__','__main__') | ||
2309 | 942 | user_ns.setdefault('__builtins__',__builtin__) | ||
2310 | 943 | |||
2311 | 944 | if user_global_ns is None: | ||
2312 | 945 | user_global_ns = user_ns | ||
2313 | 946 | if type(user_global_ns) is not dict: | ||
2314 | 947 | raise TypeError("user_global_ns must be a true dict; got %r" | ||
2315 | 948 | % type(user_global_ns)) | ||
2316 | 949 | |||
2317 | 950 | return user_ns, user_global_ns | ||
2318 | 951 | |||
2319 | 952 | def init_user_ns(self): | 964 | def init_user_ns(self): |
2320 | 953 | """Initialize all user-visible namespaces to their minimum defaults. | 965 | """Initialize all user-visible namespaces to their minimum defaults. |
2321 | 954 | 966 | ||
2322 | @@ -961,27 +973,59 @@ | |||
2323 | 961 | method. If they were not empty before, data will simply be added to | 973 | method. If they were not empty before, data will simply be added to |
2324 | 962 | therm. | 974 | therm. |
2325 | 963 | """ | 975 | """ |
2340 | 964 | # Store myself as the public api!!! | 976 | # This function works in two parts: first we put a few things in |
2341 | 965 | self.user_ns['get_ipython'] = self.get_ipython | 977 | # user_ns, and we sync that contents into user_config_ns so that these |
2342 | 966 | 978 | # initial variables aren't shown by %who. After the sync, we add the | |
2343 | 967 | # make global variables for user access to the histories | 979 | # rest of what we *do* want the user to see with %who even on a new |
2344 | 968 | self.user_ns['_ih'] = self.input_hist | 980 | # session (probably nothing, so theye really only see their own stuff) |
2345 | 969 | self.user_ns['_oh'] = self.output_hist | 981 | |
2346 | 970 | self.user_ns['_dh'] = self.dir_hist | 982 | # The user dict must *always* have a __builtin__ reference to the |
2347 | 971 | 983 | # Python standard __builtin__ namespace, which must be imported. | |
2348 | 972 | # user aliases to input and output histories | 984 | # This is so that certain operations in prompt evaluation can be |
2349 | 973 | self.user_ns['In'] = self.input_hist | 985 | # reliably executed with builtins. Note that we can NOT use |
2350 | 974 | self.user_ns['Out'] = self.output_hist | 986 | # __builtins__ (note the 's'), because that can either be a dict or a |
2351 | 975 | 987 | # module, and can even mutate at runtime, depending on the context | |
2352 | 976 | self.user_ns['_sh'] = shadowns | 988 | # (Python makes no guarantees on it). In contrast, __builtin__ is |
2353 | 977 | 989 | # always a module object, though it must be explicitly imported. | |
2354 | 990 | |||
2355 | 991 | # For more details: | ||
2356 | 992 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html | ||
2357 | 993 | ns = dict(__builtin__ = __builtin__) | ||
2358 | 994 | |||
2359 | 978 | # Put 'help' in the user namespace | 995 | # Put 'help' in the user namespace |
2360 | 979 | try: | 996 | try: |
2361 | 980 | from site import _Helper | 997 | from site import _Helper |
2363 | 981 | self.user_ns['help'] = _Helper() | 998 | ns['help'] = _Helper() |
2364 | 982 | except ImportError: | 999 | except ImportError: |
2365 | 983 | warn('help() not available - check site.py') | 1000 | warn('help() not available - check site.py') |
2366 | 984 | 1001 | ||
2367 | 1002 | # make global variables for user access to the histories | ||
2368 | 1003 | ns['_ih'] = self.input_hist | ||
2369 | 1004 | ns['_oh'] = self.output_hist | ||
2370 | 1005 | ns['_dh'] = self.dir_hist | ||
2371 | 1006 | |||
2372 | 1007 | ns['_sh'] = shadowns | ||
2373 | 1008 | |||
2374 | 1009 | # user aliases to input and output histories. These shouldn't show up | ||
2375 | 1010 | # in %who, as they can have very large reprs. | ||
2376 | 1011 | ns['In'] = self.input_hist | ||
2377 | 1012 | ns['Out'] = self.output_hist | ||
2378 | 1013 | |||
2379 | 1014 | # Store myself as the public api!!! | ||
2380 | 1015 | ns['get_ipython'] = self.get_ipython | ||
2381 | 1016 | |||
2382 | 1017 | # Sync what we've added so far to user_config_ns so these aren't seen | ||
2383 | 1018 | # by %who | ||
2384 | 1019 | self.user_config_ns.update(ns) | ||
2385 | 1020 | |||
2386 | 1021 | # Anything put into ns now would show up in %who. Think twice before | ||
2387 | 1022 | # putting anything here, as we really want %who to show the user their | ||
2388 | 1023 | # stuff, not our variables. | ||
2389 | 1024 | |||
2390 | 1025 | # Finally, update the real user's namespace | ||
2391 | 1026 | self.user_ns.update(ns) | ||
2392 | 1027 | |||
2393 | 1028 | |||
2394 | 985 | def reset(self): | 1029 | def reset(self): |
2395 | 986 | """Clear all internal namespaces. | 1030 | """Clear all internal namespaces. |
2396 | 987 | 1031 | ||
2397 | @@ -1099,9 +1143,6 @@ | |||
2398 | 1099 | def savehist(self): | 1143 | def savehist(self): |
2399 | 1100 | """Save input history to a file (via readline library).""" | 1144 | """Save input history to a file (via readline library).""" |
2400 | 1101 | 1145 | ||
2401 | 1102 | if not self.has_readline: | ||
2402 | 1103 | return | ||
2403 | 1104 | |||
2404 | 1105 | try: | 1146 | try: |
2405 | 1106 | self.readline.write_history_file(self.histfile) | 1147 | self.readline.write_history_file(self.histfile) |
2406 | 1107 | except: | 1148 | except: |
2407 | @@ -1111,12 +1152,11 @@ | |||
2408 | 1111 | def reloadhist(self): | 1152 | def reloadhist(self): |
2409 | 1112 | """Reload the input history from disk file.""" | 1153 | """Reload the input history from disk file.""" |
2410 | 1113 | 1154 | ||
2417 | 1114 | if self.has_readline: | 1155 | try: |
2418 | 1115 | try: | 1156 | self.readline.clear_history() |
2419 | 1116 | self.readline.clear_history() | 1157 | self.readline.read_history_file(self.shell.histfile) |
2420 | 1117 | self.readline.read_history_file(self.shell.histfile) | 1158 | except AttributeError: |
2421 | 1118 | except AttributeError: | 1159 | pass |
2416 | 1119 | pass | ||
2422 | 1120 | 1160 | ||
2423 | 1121 | def history_saving_wrapper(self, func): | 1161 | def history_saving_wrapper(self, func): |
2424 | 1122 | """ Wrap func for readline history saving | 1162 | """ Wrap func for readline history saving |
2425 | @@ -1150,37 +1190,14 @@ | |||
2426 | 1150 | color_scheme='NoColor', | 1190 | color_scheme='NoColor', |
2427 | 1151 | tb_offset = 1) | 1191 | tb_offset = 1) |
2428 | 1152 | 1192 | ||
2441 | 1153 | # IPython itself shouldn't crash. This will produce a detailed | 1193 | # The instance will store a pointer to the system-wide exception hook, |
2442 | 1154 | # post-mortem if it does. But we only install the crash handler for | 1194 | # so that runtime code (such as magics) can access it. This is because |
2443 | 1155 | # non-threaded shells, the threaded ones use a normal verbose reporter | 1195 | # during the read-eval loop, it may get temporarily overwritten. |
2444 | 1156 | # and lose the crash handler. This is because exceptions in the main | 1196 | self.sys_excepthook = sys.excepthook |
2433 | 1157 | # thread (such as in GUI code) propagate directly to sys.excepthook, | ||
2434 | 1158 | # and there's no point in printing crash dumps for every user exception. | ||
2435 | 1159 | if self.isthreaded: | ||
2436 | 1160 | ipCrashHandler = ultratb.FormattedTB() | ||
2437 | 1161 | else: | ||
2438 | 1162 | from IPython.core import crashhandler | ||
2439 | 1163 | ipCrashHandler = crashhandler.IPythonCrashHandler(self) | ||
2440 | 1164 | self.set_crash_handler(ipCrashHandler) | ||
2445 | 1165 | 1197 | ||
2446 | 1166 | # and add any custom exception handlers the user may have specified | 1198 | # and add any custom exception handlers the user may have specified |
2447 | 1167 | self.set_custom_exc(*custom_exceptions) | 1199 | self.set_custom_exc(*custom_exceptions) |
2448 | 1168 | 1200 | ||
2449 | 1169 | def set_crash_handler(self, crashHandler): | ||
2450 | 1170 | """Set the IPython crash handler. | ||
2451 | 1171 | |||
2452 | 1172 | This must be a callable with a signature suitable for use as | ||
2453 | 1173 | sys.excepthook.""" | ||
2454 | 1174 | |||
2455 | 1175 | # Install the given crash handler as the Python exception hook | ||
2456 | 1176 | sys.excepthook = crashHandler | ||
2457 | 1177 | |||
2458 | 1178 | # The instance will store a pointer to this, so that runtime code | ||
2459 | 1179 | # (such as magics) can access it. This is because during the | ||
2460 | 1180 | # read-eval loop, it gets temporarily overwritten (to deal with GUI | ||
2461 | 1181 | # frameworks). | ||
2462 | 1182 | self.sys_excepthook = sys.excepthook | ||
2463 | 1183 | |||
2464 | 1184 | def set_custom_exc(self,exc_tuple,handler): | 1201 | def set_custom_exc(self,exc_tuple,handler): |
2465 | 1185 | """set_custom_exc(exc_tuple,handler) | 1202 | """set_custom_exc(exc_tuple,handler) |
2466 | 1186 | 1203 | ||
2467 | @@ -1248,7 +1265,8 @@ | |||
2468 | 1248 | """ | 1265 | """ |
2469 | 1249 | self.showtraceback((etype,value,tb),tb_offset=0) | 1266 | self.showtraceback((etype,value,tb),tb_offset=0) |
2470 | 1250 | 1267 | ||
2472 | 1251 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None): | 1268 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None, |
2473 | 1269 | exception_only=False): | ||
2474 | 1252 | """Display the exception that just occurred. | 1270 | """Display the exception that just occurred. |
2475 | 1253 | 1271 | ||
2476 | 1254 | If nothing is known about the exception, this is the method which | 1272 | If nothing is known about the exception, this is the method which |
2477 | @@ -1259,18 +1277,24 @@ | |||
2478 | 1259 | care of calling it if needed, so unless you are explicitly catching a | 1277 | care of calling it if needed, so unless you are explicitly catching a |
2479 | 1260 | SyntaxError exception, don't try to analyze the stack manually and | 1278 | SyntaxError exception, don't try to analyze the stack manually and |
2480 | 1261 | simply call this method.""" | 1279 | simply call this method.""" |
2481 | 1262 | |||
2482 | 1263 | |||
2483 | 1264 | # Though this won't be called by syntax errors in the input line, | ||
2484 | 1265 | # there may be SyntaxError cases whith imported code. | ||
2485 | 1266 | 1280 | ||
2486 | 1267 | try: | 1281 | try: |
2487 | 1268 | if exc_tuple is None: | 1282 | if exc_tuple is None: |
2488 | 1269 | etype, value, tb = sys.exc_info() | 1283 | etype, value, tb = sys.exc_info() |
2489 | 1270 | else: | 1284 | else: |
2490 | 1271 | etype, value, tb = exc_tuple | 1285 | etype, value, tb = exc_tuple |
2491 | 1286 | |||
2492 | 1287 | if etype is None: | ||
2493 | 1288 | if hasattr(sys, 'last_type'): | ||
2494 | 1289 | etype, value, tb = sys.last_type, sys.last_value, \ | ||
2495 | 1290 | sys.last_traceback | ||
2496 | 1291 | else: | ||
2497 | 1292 | self.write('No traceback available to show.\n') | ||
2498 | 1293 | return | ||
2499 | 1272 | 1294 | ||
2500 | 1273 | if etype is SyntaxError: | 1295 | if etype is SyntaxError: |
2501 | 1296 | # Though this won't be called by syntax errors in the input | ||
2502 | 1297 | # line, there may be SyntaxError cases whith imported code. | ||
2503 | 1274 | self.showsyntaxerror(filename) | 1298 | self.showsyntaxerror(filename) |
2504 | 1275 | elif etype is UsageError: | 1299 | elif etype is UsageError: |
2505 | 1276 | print "UsageError:", value | 1300 | print "UsageError:", value |
2506 | @@ -1286,12 +1310,20 @@ | |||
2507 | 1286 | if etype in self.custom_exceptions: | 1310 | if etype in self.custom_exceptions: |
2508 | 1287 | self.CustomTB(etype,value,tb) | 1311 | self.CustomTB(etype,value,tb) |
2509 | 1288 | else: | 1312 | else: |
2514 | 1289 | self.InteractiveTB(etype,value,tb,tb_offset=tb_offset) | 1313 | if exception_only: |
2515 | 1290 | if self.InteractiveTB.call_pdb and self.has_readline: | 1314 | m = ('An exception has occurred, use %tb to see the ' |
2516 | 1291 | # pdb mucks up readline, fix it back | 1315 | 'full traceback.') |
2517 | 1292 | self.set_completer() | 1316 | print m |
2518 | 1317 | self.InteractiveTB.show_exception_only(etype, value) | ||
2519 | 1318 | else: | ||
2520 | 1319 | self.InteractiveTB(etype,value,tb,tb_offset=tb_offset) | ||
2521 | 1320 | if self.InteractiveTB.call_pdb: | ||
2522 | 1321 | # pdb mucks up readline, fix it back | ||
2523 | 1322 | self.set_completer() | ||
2524 | 1323 | |||
2525 | 1293 | except KeyboardInterrupt: | 1324 | except KeyboardInterrupt: |
2527 | 1294 | self.write("\nKeyboardInterrupt\n") | 1325 | self.write("\nKeyboardInterrupt\n") |
2528 | 1326 | |||
2529 | 1295 | 1327 | ||
2530 | 1296 | def showsyntaxerror(self, filename=None): | 1328 | def showsyntaxerror(self, filename=None): |
2531 | 1297 | """Display the syntax error that just occurred. | 1329 | """Display the syntax error that just occurred. |
2532 | @@ -1304,7 +1336,7 @@ | |||
2533 | 1304 | """ | 1336 | """ |
2534 | 1305 | etype, value, last_traceback = sys.exc_info() | 1337 | etype, value, last_traceback = sys.exc_info() |
2535 | 1306 | 1338 | ||
2537 | 1307 | # See note about these variables in showtraceback() below | 1339 | # See note about these variables in showtraceback() above |
2538 | 1308 | sys.last_type = etype | 1340 | sys.last_type = etype |
2539 | 1309 | sys.last_value = value | 1341 | sys.last_value = value |
2540 | 1310 | sys.last_traceback = last_traceback | 1342 | sys.last_traceback = last_traceback |
2541 | @@ -1464,20 +1496,25 @@ | |||
2542 | 1464 | def init_readline(self): | 1496 | def init_readline(self): |
2543 | 1465 | """Command history completion/saving/reloading.""" | 1497 | """Command history completion/saving/reloading.""" |
2544 | 1466 | 1498 | ||
2545 | 1499 | if self.readline_use: | ||
2546 | 1500 | import IPython.utils.rlineimpl as readline | ||
2547 | 1501 | |||
2548 | 1467 | self.rl_next_input = None | 1502 | self.rl_next_input = None |
2549 | 1468 | self.rl_do_indent = False | 1503 | self.rl_do_indent = False |
2550 | 1469 | 1504 | ||
2558 | 1470 | if not self.readline_use: | 1505 | if not self.readline_use or not readline.have_readline: |
2559 | 1471 | return | 1506 | self.has_readline = False |
2553 | 1472 | |||
2554 | 1473 | import IPython.utils.rlineimpl as readline | ||
2555 | 1474 | |||
2556 | 1475 | if not readline.have_readline: | ||
2557 | 1476 | self.has_readline = 0 | ||
2560 | 1477 | self.readline = None | 1507 | self.readline = None |
2563 | 1478 | # no point in bugging windows users with this every time: | 1508 | # Set a number of methods that depend on readline to be no-op |
2564 | 1479 | warn('Readline services not available on this platform.') | 1509 | self.savehist = no_op |
2565 | 1510 | self.reloadhist = no_op | ||
2566 | 1511 | self.set_completer = no_op | ||
2567 | 1512 | self.set_custom_completer = no_op | ||
2568 | 1513 | self.set_completer_frame = no_op | ||
2569 | 1514 | warn('Readline services not available or not loaded.') | ||
2570 | 1480 | else: | 1515 | else: |
2571 | 1516 | self.has_readline = True | ||
2572 | 1517 | self.readline = readline | ||
2573 | 1481 | sys.modules['readline'] = readline | 1518 | sys.modules['readline'] = readline |
2574 | 1482 | import atexit | 1519 | import atexit |
2575 | 1483 | from IPython.core.completer import IPCompleter | 1520 | from IPython.core.completer import IPCompleter |
2576 | @@ -1512,8 +1549,6 @@ | |||
2577 | 1512 | warn('Problems reading readline initialization file <%s>' | 1549 | warn('Problems reading readline initialization file <%s>' |
2578 | 1513 | % inputrc_name) | 1550 | % inputrc_name) |
2579 | 1514 | 1551 | ||
2580 | 1515 | self.has_readline = 1 | ||
2581 | 1516 | self.readline = readline | ||
2582 | 1517 | # save this in sys so embedded copies can restore it properly | 1552 | # save this in sys so embedded copies can restore it properly |
2583 | 1518 | sys.ipcompleter = self.Completer.complete | 1553 | sys.ipcompleter = self.Completer.complete |
2584 | 1519 | self.set_completer() | 1554 | self.set_completer() |
2585 | @@ -1585,6 +1620,9 @@ | |||
2586 | 1585 | # Set user colors (don't do it in the constructor above so that it | 1620 | # Set user colors (don't do it in the constructor above so that it |
2587 | 1586 | # doesn't crash if colors option is invalid) | 1621 | # doesn't crash if colors option is invalid) |
2588 | 1587 | self.magic_colors(self.colors) | 1622 | self.magic_colors(self.colors) |
2589 | 1623 | # History was moved to a separate module | ||
2590 | 1624 | from . import history | ||
2591 | 1625 | history.init_ipython(self) | ||
2592 | 1588 | 1626 | ||
2593 | 1589 | def magic(self,arg_s): | 1627 | def magic(self,arg_s): |
2594 | 1590 | """Call a magic function by name. | 1628 | """Call a magic function by name. |
2595 | @@ -1603,7 +1641,6 @@ | |||
2596 | 1603 | valid Python code you can type at the interpreter, including loops and | 1641 | valid Python code you can type at the interpreter, including loops and |
2597 | 1604 | compound statements. | 1642 | compound statements. |
2598 | 1605 | """ | 1643 | """ |
2599 | 1606 | |||
2600 | 1607 | args = arg_s.split(' ',1) | 1644 | args = arg_s.split(' ',1) |
2601 | 1608 | magic_name = args[0] | 1645 | magic_name = args[0] |
2602 | 1609 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) | 1646 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) |
2603 | @@ -1842,7 +1879,8 @@ | |||
2604 | 1842 | except EOFError: | 1879 | except EOFError: |
2605 | 1843 | if self.autoindent: | 1880 | if self.autoindent: |
2606 | 1844 | self.rl_do_indent = False | 1881 | self.rl_do_indent = False |
2608 | 1845 | self.readline_startup_hook(None) | 1882 | if self.has_readline: |
2609 | 1883 | self.readline_startup_hook(None) | ||
2610 | 1846 | self.write('\n') | 1884 | self.write('\n') |
2611 | 1847 | self.exit() | 1885 | self.exit() |
2612 | 1848 | except bdb.BdbQuit: | 1886 | except bdb.BdbQuit: |
2613 | @@ -1859,10 +1897,13 @@ | |||
2614 | 1859 | if (self.SyntaxTB.last_syntax_error and | 1897 | if (self.SyntaxTB.last_syntax_error and |
2615 | 1860 | self.autoedit_syntax): | 1898 | self.autoedit_syntax): |
2616 | 1861 | self.edit_syntax_error() | 1899 | self.edit_syntax_error() |
2618 | 1862 | 1900 | ||
2619 | 1863 | # We are off again... | 1901 | # We are off again... |
2620 | 1864 | __builtin__.__dict__['__IPYTHON__active'] -= 1 | 1902 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
2621 | 1865 | 1903 | ||
2622 | 1904 | # Turn off the exit flag, so the mainloop can be restarted if desired | ||
2623 | 1905 | self.exit_now = False | ||
2624 | 1906 | |||
2625 | 1866 | def safe_execfile(self, fname, *where, **kw): | 1907 | def safe_execfile(self, fname, *where, **kw): |
2626 | 1867 | """A safe version of the builtin execfile(). | 1908 | """A safe version of the builtin execfile(). |
2627 | 1868 | 1909 | ||
2628 | @@ -1878,7 +1919,8 @@ | |||
2629 | 1878 | One or two namespaces, passed to execfile() as (globals,locals). | 1919 | One or two namespaces, passed to execfile() as (globals,locals). |
2630 | 1879 | If only one is given, it is passed as both. | 1920 | If only one is given, it is passed as both. |
2631 | 1880 | exit_ignore : bool (False) | 1921 | exit_ignore : bool (False) |
2633 | 1881 | If True, then don't print errors for non-zero exit statuses. | 1922 | If True, then silence SystemExit for non-zero status (it is always |
2634 | 1923 | silenced for zero status, as it is so common). | ||
2635 | 1882 | """ | 1924 | """ |
2636 | 1883 | kw.setdefault('exit_ignore', False) | 1925 | kw.setdefault('exit_ignore', False) |
2637 | 1884 | 1926 | ||
2638 | @@ -1903,40 +1945,21 @@ | |||
2639 | 1903 | 1945 | ||
2640 | 1904 | with prepended_to_syspath(dname): | 1946 | with prepended_to_syspath(dname): |
2641 | 1905 | try: | 1947 | try: |
2660 | 1906 | if sys.platform == 'win32' and sys.version_info < (2,5,1): | 1948 | execfile(fname,*where) |
2643 | 1907 | # Work around a bug in Python for Windows. The bug was | ||
2644 | 1908 | # fixed in in Python 2.5 r54159 and 54158, but that's still | ||
2645 | 1909 | # SVN Python as of March/07. For details, see: | ||
2646 | 1910 | # http://projects.scipy.org/ipython/ipython/ticket/123 | ||
2647 | 1911 | try: | ||
2648 | 1912 | globs,locs = where[0:2] | ||
2649 | 1913 | except: | ||
2650 | 1914 | try: | ||
2651 | 1915 | globs = locs = where[0] | ||
2652 | 1916 | except: | ||
2653 | 1917 | globs = locs = globals() | ||
2654 | 1918 | exec file(fname) in globs,locs | ||
2655 | 1919 | else: | ||
2656 | 1920 | execfile(fname,*where) | ||
2657 | 1921 | except SyntaxError: | ||
2658 | 1922 | self.showsyntaxerror() | ||
2659 | 1923 | warn('Failure executing file: <%s>' % fname) | ||
2661 | 1924 | except SystemExit, status: | 1949 | except SystemExit, status: |
2674 | 1925 | # Code that correctly sets the exit status flag to success (0) | 1950 | # If the call was made with 0 or None exit status (sys.exit(0) |
2675 | 1926 | # shouldn't be bothered with a traceback. Note that a plain | 1951 | # or sys.exit() ), don't bother showing a traceback, as both of |
2676 | 1927 | # sys.exit() does NOT set the message to 0 (it's empty) so that | 1952 | # these are considered normal by the OS: |
2677 | 1928 | # will still get a traceback. Note that the structure of the | 1953 | # > python -c'import sys;sys.exit(0)'; echo $? |
2678 | 1929 | # SystemExit exception changed between Python 2.4 and 2.5, so | 1954 | # 0 |
2679 | 1930 | # the checks must be done in a version-dependent way. | 1955 | # > python -c'import sys;sys.exit()'; echo $? |
2680 | 1931 | show = False | 1956 | # 0 |
2681 | 1932 | if status.args[0]==0 and not kw['exit_ignore']: | 1957 | # For other exit status, we show the exception unless |
2682 | 1933 | show = True | 1958 | # explicitly silenced, but only in short form. |
2683 | 1934 | if show: | 1959 | if status.code not in (0, None) and not kw['exit_ignore']: |
2684 | 1935 | self.showtraceback() | 1960 | self.showtraceback(exception_only=True) |
2673 | 1936 | warn('Failure executing file: <%s>' % fname) | ||
2685 | 1937 | except: | 1961 | except: |
2686 | 1938 | self.showtraceback() | 1962 | self.showtraceback() |
2687 | 1939 | warn('Failure executing file: <%s>' % fname) | ||
2688 | 1940 | 1963 | ||
2689 | 1941 | def safe_execfile_ipy(self, fname): | 1964 | def safe_execfile_ipy(self, fname): |
2690 | 1942 | """Like safe_execfile, but for .ipy files with IPython syntax. | 1965 | """Like safe_execfile, but for .ipy files with IPython syntax. |
2691 | @@ -2150,9 +2173,8 @@ | |||
2692 | 2150 | sys.excepthook = old_excepthook | 2173 | sys.excepthook = old_excepthook |
2693 | 2151 | except SystemExit: | 2174 | except SystemExit: |
2694 | 2152 | self.resetbuffer() | 2175 | self.resetbuffer() |
2698 | 2153 | self.showtraceback() | 2176 | self.showtraceback(exception_only=True) |
2699 | 2154 | warn("Type %exit or %quit to exit IPython " | 2177 | warn("To exit: use any of 'exit', 'quit', %Exit or Ctrl-D.", level=1) |
2697 | 2155 | "(%Exit or %Quit do so unconditionally).",level=1) | ||
2700 | 2156 | except self.custom_exceptions: | 2178 | except self.custom_exceptions: |
2701 | 2157 | etype,value,tb = sys.exc_info() | 2179 | etype,value,tb = sys.exc_info() |
2702 | 2158 | self.CustomTB(etype,value,tb) | 2180 | self.CustomTB(etype,value,tb) |
2703 | @@ -2336,7 +2358,7 @@ | |||
2704 | 2336 | with prepended_to_syspath(self.ipython_extension_dir): | 2358 | with prepended_to_syspath(self.ipython_extension_dir): |
2705 | 2337 | __import__(module_str) | 2359 | __import__(module_str) |
2706 | 2338 | mod = sys.modules[module_str] | 2360 | mod = sys.modules[module_str] |
2708 | 2339 | self._call_load_ipython_extension(mod) | 2361 | return self._call_load_ipython_extension(mod) |
2709 | 2340 | 2362 | ||
2710 | 2341 | def unload_extension(self, module_str): | 2363 | def unload_extension(self, module_str): |
2711 | 2342 | """Unload an IPython extension by its module name. | 2364 | """Unload an IPython extension by its module name. |
2712 | @@ -2368,11 +2390,11 @@ | |||
2713 | 2368 | 2390 | ||
2714 | 2369 | def _call_load_ipython_extension(self, mod): | 2391 | def _call_load_ipython_extension(self, mod): |
2715 | 2370 | if hasattr(mod, 'load_ipython_extension'): | 2392 | if hasattr(mod, 'load_ipython_extension'): |
2717 | 2371 | mod.load_ipython_extension(self) | 2393 | return mod.load_ipython_extension(self) |
2718 | 2372 | 2394 | ||
2719 | 2373 | def _call_unload_ipython_extension(self, mod): | 2395 | def _call_unload_ipython_extension(self, mod): |
2720 | 2374 | if hasattr(mod, 'unload_ipython_extension'): | 2396 | if hasattr(mod, 'unload_ipython_extension'): |
2722 | 2375 | mod.unload_ipython_extension(self) | 2397 | return mod.unload_ipython_extension(self) |
2723 | 2376 | 2398 | ||
2724 | 2377 | #------------------------------------------------------------------------- | 2399 | #------------------------------------------------------------------------- |
2725 | 2378 | # Things related to the prefilter | 2400 | # Things related to the prefilter |
2726 | @@ -2380,6 +2402,10 @@ | |||
2727 | 2380 | 2402 | ||
2728 | 2381 | def init_prefilter(self): | 2403 | def init_prefilter(self): |
2729 | 2382 | self.prefilter_manager = PrefilterManager(self, config=self.config) | 2404 | self.prefilter_manager = PrefilterManager(self, config=self.config) |
2730 | 2405 | # Ultimately this will be refactored in the new interpreter code, but | ||
2731 | 2406 | # for now, we should expose the main prefilter method (there's legacy | ||
2732 | 2407 | # code out there that may rely on this). | ||
2733 | 2408 | self.prefilter = self.prefilter_manager.prefilter_lines | ||
2734 | 2383 | 2409 | ||
2735 | 2384 | #------------------------------------------------------------------------- | 2410 | #------------------------------------------------------------------------- |
2736 | 2385 | # Utilities | 2411 | # Utilities |
2737 | @@ -2445,11 +2471,46 @@ | |||
2738 | 2445 | return ask_yes_no(prompt,default) | 2471 | return ask_yes_no(prompt,default) |
2739 | 2446 | 2472 | ||
2740 | 2447 | #------------------------------------------------------------------------- | 2473 | #------------------------------------------------------------------------- |
2741 | 2474 | # Things related to GUI support and pylab | ||
2742 | 2475 | #------------------------------------------------------------------------- | ||
2743 | 2476 | |||
2744 | 2477 | def enable_pylab(self, gui=None): | ||
2745 | 2478 | """Activate pylab support at runtime. | ||
2746 | 2479 | |||
2747 | 2480 | This turns on support for matplotlib, preloads into the interactive | ||
2748 | 2481 | namespace all of numpy and pylab, and configures IPython to correcdtly | ||
2749 | 2482 | interact with the GUI event loop. The GUI backend to be used can be | ||
2750 | 2483 | optionally selected with the optional :param:`gui` argument. | ||
2751 | 2484 | |||
2752 | 2485 | Parameters | ||
2753 | 2486 | ---------- | ||
2754 | 2487 | gui : optional, string | ||
2755 | 2488 | |||
2756 | 2489 | If given, dictates the choice of matplotlib GUI backend to use | ||
2757 | 2490 | (should be one of IPython's supported backends, 'tk', 'qt', 'wx' or | ||
2758 | 2491 | 'gtk'), otherwise we use the default chosen by matplotlib (as | ||
2759 | 2492 | dictated by the matplotlib build-time options plus the user's | ||
2760 | 2493 | matplotlibrc configuration file). | ||
2761 | 2494 | """ | ||
2762 | 2495 | # We want to prevent the loading of pylab to pollute the user's | ||
2763 | 2496 | # namespace as shown by the %who* magics, so we execute the activation | ||
2764 | 2497 | # code in an empty namespace, and we update *both* user_ns and | ||
2765 | 2498 | # user_config_ns with this information. | ||
2766 | 2499 | ns = {} | ||
2767 | 2500 | gui = pylab_activate(ns, gui) | ||
2768 | 2501 | self.user_ns.update(ns) | ||
2769 | 2502 | self.user_config_ns.update(ns) | ||
2770 | 2503 | # Now we must activate the gui pylab wants to use, and fix %run to take | ||
2771 | 2504 | # plot updates into account | ||
2772 | 2505 | enable_gui(gui) | ||
2773 | 2506 | self.magic_run = self._pylab_magic_run | ||
2774 | 2507 | |||
2775 | 2508 | #------------------------------------------------------------------------- | ||
2776 | 2448 | # Things related to IPython exiting | 2509 | # Things related to IPython exiting |
2777 | 2449 | #------------------------------------------------------------------------- | 2510 | #------------------------------------------------------------------------- |
2778 | 2450 | 2511 | ||
2779 | 2451 | def ask_exit(self): | 2512 | def ask_exit(self): |
2781 | 2452 | """ Call for exiting. Can be overiden and used as a callback. """ | 2513 | """ Ask the shell to exit. Can be overiden and used as a callback. """ |
2782 | 2453 | self.exit_now = True | 2514 | self.exit_now = True |
2783 | 2454 | 2515 | ||
2784 | 2455 | def exit(self): | 2516 | def exit(self): |
2785 | 2456 | 2517 | ||
2786 | === modified file 'IPython/core/magic.py' | |||
2787 | --- IPython/core/magic.py 2009-12-30 19:26:16 +0000 | |||
2788 | +++ IPython/core/magic.py 2010-01-18 01:17:11 +0000 | |||
2789 | @@ -44,21 +44,26 @@ | |||
2790 | 44 | 44 | ||
2791 | 45 | # Homebrewed | 45 | # Homebrewed |
2792 | 46 | import IPython | 46 | import IPython |
2794 | 47 | from IPython.utils import wildcard | 47 | import IPython.utils.generics |
2795 | 48 | |||
2796 | 48 | from IPython.core import debugger, oinspect | 49 | from IPython.core import debugger, oinspect |
2797 | 49 | from IPython.core.error import TryNext | 50 | from IPython.core.error import TryNext |
2798 | 51 | from IPython.core.error import UsageError | ||
2799 | 50 | from IPython.core.fakemodule import FakeModule | 52 | from IPython.core.fakemodule import FakeModule |
2800 | 53 | from IPython.core.macro import Macro | ||
2801 | 54 | from IPython.core.page import page | ||
2802 | 51 | from IPython.core.prefilter import ESC_MAGIC | 55 | from IPython.core.prefilter import ESC_MAGIC |
2803 | 56 | from IPython.core.pylabtools import mpl_runner | ||
2804 | 57 | from IPython.lib.inputhook import enable_gui | ||
2805 | 52 | from IPython.external.Itpl import Itpl, itpl, printpl,itplns | 58 | from IPython.external.Itpl import Itpl, itpl, printpl,itplns |
2806 | 59 | from IPython.testing import decorators as testdec | ||
2807 | 60 | from IPython.utils import platutils | ||
2808 | 61 | from IPython.utils import wildcard | ||
2809 | 53 | from IPython.utils.PyColorize import Parser | 62 | from IPython.utils.PyColorize import Parser |
2810 | 54 | from IPython.utils.ipstruct import Struct | 63 | from IPython.utils.ipstruct import Struct |
2812 | 55 | from IPython.core.macro import Macro | 64 | |
2813 | 65 | # XXX - We need to switch to explicit imports here with genutils | ||
2814 | 56 | from IPython.utils.genutils import * | 66 | from IPython.utils.genutils import * |
2815 | 57 | from IPython.core.page import page | ||
2816 | 58 | from IPython.utils import platutils | ||
2817 | 59 | import IPython.utils.generics | ||
2818 | 60 | from IPython.core.error import UsageError | ||
2819 | 61 | from IPython.testing import decorators as testdec | ||
2820 | 62 | 67 | ||
2821 | 63 | #*************************************************************************** | 68 | #*************************************************************************** |
2822 | 64 | # Utility functions | 69 | # Utility functions |
2823 | @@ -80,10 +85,16 @@ | |||
2824 | 80 | done.add(h) | 85 | done.add(h) |
2825 | 81 | 86 | ||
2826 | 82 | return newhead + tail | 87 | return newhead + tail |
2828 | 83 | 88 | ||
2829 | 84 | 89 | ||
2830 | 85 | #*************************************************************************** | 90 | #*************************************************************************** |
2831 | 86 | # Main class implementing Magic functionality | 91 | # Main class implementing Magic functionality |
2832 | 92 | |||
2833 | 93 | # XXX - for some odd reason, if Magic is made a new-style class, we get errors | ||
2834 | 94 | # on construction of the main InteractiveShell object. Something odd is going | ||
2835 | 95 | # on with super() calls, Component and the MRO... For now leave it as-is, but | ||
2836 | 96 | # eventually this needs to be clarified. | ||
2837 | 97 | |||
2838 | 87 | class Magic: | 98 | class Magic: |
2839 | 88 | """Magic functions for InteractiveShell. | 99 | """Magic functions for InteractiveShell. |
2840 | 89 | 100 | ||
2841 | @@ -335,7 +346,7 @@ | |||
2842 | 335 | raise ValueError,'incorrect mode given: %s' % mode | 346 | raise ValueError,'incorrect mode given: %s' % mode |
2843 | 336 | # Get options | 347 | # Get options |
2844 | 337 | list_all = kw.get('list_all',0) | 348 | list_all = kw.get('list_all',0) |
2846 | 338 | posix = kw.get('posix',True) | 349 | posix = kw.get('posix', os.name == 'posix') |
2847 | 339 | 350 | ||
2848 | 340 | # Check if we have more than one argument to warrant extra processing: | 351 | # Check if we have more than one argument to warrant extra processing: |
2849 | 341 | odict = {} # Dictionary with options | 352 | odict = {} # Dictionary with options |
2850 | @@ -864,7 +875,7 @@ | |||
2851 | 864 | show_all=opt('a'),ignore_case=ignore_case) | 875 | show_all=opt('a'),ignore_case=ignore_case) |
2852 | 865 | except: | 876 | except: |
2853 | 866 | shell.showtraceback() | 877 | shell.showtraceback() |
2855 | 867 | 878 | ||
2856 | 868 | def magic_who_ls(self, parameter_s=''): | 879 | def magic_who_ls(self, parameter_s=''): |
2857 | 869 | """Return a sorted list of all interactive variables. | 880 | """Return a sorted list of all interactive variables. |
2858 | 870 | 881 | ||
2859 | @@ -874,17 +885,15 @@ | |||
2860 | 874 | user_ns = self.shell.user_ns | 885 | user_ns = self.shell.user_ns |
2861 | 875 | internal_ns = self.shell.internal_ns | 886 | internal_ns = self.shell.internal_ns |
2862 | 876 | user_config_ns = self.shell.user_config_ns | 887 | user_config_ns = self.shell.user_config_ns |
2864 | 877 | out = [] | 888 | out = [ i for i in user_ns |
2865 | 889 | if not i.startswith('_') \ | ||
2866 | 890 | and not (i in internal_ns or i in user_config_ns) ] | ||
2867 | 891 | |||
2868 | 878 | typelist = parameter_s.split() | 892 | typelist = parameter_s.split() |
2869 | 893 | if typelist: | ||
2870 | 894 | typeset = set(typelist) | ||
2871 | 895 | out = [i for i in out if type(i).__name__ in typeset] | ||
2872 | 879 | 896 | ||
2873 | 880 | for i in user_ns: | ||
2874 | 881 | if not (i.startswith('_') or i.startswith('_i')) \ | ||
2875 | 882 | and not (i in internal_ns or i in user_config_ns): | ||
2876 | 883 | if typelist: | ||
2877 | 884 | if type(user_ns[i]).__name__ in typelist: | ||
2878 | 885 | out.append(i) | ||
2879 | 886 | else: | ||
2880 | 887 | out.append(i) | ||
2881 | 888 | out.sort() | 897 | out.sort() |
2882 | 889 | return out | 898 | return out |
2883 | 890 | 899 | ||
2884 | @@ -1571,7 +1580,7 @@ | |||
2885 | 1571 | return | 1580 | return |
2886 | 1572 | 1581 | ||
2887 | 1573 | if filename.lower().endswith('.ipy'): | 1582 | if filename.lower().endswith('.ipy'): |
2889 | 1574 | self.safe_execfile_ipy(filename) | 1583 | self.shell.safe_execfile_ipy(filename) |
2890 | 1575 | return | 1584 | return |
2891 | 1576 | 1585 | ||
2892 | 1577 | # Control the response to exit() calls made by the script being run | 1586 | # Control the response to exit() calls made by the script being run |
2893 | @@ -2522,25 +2531,15 @@ | |||
2894 | 2522 | self.shell.pprint = 1 - self.shell.pprint | 2531 | self.shell.pprint = 1 - self.shell.pprint |
2895 | 2523 | print 'Pretty printing has been turned', \ | 2532 | print 'Pretty printing has been turned', \ |
2896 | 2524 | ['OFF','ON'][self.shell.pprint] | 2533 | ['OFF','ON'][self.shell.pprint] |
2911 | 2525 | 2534 | ||
2898 | 2526 | def magic_exit(self, parameter_s=''): | ||
2899 | 2527 | """Exit IPython, confirming if configured to do so. | ||
2900 | 2528 | |||
2901 | 2529 | You can configure whether IPython asks for confirmation upon exit by | ||
2902 | 2530 | setting the confirm_exit flag in the ipythonrc file.""" | ||
2903 | 2531 | |||
2904 | 2532 | self.shell.exit() | ||
2905 | 2533 | |||
2906 | 2534 | def magic_quit(self, parameter_s=''): | ||
2907 | 2535 | """Exit IPython, confirming if configured to do so (like %exit)""" | ||
2908 | 2536 | |||
2909 | 2537 | self.shell.exit() | ||
2910 | 2538 | |||
2912 | 2539 | def magic_Exit(self, parameter_s=''): | 2535 | def magic_Exit(self, parameter_s=''): |
2913 | 2540 | """Exit IPython without confirmation.""" | 2536 | """Exit IPython without confirmation.""" |
2914 | 2541 | 2537 | ||
2915 | 2542 | self.shell.ask_exit() | 2538 | self.shell.ask_exit() |
2916 | 2543 | 2539 | ||
2917 | 2540 | # Add aliases as magics so all common forms work: exit, quit, Exit, Quit. | ||
2918 | 2541 | magic_exit = magic_quit = magic_Quit = magic_Exit | ||
2919 | 2542 | |||
2920 | 2544 | #...................................................................... | 2543 | #...................................................................... |
2921 | 2545 | # Functions to implement unix shell-type things | 2544 | # Functions to implement unix shell-type things |
2922 | 2546 | 2545 | ||
2923 | @@ -2685,11 +2684,12 @@ | |||
2924 | 2685 | else: | 2684 | else: |
2925 | 2686 | syscmdlist.append(ff) | 2685 | syscmdlist.append(ff) |
2926 | 2687 | else: | 2686 | else: |
2927 | 2687 | no_alias = self.shell.alias_manager.no_alias | ||
2928 | 2688 | for pdir in path: | 2688 | for pdir in path: |
2929 | 2689 | os.chdir(pdir) | 2689 | os.chdir(pdir) |
2930 | 2690 | for ff in os.listdir(pdir): | 2690 | for ff in os.listdir(pdir): |
2931 | 2691 | base, ext = os.path.splitext(ff) | 2691 | base, ext = os.path.splitext(ff) |
2933 | 2692 | if isexec(ff) and base.lower() not in self.shell.no_alias: | 2692 | if isexec(ff) and base.lower() not in no_alias: |
2934 | 2693 | if ext.lower() == '.exe': | 2693 | if ext.lower() == '.exe': |
2935 | 2694 | ff = base | 2694 | ff = base |
2936 | 2695 | try: | 2695 | try: |
2937 | @@ -3399,8 +3399,6 @@ | |||
2938 | 3399 | your existing IPython session. | 3399 | your existing IPython session. |
2939 | 3400 | """ | 3400 | """ |
2940 | 3401 | 3401 | ||
2941 | 3402 | # XXX - Fix this to have cleaner activate/deactivate calls. | ||
2942 | 3403 | from IPython.extensions import InterpreterPasteInput as ipaste | ||
2943 | 3404 | from IPython.utils.ipstruct import Struct | 3402 | from IPython.utils.ipstruct import Struct |
2944 | 3405 | 3403 | ||
2945 | 3406 | # Shorthands | 3404 | # Shorthands |
2946 | @@ -3423,8 +3421,6 @@ | |||
2947 | 3423 | 3421 | ||
2948 | 3424 | if mode == False: | 3422 | if mode == False: |
2949 | 3425 | # turn on | 3423 | # turn on |
2950 | 3426 | ipaste.activate_prefilter() | ||
2951 | 3427 | |||
2952 | 3428 | oc.prompt1.p_template = '>>> ' | 3424 | oc.prompt1.p_template = '>>> ' |
2953 | 3429 | oc.prompt2.p_template = '... ' | 3425 | oc.prompt2.p_template = '... ' |
2954 | 3430 | oc.prompt_out.p_template = '' | 3426 | oc.prompt_out.p_template = '' |
2955 | @@ -3438,13 +3434,11 @@ | |||
2956 | 3438 | oc.prompt_out.pad_left = False | 3434 | oc.prompt_out.pad_left = False |
2957 | 3439 | 3435 | ||
2958 | 3440 | shell.pprint = False | 3436 | shell.pprint = False |
2960 | 3441 | 3437 | ||
2961 | 3442 | shell.magic_xmode('Plain') | 3438 | shell.magic_xmode('Plain') |
2962 | 3443 | 3439 | ||
2963 | 3444 | else: | 3440 | else: |
2964 | 3445 | # turn off | 3441 | # turn off |
2965 | 3446 | ipaste.deactivate_prefilter() | ||
2966 | 3447 | |||
2967 | 3448 | oc.prompt1.p_template = shell.prompt_in1 | 3442 | oc.prompt1.p_template = shell.prompt_in1 |
2968 | 3449 | oc.prompt2.p_template = shell.prompt_in2 | 3443 | oc.prompt2.p_template = shell.prompt_in2 |
2969 | 3450 | oc.prompt_out.p_template = shell.prompt_out | 3444 | oc.prompt_out.p_template = shell.prompt_out |
2970 | @@ -3457,7 +3451,7 @@ | |||
2971 | 3457 | oc.prompt1.pad_left = oc.prompt2.pad_left = \ | 3451 | oc.prompt1.pad_left = oc.prompt2.pad_left = \ |
2972 | 3458 | oc.prompt_out.pad_left = dstore.rc_prompts_pad_left | 3452 | oc.prompt_out.pad_left = dstore.rc_prompts_pad_left |
2973 | 3459 | 3453 | ||
2975 | 3460 | rc.pprint = dstore.rc_pprint | 3454 | shell.pprint = dstore.rc_pprint |
2976 | 3461 | 3455 | ||
2977 | 3462 | shell.magic_xmode(dstore.xmode) | 3456 | shell.magic_xmode(dstore.xmode) |
2978 | 3463 | 3457 | ||
2979 | @@ -3475,7 +3469,7 @@ | |||
2980 | 3475 | using the (pylab/wthread/etc.) command line flags. GUI toolkits | 3469 | using the (pylab/wthread/etc.) command line flags. GUI toolkits |
2981 | 3476 | can now be enabled, disabled and swtiched at runtime and keyboard | 3470 | can now be enabled, disabled and swtiched at runtime and keyboard |
2982 | 3477 | interrupts should work without any problems. The following toolkits | 3471 | interrupts should work without any problems. The following toolkits |
2984 | 3478 | are supports: wxPython, PyQt4, PyGTK, and Tk:: | 3472 | are supported: wxPython, PyQt4, PyGTK, and Tk:: |
2985 | 3479 | 3473 | ||
2986 | 3480 | %gui wx # enable wxPython event loop integration | 3474 | %gui wx # enable wxPython event loop integration |
2987 | 3481 | %gui qt4|qt # enable PyQt4 event loop integration | 3475 | %gui qt4|qt # enable PyQt4 event loop integration |
2988 | @@ -3494,25 +3488,13 @@ | |||
2989 | 3494 | 3488 | ||
2990 | 3495 | This is highly recommended for most users. | 3489 | This is highly recommended for most users. |
2991 | 3496 | """ | 3490 | """ |
3007 | 3497 | from IPython.lib import inputhook | 3491 | opts, arg = self.parse_options(parameter_s,'a') |
3008 | 3498 | if "-a" in parameter_s: | 3492 | if arg=='': arg = None |
3009 | 3499 | app = True | 3493 | return enable_gui(arg, 'a' in opts) |
2995 | 3500 | else: | ||
2996 | 3501 | app = False | ||
2997 | 3502 | if not parameter_s: | ||
2998 | 3503 | inputhook.clear_inputhook() | ||
2999 | 3504 | elif 'wx' in parameter_s: | ||
3000 | 3505 | return inputhook.enable_wx(app) | ||
3001 | 3506 | elif ('qt4' in parameter_s) or ('qt' in parameter_s): | ||
3002 | 3507 | return inputhook.enable_qt4(app) | ||
3003 | 3508 | elif 'gtk' in parameter_s: | ||
3004 | 3509 | return inputhook.enable_gtk(app) | ||
3005 | 3510 | elif 'tk' in parameter_s: | ||
3006 | 3511 | return inputhook.enable_tk(app) | ||
3010 | 3512 | 3494 | ||
3011 | 3513 | def magic_load_ext(self, module_str): | 3495 | def magic_load_ext(self, module_str): |
3012 | 3514 | """Load an IPython extension by its module name.""" | 3496 | """Load an IPython extension by its module name.""" |
3014 | 3515 | self.load_extension(module_str) | 3497 | return self.load_extension(module_str) |
3015 | 3516 | 3498 | ||
3016 | 3517 | def magic_unload_ext(self, module_str): | 3499 | def magic_unload_ext(self, module_str): |
3017 | 3518 | """Unload an IPython extension by its module name.""" | 3500 | """Unload an IPython extension by its module name.""" |
3018 | @@ -3522,6 +3504,7 @@ | |||
3019 | 3522 | """Reload an IPython extension by its module name.""" | 3504 | """Reload an IPython extension by its module name.""" |
3020 | 3523 | self.reload_extension(module_str) | 3505 | self.reload_extension(module_str) |
3021 | 3524 | 3506 | ||
3022 | 3507 | @testdec.skip_doctest | ||
3023 | 3525 | def magic_install_profiles(self, s): | 3508 | def magic_install_profiles(self, s): |
3024 | 3526 | """Install the default IPython profiles into the .ipython dir. | 3509 | """Install the default IPython profiles into the .ipython dir. |
3025 | 3527 | 3510 | ||
3026 | @@ -3576,5 +3559,58 @@ | |||
3027 | 3576 | shutil.copy(src, dst) | 3559 | shutil.copy(src, dst) |
3028 | 3577 | print "Installing default config file: %s" % dst | 3560 | print "Installing default config file: %s" % dst |
3029 | 3578 | 3561 | ||
3030 | 3562 | # Pylab support: simple wrappers that activate pylab, load gui input | ||
3031 | 3563 | # handling and modify slightly %run | ||
3032 | 3564 | |||
3033 | 3565 | @testdec.skip_doctest | ||
3034 | 3566 | def _pylab_magic_run(self, parameter_s=''): | ||
3035 | 3567 | Magic.magic_run(self, parameter_s, | ||
3036 | 3568 | runner=mpl_runner(self.shell.safe_execfile)) | ||
3037 | 3569 | |||
3038 | 3570 | _pylab_magic_run.__doc__ = magic_run.__doc__ | ||
3039 | 3571 | |||
3040 | 3572 | @testdec.skip_doctest | ||
3041 | 3573 | def magic_pylab(self, s): | ||
3042 | 3574 | """Load numpy and matplotlib to work interactively. | ||
3043 | 3575 | |||
3044 | 3576 | %pylab [GUINAME] | ||
3045 | 3577 | |||
3046 | 3578 | This function lets you activate pylab (matplotlib, numpy and | ||
3047 | 3579 | interactive support) at any point during an IPython session. | ||
3048 | 3580 | |||
3049 | 3581 | It will import at the top level numpy as np, pyplot as plt, matplotlib, | ||
3050 | 3582 | pylab and mlab, as well as all names from numpy and pylab. | ||
3051 | 3583 | |||
3052 | 3584 | Parameters | ||
3053 | 3585 | ---------- | ||
3054 | 3586 | guiname : optional | ||
3055 | 3587 | One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk' or | ||
3056 | 3588 | 'tk'). If given, the corresponding Matplotlib backend is used, | ||
3057 | 3589 | otherwise matplotlib's default (which you can override in your | ||
3058 | 3590 | matplotlib config file) is used. | ||
3059 | 3591 | |||
3060 | 3592 | Examples | ||
3061 | 3593 | -------- | ||
3062 | 3594 | In this case, where the MPL default is TkAgg: | ||
3063 | 3595 | In [2]: %pylab | ||
3064 | 3596 | |||
3065 | 3597 | Welcome to pylab, a matplotlib-based Python environment. | ||
3066 | 3598 | Backend in use: TkAgg | ||
3067 | 3599 | For more information, type 'help(pylab)'. | ||
3068 | 3600 | |||
3069 | 3601 | But you can explicitly request a different backend: | ||
3070 | 3602 | In [3]: %pylab qt | ||
3071 | 3603 | |||
3072 | 3604 | Welcome to pylab, a matplotlib-based Python environment. | ||
3073 | 3605 | Backend in use: Qt4Agg | ||
3074 | 3606 | For more information, type 'help(pylab)'. | ||
3075 | 3607 | """ | ||
3076 | 3608 | self.shell.enable_pylab(s) | ||
3077 | 3609 | |||
3078 | 3610 | def magic_tb(self, s): | ||
3079 | 3611 | """Print the last traceback with the currently active exception mode. | ||
3080 | 3612 | |||
3081 | 3613 | See %xmode for changing exception reporting modes.""" | ||
3082 | 3614 | self.shell.showtraceback() | ||
3083 | 3579 | 3615 | ||
3084 | 3580 | # end Magic | 3616 | # end Magic |
3085 | 3581 | 3617 | ||
3086 | === modified file 'IPython/core/prefilter.py' | |||
3087 | --- IPython/core/prefilter.py 2009-11-15 07:37:49 +0000 | |||
3088 | +++ IPython/core/prefilter.py 2010-01-18 01:17:11 +0000 | |||
3089 | @@ -158,7 +158,7 @@ | |||
3090 | 158 | without worrying about *further* damaging state. | 158 | without worrying about *further* damaging state. |
3091 | 159 | """ | 159 | """ |
3092 | 160 | if not self._oinfo: | 160 | if not self._oinfo: |
3094 | 161 | self._oinfo = ip._ofind(self.ifun) | 161 | self._oinfo = ip.shell._ofind(self.ifun) |
3095 | 162 | return self._oinfo | 162 | return self._oinfo |
3096 | 163 | 163 | ||
3097 | 164 | def __str__(self): | 164 | def __str__(self): |
3098 | @@ -362,7 +362,7 @@ | |||
3099 | 362 | line = transformer.transform(line, continue_prompt) | 362 | line = transformer.transform(line, continue_prompt) |
3100 | 363 | return line | 363 | return line |
3101 | 364 | 364 | ||
3103 | 365 | def prefilter_line(self, line, continue_prompt): | 365 | def prefilter_line(self, line, continue_prompt=False): |
3104 | 366 | """Prefilter a single input line as text. | 366 | """Prefilter a single input line as text. |
3105 | 367 | 367 | ||
3106 | 368 | This method prefilters a single line of text by calling the | 368 | This method prefilters a single line of text by calling the |
3107 | @@ -416,7 +416,7 @@ | |||
3108 | 416 | # print "prefiltered line: %r" % prefiltered | 416 | # print "prefiltered line: %r" % prefiltered |
3109 | 417 | return prefiltered | 417 | return prefiltered |
3110 | 418 | 418 | ||
3112 | 419 | def prefilter_lines(self, lines, continue_prompt): | 419 | def prefilter_lines(self, lines, continue_prompt=False): |
3113 | 420 | """Prefilter multiple input lines of text. | 420 | """Prefilter multiple input lines of text. |
3114 | 421 | 421 | ||
3115 | 422 | This is the main entry point for prefiltering multiple lines of | 422 | This is the main entry point for prefiltering multiple lines of |
3116 | @@ -427,11 +427,19 @@ | |||
3117 | 427 | which is the case when the user goes back to a multiline history | 427 | which is the case when the user goes back to a multiline history |
3118 | 428 | entry and presses enter. | 428 | entry and presses enter. |
3119 | 429 | """ | 429 | """ |
3125 | 430 | out = [] | 430 | llines = lines.rstrip('\n').split('\n') |
3126 | 431 | for line in lines.rstrip('\n').split('\n'): | 431 | # We can get multiple lines in one shot, where multiline input 'blends' |
3127 | 432 | out.append(self.prefilter_line(line, continue_prompt)) | 432 | # into one line, in cases like recalling from the readline history |
3128 | 433 | return '\n'.join(out) | 433 | # buffer. We need to make sure that in such cases, we correctly |
3129 | 434 | 434 | # communicate downstream which line is first and which are continuation | |
3130 | 435 | # ones. | ||
3131 | 436 | if len(llines) > 1: | ||
3132 | 437 | out = '\n'.join([self.prefilter_line(line, lnum>0) | ||
3133 | 438 | for lnum, line in enumerate(llines) ]) | ||
3134 | 439 | else: | ||
3135 | 440 | out = self.prefilter_line(llines[0], continue_prompt) | ||
3136 | 441 | |||
3137 | 442 | return out | ||
3138 | 435 | 443 | ||
3139 | 436 | #----------------------------------------------------------------------------- | 444 | #----------------------------------------------------------------------------- |
3140 | 437 | # Prefilter transformers | 445 | # Prefilter transformers |
3141 | @@ -508,6 +516,47 @@ | |||
3142 | 508 | return line | 516 | return line |
3143 | 509 | 517 | ||
3144 | 510 | 518 | ||
3145 | 519 | _classic_prompt_re = re.compile(r'(^[ \t]*>>> |^[ \t]*\.\.\. )') | ||
3146 | 520 | |||
3147 | 521 | class PyPromptTransformer(PrefilterTransformer): | ||
3148 | 522 | """Handle inputs that start with '>>> ' syntax.""" | ||
3149 | 523 | |||
3150 | 524 | priority = Int(50, config=True) | ||
3151 | 525 | |||
3152 | 526 | def transform(self, line, continue_prompt): | ||
3153 | 527 | |||
3154 | 528 | if not line or line.isspace() or line.strip() == '...': | ||
3155 | 529 | # This allows us to recognize multiple input prompts separated by | ||
3156 | 530 | # blank lines and pasted in a single chunk, very common when | ||
3157 | 531 | # pasting doctests or long tutorial passages. | ||
3158 | 532 | return '' | ||
3159 | 533 | m = _classic_prompt_re.match(line) | ||
3160 | 534 | if m: | ||
3161 | 535 | return line[len(m.group(0)):] | ||
3162 | 536 | else: | ||
3163 | 537 | return line | ||
3164 | 538 | |||
3165 | 539 | |||
3166 | 540 | _ipy_prompt_re = re.compile(r'(^[ \t]*In \[\d+\]: |^[ \t]*\ \ \ \.\.\.+: )') | ||
3167 | 541 | |||
3168 | 542 | class IPyPromptTransformer(PrefilterTransformer): | ||
3169 | 543 | """Handle inputs that start classic IPython prompt syntax.""" | ||
3170 | 544 | |||
3171 | 545 | priority = Int(50, config=True) | ||
3172 | 546 | |||
3173 | 547 | def transform(self, line, continue_prompt): | ||
3174 | 548 | |||
3175 | 549 | if not line or line.isspace() or line.strip() == '...': | ||
3176 | 550 | # This allows us to recognize multiple input prompts separated by | ||
3177 | 551 | # blank lines and pasted in a single chunk, very common when | ||
3178 | 552 | # pasting doctests or long tutorial passages. | ||
3179 | 553 | return '' | ||
3180 | 554 | m = _ipy_prompt_re.match(line) | ||
3181 | 555 | if m: | ||
3182 | 556 | return line[len(m.group(0)):] | ||
3183 | 557 | else: | ||
3184 | 558 | return line | ||
3185 | 559 | |||
3186 | 511 | #----------------------------------------------------------------------------- | 560 | #----------------------------------------------------------------------------- |
3187 | 512 | # Prefilter checkers | 561 | # Prefilter checkers |
3188 | 513 | #----------------------------------------------------------------------------- | 562 | #----------------------------------------------------------------------------- |
3189 | @@ -755,9 +804,17 @@ | |||
3190 | 755 | line = line_info.line | 804 | line = line_info.line |
3191 | 756 | continue_prompt = line_info.continue_prompt | 805 | continue_prompt = line_info.continue_prompt |
3192 | 757 | 806 | ||
3196 | 758 | if (continue_prompt and self.shell.autoindent and line.isspace() and | 807 | if (continue_prompt and |
3197 | 759 | (0 < abs(len(line) - self.shell.indent_current_nsp) <= 2 or | 808 | self.shell.autoindent and |
3198 | 760 | (self.shell.buffer[-1]).isspace() )): | 809 | line.isspace() and |
3199 | 810 | |||
3200 | 811 | (0 < abs(len(line) - self.shell.indent_current_nsp) <= 2 | ||
3201 | 812 | or | ||
3202 | 813 | not self.shell.buffer | ||
3203 | 814 | or | ||
3204 | 815 | (self.shell.buffer[-1]).isspace() | ||
3205 | 816 | ) | ||
3206 | 817 | ): | ||
3207 | 761 | line = '' | 818 | line = '' |
3208 | 762 | 819 | ||
3209 | 763 | self.shell.log(line, line, continue_prompt) | 820 | self.shell.log(line, line, continue_prompt) |
3210 | @@ -845,12 +902,11 @@ | |||
3211 | 845 | pre = line_info.pre | 902 | pre = line_info.pre |
3212 | 846 | continue_prompt = line_info.continue_prompt | 903 | continue_prompt = line_info.continue_prompt |
3213 | 847 | obj = line_info.ofind(self)['obj'] | 904 | obj = line_info.ofind(self)['obj'] |
3214 | 848 | |||
3215 | 849 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun,the_rest) # dbg | 905 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun,the_rest) # dbg |
3216 | 850 | 906 | ||
3217 | 851 | # This should only be active for single-line input! | 907 | # This should only be active for single-line input! |
3218 | 852 | if continue_prompt: | 908 | if continue_prompt: |
3220 | 853 | self.log(line,line,continue_prompt) | 909 | self.shell.log(line,line,continue_prompt) |
3221 | 854 | return line | 910 | return line |
3222 | 855 | 911 | ||
3223 | 856 | force_auto = isinstance(obj, IPyAutocall) | 912 | force_auto = isinstance(obj, IPyAutocall) |
3224 | @@ -967,7 +1023,9 @@ | |||
3225 | 967 | 1023 | ||
3226 | 968 | _default_transformers = [ | 1024 | _default_transformers = [ |
3227 | 969 | AssignSystemTransformer, | 1025 | AssignSystemTransformer, |
3229 | 970 | AssignMagicTransformer | 1026 | AssignMagicTransformer, |
3230 | 1027 | PyPromptTransformer, | ||
3231 | 1028 | IPyPromptTransformer, | ||
3232 | 971 | ] | 1029 | ] |
3233 | 972 | 1030 | ||
3234 | 973 | _default_checkers = [ | 1031 | _default_checkers = [ |
3235 | @@ -992,4 +1050,3 @@ | |||
3236 | 992 | HelpHandler, | 1050 | HelpHandler, |
3237 | 993 | EmacsHandler | 1051 | EmacsHandler |
3238 | 994 | ] | 1052 | ] |
3239 | 995 | |||
3240 | 996 | 1053 | ||
3241 | === modified file 'IPython/core/prompts.py' | |||
3242 | --- IPython/core/prompts.py 2009-09-12 15:58:55 +0000 | |||
3243 | +++ IPython/core/prompts.py 2010-01-18 01:17:11 +0000 | |||
3244 | @@ -131,8 +131,14 @@ | |||
3245 | 131 | # Prompt/history count, with the actual digits replaced by dots. Used | 131 | # Prompt/history count, with the actual digits replaced by dots. Used |
3246 | 132 | # mainly in continuation prompts (prompt_in2) | 132 | # mainly in continuation prompts (prompt_in2) |
3247 | 133 | #r'\D': '${"."*len(str(self.cache.prompt_count))}', | 133 | #r'\D': '${"."*len(str(self.cache.prompt_count))}', |
3250 | 134 | # More robust form of the above expression, that uses __builtins__ | 134 | |
3251 | 135 | r'\D': '${"."*__builtins__.len(__builtins__.str(self.cache.prompt_count))}', | 135 | # More robust form of the above expression, that uses the __builtin__ |
3252 | 136 | # module. Note that we can NOT use __builtins__ (note the 's'), because | ||
3253 | 137 | # that can either be a dict or a module, and can even mutate at runtime, | ||
3254 | 138 | # depending on the context (Python makes no guarantees on it). In | ||
3255 | 139 | # contrast, __builtin__ is always a module object, though it must be | ||
3256 | 140 | # explicitly imported. | ||
3257 | 141 | r'\D': '${"."*__builtin__.len(__builtin__.str(self.cache.prompt_count))}', | ||
3258 | 136 | 142 | ||
3259 | 137 | # Current working directory | 143 | # Current working directory |
3260 | 138 | r'\w': '${os.getcwd()}', | 144 | r'\w': '${os.getcwd()}', |
3261 | @@ -215,6 +221,7 @@ | |||
3262 | 215 | out = '<ERROR: %s>' % msg | 221 | out = '<ERROR: %s>' % msg |
3263 | 216 | except Exception,msg: | 222 | except Exception,msg: |
3264 | 217 | out = '<ERROR: %s>' % msg | 223 | out = '<ERROR: %s>' % msg |
3265 | 224 | #raise # dbg | ||
3266 | 218 | return out | 225 | return out |
3267 | 219 | 226 | ||
3268 | 220 | class BasePrompt(object): | 227 | class BasePrompt(object): |
3269 | @@ -549,18 +556,23 @@ | |||
3270 | 549 | # print "Got prompt: ", outprompt | 556 | # print "Got prompt: ", outprompt |
3271 | 550 | if self.do_full_cache: | 557 | if self.do_full_cache: |
3272 | 551 | cout_write(outprompt) | 558 | cout_write(outprompt) |
3273 | 552 | else: | ||
3274 | 553 | print "self.do_full_cache = False" | ||
3275 | 554 | 559 | ||
3278 | 555 | # and now call a possibly user-defined print mechanism | 560 | # and now call a possibly user-defined print mechanism. Note that |
3279 | 556 | manipulated_val = self.display(arg) | 561 | # self.display typically prints as a side-effect, we don't do any |
3280 | 562 | # printing to stdout here. | ||
3281 | 563 | try: | ||
3282 | 564 | manipulated_val = self.display(arg) | ||
3283 | 565 | except TypeError: | ||
3284 | 566 | # If the user's display hook didn't return a string we can | ||
3285 | 567 | # print, we're done. Happens commonly if they return None | ||
3286 | 568 | cout_write('\n') | ||
3287 | 569 | return | ||
3288 | 557 | 570 | ||
3289 | 558 | # user display hooks can change the variable to be stored in | 571 | # user display hooks can change the variable to be stored in |
3290 | 559 | # output history | 572 | # output history |
3291 | 560 | |||
3292 | 561 | if manipulated_val is not None: | 573 | if manipulated_val is not None: |
3293 | 562 | arg = manipulated_val | 574 | arg = manipulated_val |
3295 | 563 | 575 | ||
3296 | 564 | # avoid recursive reference when displaying _oh/Out | 576 | # avoid recursive reference when displaying _oh/Out |
3297 | 565 | if arg is not self.user_ns['_oh']: | 577 | if arg is not self.user_ns['_oh']: |
3298 | 566 | self.update(arg) | 578 | self.update(arg) |
3299 | 567 | 579 | ||
3300 | === added file 'IPython/core/pylabtools.py' | |||
3301 | --- IPython/core/pylabtools.py 1970-01-01 00:00:00 +0000 | |||
3302 | +++ IPython/core/pylabtools.py 2010-01-18 01:17:11 +0000 | |||
3303 | @@ -0,0 +1,145 @@ | |||
3304 | 1 | # -*- coding: utf-8 -*- | ||
3305 | 2 | """Pylab (matplotlib) support utilities. | ||
3306 | 3 | |||
3307 | 4 | Authors | ||
3308 | 5 | ------- | ||
3309 | 6 | Fernando Perez. | ||
3310 | 7 | """ | ||
3311 | 8 | |||
3312 | 9 | #----------------------------------------------------------------------------- | ||
3313 | 10 | # Copyright (C) 2009 The IPython Development Team | ||
3314 | 11 | # | ||
3315 | 12 | # Distributed under the terms of the BSD License. The full license is in | ||
3316 | 13 | # the file COPYING, distributed as part of this software. | ||
3317 | 14 | #----------------------------------------------------------------------------- | ||
3318 | 15 | #----------------------------------------------------------------------------- | ||
3319 | 16 | # Imports | ||
3320 | 17 | #----------------------------------------------------------------------------- | ||
3321 | 18 | from IPython.utils.genutils import flag_calls | ||
3322 | 19 | |||
3323 | 20 | #----------------------------------------------------------------------------- | ||
3324 | 21 | # Main classes and functions | ||
3325 | 22 | #----------------------------------------------------------------------------- | ||
3326 | 23 | |||
3327 | 24 | def pylab_activate(user_ns, gui=None, import_all=True): | ||
3328 | 25 | """Activate pylab mode in the user's namespace. | ||
3329 | 26 | |||
3330 | 27 | Loads and initializes numpy, matplotlib and friends for interactive use. | ||
3331 | 28 | |||
3332 | 29 | Parameters | ||
3333 | 30 | ---------- | ||
3334 | 31 | user_ns : dict | ||
3335 | 32 | Namespace where the imports will occur. | ||
3336 | 33 | |||
3337 | 34 | gui : optional, string | ||
3338 | 35 | A valid gui name following the conventions of the %gui magic. | ||
3339 | 36 | |||
3340 | 37 | import_all : optional, boolean | ||
3341 | 38 | If true, an 'import *' is done from numpy and pylab. | ||
3342 | 39 | |||
3343 | 40 | Returns | ||
3344 | 41 | ------- | ||
3345 | 42 | The actual gui used (if not given as input, it was obtained from matplotlib | ||
3346 | 43 | itself, and will be needed next to configure IPython's gui integration. | ||
3347 | 44 | """ | ||
3348 | 45 | |||
3349 | 46 | # Initialize matplotlib to interactive mode always | ||
3350 | 47 | import matplotlib | ||
3351 | 48 | |||
3352 | 49 | # If user specifies a GUI, that dictates the backend, otherwise we read the | ||
3353 | 50 | # user's mpl default from the mpl rc structure | ||
3354 | 51 | g2b = {'tk': 'TkAgg', | ||
3355 | 52 | 'gtk': 'GTKAgg', | ||
3356 | 53 | 'wx': 'WXAgg', | ||
3357 | 54 | 'qt': 'Qt4Agg', # qt3 not supported | ||
3358 | 55 | 'qt4': 'Qt4Agg' } | ||
3359 | 56 | |||
3360 | 57 | if gui: | ||
3361 | 58 | # select backend based on requested gui | ||
3362 | 59 | backend = g2b[gui] | ||
3363 | 60 | else: | ||
3364 | 61 | backend = matplotlib.rcParams['backend'] | ||
3365 | 62 | # In this case, we need to find what the appropriate gui selection call | ||
3366 | 63 | # should be for IPython, so we can activate inputhook accordingly | ||
3367 | 64 | b2g = dict(zip(g2b.values(),g2b.keys())) | ||
3368 | 65 | gui = b2g[backend] | ||
3369 | 66 | |||
3370 | 67 | # We must set the desired backend before importing pylab | ||
3371 | 68 | matplotlib.use(backend) | ||
3372 | 69 | |||
3373 | 70 | # This must be imported last in the matplotlib series, after | ||
3374 | 71 | # backend/interactivity choices have been made | ||
3375 | 72 | import matplotlib.pylab as pylab | ||
3376 | 73 | |||
3377 | 74 | # XXX For now leave this commented out, but depending on discussions with | ||
3378 | 75 | # mpl-dev, we may be able to allow interactive switching... | ||
3379 | 76 | #import matplotlib.pyplot | ||
3380 | 77 | #matplotlib.pyplot.switch_backend(backend) | ||
3381 | 78 | |||
3382 | 79 | pylab.show._needmain = False | ||
3383 | 80 | # We need to detect at runtime whether show() is called by the user. | ||
3384 | 81 | # For this, we wrap it into a decorator which adds a 'called' flag. | ||
3385 | 82 | pylab.draw_if_interactive = flag_calls(pylab.draw_if_interactive) | ||
3386 | 83 | |||
3387 | 84 | # Import numpy as np/pyplot as plt are conventions we're trying to | ||
3388 | 85 | # somewhat standardize on. Making them available to users by default | ||
3389 | 86 | # will greatly help this. | ||
3390 | 87 | exec ("import numpy\n" | ||
3391 | 88 | "import matplotlib\n" | ||
3392 | 89 | "from matplotlib import pylab, mlab, pyplot\n" | ||
3393 | 90 | "np = numpy\n" | ||
3394 | 91 | "plt = pyplot\n" | ||
3395 | 92 | ) in user_ns | ||
3396 | 93 | |||
3397 | 94 | if import_all: | ||
3398 | 95 | exec("from matplotlib.pylab import *\n" | ||
3399 | 96 | "from numpy import *\n") in user_ns | ||
3400 | 97 | |||
3401 | 98 | matplotlib.interactive(True) | ||
3402 | 99 | |||
3403 | 100 | print """ | ||
3404 | 101 | Welcome to pylab, a matplotlib-based Python environment [backend: %s]. | ||
3405 | 102 | For more information, type 'help(pylab)'.""" % backend | ||
3406 | 103 | |||
3407 | 104 | return gui | ||
3408 | 105 | |||
3409 | 106 | # We need a little factory function here to create the closure where | ||
3410 | 107 | # safe_execfile can live. | ||
3411 | 108 | def mpl_runner(safe_execfile): | ||
3412 | 109 | """Factory to return a matplotlib-enabled runner for %run. | ||
3413 | 110 | |||
3414 | 111 | Parameters | ||
3415 | 112 | ---------- | ||
3416 | 113 | safe_execfile : function | ||
3417 | 114 | This must be a function with the same interface as the | ||
3418 | 115 | :meth:`safe_execfile` method of IPython. | ||
3419 | 116 | |||
3420 | 117 | Returns | ||
3421 | 118 | ------- | ||
3422 | 119 | A function suitable for use as the ``runner`` argument of the %run magic | ||
3423 | 120 | function. | ||
3424 | 121 | """ | ||
3425 | 122 | |||
3426 | 123 | def mpl_execfile(fname,*where,**kw): | ||
3427 | 124 | """matplotlib-aware wrapper around safe_execfile. | ||
3428 | 125 | |||
3429 | 126 | Its interface is identical to that of the :func:`execfile` builtin. | ||
3430 | 127 | |||
3431 | 128 | This is ultimately a call to execfile(), but wrapped in safeties to | ||
3432 | 129 | properly handle interactive rendering.""" | ||
3433 | 130 | |||
3434 | 131 | import matplotlib | ||
3435 | 132 | import matplotlib.pylab as pylab | ||
3436 | 133 | |||
3437 | 134 | #print '*** Matplotlib runner ***' # dbg | ||
3438 | 135 | # turn off rendering until end of script | ||
3439 | 136 | is_interactive = matplotlib.rcParams['interactive'] | ||
3440 | 137 | matplotlib.interactive(False) | ||
3441 | 138 | safe_execfile(fname,*where,**kw) | ||
3442 | 139 | matplotlib.interactive(is_interactive) | ||
3443 | 140 | # make rendering call now, if the user tried to do it | ||
3444 | 141 | if pylab.draw_if_interactive.called: | ||
3445 | 142 | pylab.draw() | ||
3446 | 143 | pylab.draw_if_interactive.called = False | ||
3447 | 144 | |||
3448 | 145 | return mpl_execfile | ||
3449 | 0 | 146 | ||
3450 | === modified file 'IPython/core/quitter.py' (properties changed: -x to +x) | |||
3451 | --- IPython/core/quitter.py 2009-08-27 19:20:47 +0000 | |||
3452 | +++ IPython/core/quitter.py 2010-01-18 01:17:11 +0000 | |||
3453 | @@ -1,10 +1,10 @@ | |||
3456 | 1 | #!/usr/bin/env python | 1 | # coding: utf-8 |
3455 | 2 | # encoding: utf-8 | ||
3457 | 3 | """ | 2 | """ |
3458 | 4 | A simple class for quitting IPython. | 3 | A simple class for quitting IPython. |
3459 | 5 | 4 | ||
3462 | 6 | Authors: | 5 | Authors |
3463 | 7 | 6 | ------- | |
3464 | 7 | * Fernando Perez | ||
3465 | 8 | * Brian Granger | 8 | * Brian Granger |
3466 | 9 | """ | 9 | """ |
3467 | 10 | 10 | ||
3468 | @@ -19,6 +19,7 @@ | |||
3469 | 19 | # Imports | 19 | # Imports |
3470 | 20 | #----------------------------------------------------------------------------- | 20 | #----------------------------------------------------------------------------- |
3471 | 21 | 21 | ||
3472 | 22 | import sys | ||
3473 | 22 | 23 | ||
3474 | 23 | class Quitter(object): | 24 | class Quitter(object): |
3475 | 24 | """Simple class to handle exit, similar to Python 2.5's. | 25 | """Simple class to handle exit, similar to Python 2.5's. |
3476 | @@ -30,9 +31,13 @@ | |||
3477 | 30 | self.shell = shell | 31 | self.shell = shell |
3478 | 31 | self.name = name | 32 | self.name = name |
3479 | 32 | 33 | ||
3481 | 33 | def __repr__(self): | 34 | def __str__(self): |
3482 | 34 | return 'Type %s() to exit.' % self.name | 35 | return 'Type %s() to exit.' % self.name |
3483 | 35 | __str__ = __repr__ | ||
3484 | 36 | 36 | ||
3485 | 37 | def __call__(self): | 37 | def __call__(self): |
3486 | 38 | self.shell.exit() | ||
3487 | 39 | \ No newline at end of file | 38 | \ No newline at end of file |
3488 | 39 | self.shell.ask_exit() | ||
3489 | 40 | |||
3490 | 41 | # Repr MUST return a string, else display like pprint hooks get confused | ||
3491 | 42 | def __repr__(self): | ||
3492 | 43 | self.shell.ask_exit() | ||
3493 | 44 | return 'Bye.' | ||
3494 | 40 | 45 | ||
3495 | === modified file 'IPython/core/release.py' | |||
3496 | --- IPython/core/release.py 2009-12-30 19:36:04 +0000 | |||
3497 | +++ IPython/core/release.py 2010-01-18 01:17:11 +0000 | |||
3498 | @@ -23,7 +23,7 @@ | |||
3499 | 23 | development = True # change this to False to do a release | 23 | development = True # change this to False to do a release |
3500 | 24 | version_base = '0.11' | 24 | version_base = '0.11' |
3501 | 25 | branch = 'ipython' | 25 | branch = 'ipython' |
3503 | 26 | revision = '1219' | 26 | revision = '1346' |
3504 | 27 | 27 | ||
3505 | 28 | if development: | 28 | if development: |
3506 | 29 | if branch == 'ipython': | 29 | if branch == 'ipython': |
3507 | 30 | 30 | ||
3508 | === removed file 'IPython/core/tests/obj_del.py' | |||
3509 | --- IPython/core/tests/obj_del.py 2009-09-12 15:58:55 +0000 | |||
3510 | +++ IPython/core/tests/obj_del.py 1970-01-01 00:00:00 +0000 | |||
3511 | @@ -1,35 +0,0 @@ | |||
3512 | 1 | """Test code for https://bugs.launchpad.net/ipython/+bug/239054 | ||
3513 | 2 | |||
3514 | 3 | WARNING: this script exits IPython! It MUST be run in a subprocess. | ||
3515 | 4 | |||
3516 | 5 | When you run the following script from CPython it prints: | ||
3517 | 6 | __init__ is here | ||
3518 | 7 | __del__ is here | ||
3519 | 8 | |||
3520 | 9 | and creates the __del__.txt file | ||
3521 | 10 | |||
3522 | 11 | When you run it from IPython it prints: | ||
3523 | 12 | __init__ is here | ||
3524 | 13 | |||
3525 | 14 | When you exit() or Exit from IPython neothing is printed and no file is created | ||
3526 | 15 | (the file thing is to make sure __del__ is really never called and not that | ||
3527 | 16 | just the output is eaten). | ||
3528 | 17 | |||
3529 | 18 | Note that if you call %reset in IPython then everything is Ok. | ||
3530 | 19 | |||
3531 | 20 | IPython should do the equivalent of %reset and release all the references it | ||
3532 | 21 | holds before exit. This behavior is important when working with binding objects | ||
3533 | 22 | that rely on __del__. If the current behavior has some use case then I suggest | ||
3534 | 23 | to add a configuration option to IPython to control it. | ||
3535 | 24 | """ | ||
3536 | 25 | import sys | ||
3537 | 26 | |||
3538 | 27 | class A(object): | ||
3539 | 28 | def __del__(self): | ||
3540 | 29 | print 'obj_del.py: object A deleted' | ||
3541 | 30 | |||
3542 | 31 | a = A() | ||
3543 | 32 | |||
3544 | 33 | # Now, we force an exit, the caller will check that the del printout was given | ||
3545 | 34 | _ip = get_ipython() | ||
3546 | 35 | _ip.ask_exit() | ||
3547 | 36 | 0 | ||
3548 | === added file 'IPython/core/tests/simpleerr.py' | |||
3549 | --- IPython/core/tests/simpleerr.py 1970-01-01 00:00:00 +0000 | |||
3550 | +++ IPython/core/tests/simpleerr.py 2010-01-18 01:17:11 +0000 | |||
3551 | @@ -0,0 +1,32 @@ | |||
3552 | 1 | """Error script. DO NOT EDIT FURTHER! It will break exception doctests!!!""" | ||
3553 | 2 | import sys | ||
3554 | 3 | |||
3555 | 4 | def div0(): | ||
3556 | 5 | "foo" | ||
3557 | 6 | x = 1 | ||
3558 | 7 | y = 0 | ||
3559 | 8 | x/y | ||
3560 | 9 | |||
3561 | 10 | def sysexit(stat, mode): | ||
3562 | 11 | raise SystemExit(stat, 'Mode = %s' % mode) | ||
3563 | 12 | |||
3564 | 13 | def bar(mode): | ||
3565 | 14 | "bar" | ||
3566 | 15 | if mode=='div': | ||
3567 | 16 | div0() | ||
3568 | 17 | elif mode=='exit': | ||
3569 | 18 | try: | ||
3570 | 19 | stat = int(sys.argv[2]) | ||
3571 | 20 | except: | ||
3572 | 21 | stat = 1 | ||
3573 | 22 | sysexit(stat, mode) | ||
3574 | 23 | else: | ||
3575 | 24 | raise ValueError('Unknown mode') | ||
3576 | 25 | |||
3577 | 26 | if __name__ == '__main__': | ||
3578 | 27 | try: | ||
3579 | 28 | mode = sys.argv[1] | ||
3580 | 29 | except IndexError: | ||
3581 | 30 | mode = 'div' | ||
3582 | 31 | |||
3583 | 32 | bar(mode) | ||
3584 | 0 | 33 | ||
3585 | === modified file 'IPython/core/tests/tclass.py' | |||
3586 | --- IPython/core/tests/tclass.py 2009-07-02 18:59:10 +0000 | |||
3587 | +++ IPython/core/tests/tclass.py 2010-01-18 01:17:11 +0000 | |||
3588 | @@ -1,22 +1,19 @@ | |||
3590 | 1 | """Simple script to instantiate a class for testing %run""" | 1 | """Simple script to be run *twice*, to check reference counting bugs. |
3591 | 2 | |||
3592 | 3 | See test_run for details.""" | ||
3593 | 2 | 4 | ||
3594 | 3 | import sys | 5 | import sys |
3595 | 4 | 6 | ||
3605 | 5 | # An external test will check that calls to f() work after %run | 7 | # We want to ensure that while objects remain available for immediate access, |
3606 | 6 | class foo: pass | 8 | # objects from *previous* runs of the same script get collected, to avoid |
3607 | 7 | 9 | # accumulating massive amounts of old references. | |
3599 | 8 | def f(): | ||
3600 | 9 | return foo() | ||
3601 | 10 | |||
3602 | 11 | # We also want to ensure that while objects remain available for immediate | ||
3603 | 12 | # access, objects from *previous* runs of the same script get collected, to | ||
3604 | 13 | # avoid accumulating massive amounts of old references. | ||
3608 | 14 | class C(object): | 10 | class C(object): |
3609 | 15 | def __init__(self,name): | 11 | def __init__(self,name): |
3610 | 16 | self.name = name | 12 | self.name = name |
3611 | 17 | 13 | ||
3612 | 18 | def __del__(self): | 14 | def __del__(self): |
3613 | 19 | print 'tclass.py: deleting object:',self.name | 15 | print 'tclass.py: deleting object:',self.name |
3614 | 16 | sys.stdout.flush() | ||
3615 | 20 | 17 | ||
3616 | 21 | try: | 18 | try: |
3617 | 22 | name = sys.argv[1] | 19 | name = sys.argv[1] |
3618 | @@ -25,3 +22,10 @@ | |||
3619 | 25 | else: | 22 | else: |
3620 | 26 | if name.startswith('C'): | 23 | if name.startswith('C'): |
3621 | 27 | c = C(name) | 24 | c = C(name) |
3622 | 25 | |||
3623 | 26 | #print >> sys.stderr, "ARGV:", sys.argv # dbg | ||
3624 | 27 | |||
3625 | 28 | # This next print statement is NOT debugging, we're making the check on a | ||
3626 | 29 | # completely separate process so we verify by capturing stdout: | ||
3627 | 30 | print 'ARGV 1-:', sys.argv[1:] | ||
3628 | 31 | sys.stdout.flush() | ||
3629 | 28 | 32 | ||
3630 | === added file 'IPython/core/tests/test_completer.py' | |||
3631 | --- IPython/core/tests/test_completer.py 1970-01-01 00:00:00 +0000 | |||
3632 | +++ IPython/core/tests/test_completer.py 2010-01-18 01:17:11 +0000 | |||
3633 | @@ -0,0 +1,35 @@ | |||
3634 | 1 | """Tests for the IPython tab-completion machinery. | ||
3635 | 2 | """ | ||
3636 | 3 | #----------------------------------------------------------------------------- | ||
3637 | 4 | # Module imports | ||
3638 | 5 | #----------------------------------------------------------------------------- | ||
3639 | 6 | |||
3640 | 7 | # stdlib | ||
3641 | 8 | import sys | ||
3642 | 9 | |||
3643 | 10 | # third party | ||
3644 | 11 | import nose.tools as nt | ||
3645 | 12 | |||
3646 | 13 | # our own packages | ||
3647 | 14 | from IPython.core import completer | ||
3648 | 15 | |||
3649 | 16 | #----------------------------------------------------------------------------- | ||
3650 | 17 | # Test functions | ||
3651 | 18 | #----------------------------------------------------------------------------- | ||
3652 | 19 | def test_protect_filename(): | ||
3653 | 20 | pairs = [ ('abc','abc'), | ||
3654 | 21 | (' abc',r'\ abc'), | ||
3655 | 22 | ('a bc',r'a\ bc'), | ||
3656 | 23 | ('a bc',r'a\ \ bc'), | ||
3657 | 24 | (' bc',r'\ \ bc'), | ||
3658 | 25 | ] | ||
3659 | 26 | # On posix, we also protect parens | ||
3660 | 27 | if sys.platform != 'win32': | ||
3661 | 28 | pairs.extend( [('a(bc',r'a\(bc'), | ||
3662 | 29 | ('a)bc',r'a\)bc'), | ||
3663 | 30 | ('a( )bc',r'a\(\ \)bc'), | ||
3664 | 31 | ] ) | ||
3665 | 32 | # run the actual tests | ||
3666 | 33 | for s1, s2 in pairs: | ||
3667 | 34 | s1p = completer.protect_filename(s1) | ||
3668 | 35 | nt.assert_equals(s1p, s2) | ||
3669 | 0 | 36 | ||
3670 | === modified file 'IPython/core/tests/test_iplib.py' | |||
3671 | --- IPython/core/tests/test_iplib.py 2009-11-09 01:49:24 +0000 | |||
3672 | +++ IPython/core/tests/test_iplib.py 2010-01-18 01:17:11 +0000 | |||
3673 | @@ -13,45 +13,233 @@ | |||
3674 | 13 | import nose.tools as nt | 13 | import nose.tools as nt |
3675 | 14 | 14 | ||
3676 | 15 | # our own packages | 15 | # our own packages |
3680 | 16 | from IPython.core import iplib | 16 | from IPython.testing import decorators as dec |
3681 | 17 | from IPython.core import ipapi | 17 | from IPython.testing.globalipapp import get_ipython |
3679 | 18 | |||
3682 | 19 | 18 | ||
3683 | 20 | #----------------------------------------------------------------------------- | 19 | #----------------------------------------------------------------------------- |
3684 | 21 | # Globals | 20 | # Globals |
3685 | 22 | #----------------------------------------------------------------------------- | 21 | #----------------------------------------------------------------------------- |
3686 | 23 | 22 | ||
3704 | 24 | # Useful global ipapi object and main IPython one. Unfortunately we have a | 23 | # Get the public instance of IPython |
3705 | 25 | # long precedent of carrying the 'ipapi' global object which is injected into | 24 | ip = get_ipython() |
3689 | 26 | # the system namespace as _ip, but that keeps a pointer to the actual IPython | ||
3690 | 27 | # InteractiveShell instance, which is named IP. Since in testing we do need | ||
3691 | 28 | # access to the real thing (we want to probe beyond what ipapi exposes), make | ||
3692 | 29 | # here a global reference to each. In general, things that are exposed by the | ||
3693 | 30 | # ipapi instance should be read from there, but we also will often need to use | ||
3694 | 31 | # the actual IPython one. | ||
3695 | 32 | |||
3696 | 33 | # Get the public instance of IPython, and if it's None, make one so we can use | ||
3697 | 34 | # it for testing | ||
3698 | 35 | ip = ipapi.get() | ||
3699 | 36 | if ip is None: | ||
3700 | 37 | # IPython not running yet, make one from the testing machinery for | ||
3701 | 38 | # consistency when the test suite is being run via iptest | ||
3702 | 39 | from IPython.testing.plugin import ipdoctest | ||
3703 | 40 | ip = ipapi.get() | ||
3706 | 41 | 25 | ||
3707 | 42 | #----------------------------------------------------------------------------- | 26 | #----------------------------------------------------------------------------- |
3708 | 43 | # Test functions | 27 | # Test functions |
3709 | 44 | #----------------------------------------------------------------------------- | 28 | #----------------------------------------------------------------------------- |
3710 | 45 | 29 | ||
3711 | 30 | @dec.parametric | ||
3712 | 46 | def test_reset(): | 31 | def test_reset(): |
3713 | 47 | """reset must clear most namespaces.""" | 32 | """reset must clear most namespaces.""" |
3716 | 48 | ip.reset() # first, it should run without error | 33 | # The number of variables in the private user_config_ns is not zero, but it |
3717 | 49 | # Then, check that most namespaces end up empty | 34 | # should be constant regardless of what we do |
3718 | 35 | nvars_config_ns = len(ip.user_config_ns) | ||
3719 | 36 | |||
3720 | 37 | # Check that reset runs without error | ||
3721 | 38 | ip.reset() | ||
3722 | 39 | |||
3723 | 40 | # Once we've reset it (to clear of any junk that might have been there from | ||
3724 | 41 | # other tests, we can count how many variables are in the user's namespace | ||
3725 | 42 | nvars_user_ns = len(ip.user_ns) | ||
3726 | 43 | |||
3727 | 44 | # Now add a few variables to user_ns, and check that reset clears them | ||
3728 | 45 | ip.user_ns['x'] = 1 | ||
3729 | 46 | ip.user_ns['y'] = 1 | ||
3730 | 47 | ip.reset() | ||
3731 | 48 | |||
3732 | 49 | # Finally, check that all namespaces have only as many variables as we | ||
3733 | 50 | # expect to find in them: | ||
3734 | 50 | for ns in ip.ns_refs_table: | 51 | for ns in ip.ns_refs_table: |
3735 | 51 | if ns is ip.user_ns: | 52 | if ns is ip.user_ns: |
3736 | 52 | # The user namespace is reset with some data, so we can't check for | ||
3737 | 53 | # it being empty | ||
3738 | 54 | continue | ||
3739 | 55 | nt.assert_equals(len(ns),0) | ||
3740 | 56 | |||
3741 | 57 | |||
3742 | 58 | \ No newline at end of file | 53 | \ No newline at end of file |
3743 | 54 | nvars_expected = nvars_user_ns | ||
3744 | 55 | elif ns is ip.user_config_ns: | ||
3745 | 56 | nvars_expected = nvars_config_ns | ||
3746 | 57 | else: | ||
3747 | 58 | nvars_expected = 0 | ||
3748 | 59 | |||
3749 | 60 | yield nt.assert_equals(len(ns), nvars_expected) | ||
3750 | 61 | |||
3751 | 62 | |||
3752 | 63 | # Tests for reporting of exceptions in various modes, handling of SystemExit, | ||
3753 | 64 | # and %tb functionality. This is really a mix of testing ultraTB and iplib. | ||
3754 | 65 | |||
3755 | 66 | def doctest_tb_plain(): | ||
3756 | 67 | """ | ||
3757 | 68 | In [18]: xmode plain | ||
3758 | 69 | Exception reporting mode: Plain | ||
3759 | 70 | |||
3760 | 71 | In [19]: run simpleerr.py | ||
3761 | 72 | Traceback (most recent call last): | ||
3762 | 73 | ...line 32, in <module> | ||
3763 | 74 | bar(mode) | ||
3764 | 75 | ...line 16, in bar | ||
3765 | 76 | div0() | ||
3766 | 77 | ...line 8, in div0 | ||
3767 | 78 | x/y | ||
3768 | 79 | ZeroDivisionError: integer division or modulo by zero | ||
3769 | 80 | """ | ||
3770 | 81 | |||
3771 | 82 | |||
3772 | 83 | def doctest_tb_context(): | ||
3773 | 84 | """ | ||
3774 | 85 | In [3]: xmode context | ||
3775 | 86 | Exception reporting mode: Context | ||
3776 | 87 | |||
3777 | 88 | In [4]: run simpleerr.py | ||
3778 | 89 | --------------------------------------------------------------------------- | ||
3779 | 90 | ZeroDivisionError Traceback (most recent call last) | ||
3780 | 91 | <BLANKLINE> | ||
3781 | 92 | ... in <module>() | ||
3782 | 93 | 30 mode = 'div' | ||
3783 | 94 | 31 | ||
3784 | 95 | ---> 32 bar(mode) | ||
3785 | 96 | 33 | ||
3786 | 97 | 34 | ||
3787 | 98 | <BLANKLINE> | ||
3788 | 99 | ... in bar(mode) | ||
3789 | 100 | 14 "bar" | ||
3790 | 101 | 15 if mode=='div': | ||
3791 | 102 | ---> 16 div0() | ||
3792 | 103 | 17 elif mode=='exit': | ||
3793 | 104 | 18 try: | ||
3794 | 105 | <BLANKLINE> | ||
3795 | 106 | ... in div0() | ||
3796 | 107 | 6 x = 1 | ||
3797 | 108 | 7 y = 0 | ||
3798 | 109 | ----> 8 x/y | ||
3799 | 110 | 9 | ||
3800 | 111 | 10 def sysexit(stat, mode): | ||
3801 | 112 | <BLANKLINE> | ||
3802 | 113 | ZeroDivisionError: integer division or modulo by zero | ||
3803 | 114 | """ | ||
3804 | 115 | |||
3805 | 116 | |||
3806 | 117 | def doctest_tb_verbose(): | ||
3807 | 118 | """ | ||
3808 | 119 | In [5]: xmode verbose | ||
3809 | 120 | Exception reporting mode: Verbose | ||
3810 | 121 | |||
3811 | 122 | In [6]: run simpleerr.py | ||
3812 | 123 | --------------------------------------------------------------------------- | ||
3813 | 124 | ZeroDivisionError Traceback (most recent call last) | ||
3814 | 125 | <BLANKLINE> | ||
3815 | 126 | ... in <module>() | ||
3816 | 127 | 30 mode = 'div' | ||
3817 | 128 | 31 | ||
3818 | 129 | ---> 32 bar(mode) | ||
3819 | 130 | global bar = <function bar at ...> | ||
3820 | 131 | global mode = 'div' | ||
3821 | 132 | 33 | ||
3822 | 133 | 34 | ||
3823 | 134 | <BLANKLINE> | ||
3824 | 135 | ... in bar(mode='div') | ||
3825 | 136 | 14 "bar" | ||
3826 | 137 | 15 if mode=='div': | ||
3827 | 138 | ---> 16 div0() | ||
3828 | 139 | global div0 = <function div0 at ...> | ||
3829 | 140 | 17 elif mode=='exit': | ||
3830 | 141 | 18 try: | ||
3831 | 142 | <BLANKLINE> | ||
3832 | 143 | ... in div0() | ||
3833 | 144 | 6 x = 1 | ||
3834 | 145 | 7 y = 0 | ||
3835 | 146 | ----> 8 x/y | ||
3836 | 147 | x = 1 | ||
3837 | 148 | y = 0 | ||
3838 | 149 | 9 | ||
3839 | 150 | 10 def sysexit(stat, mode): | ||
3840 | 151 | <BLANKLINE> | ||
3841 | 152 | ZeroDivisionError: integer division or modulo by zero | ||
3842 | 153 | """ | ||
3843 | 154 | |||
3844 | 155 | |||
3845 | 156 | def doctest_tb_sysexit(): | ||
3846 | 157 | """ | ||
3847 | 158 | In [17]: %xmode plain | ||
3848 | 159 | Exception reporting mode: Plain | ||
3849 | 160 | |||
3850 | 161 | In [18]: %run simpleerr.py exit | ||
3851 | 162 | An exception has occurred, use %tb to see the full traceback. | ||
3852 | 163 | SystemExit: (1, 'Mode = exit') | ||
3853 | 164 | |||
3854 | 165 | In [19]: %run simpleerr.py exit 2 | ||
3855 | 166 | An exception has occurred, use %tb to see the full traceback. | ||
3856 | 167 | SystemExit: (2, 'Mode = exit') | ||
3857 | 168 | |||
3858 | 169 | In [20]: %tb | ||
3859 | 170 | Traceback (most recent call last): | ||
3860 | 171 | File ... in <module> | ||
3861 | 172 | bar(mode) | ||
3862 | 173 | File ... line 22, in bar | ||
3863 | 174 | sysexit(stat, mode) | ||
3864 | 175 | File ... line 11, in sysexit | ||
3865 | 176 | raise SystemExit(stat, 'Mode = %s' % mode) | ||
3866 | 177 | SystemExit: (2, 'Mode = exit') | ||
3867 | 178 | |||
3868 | 179 | In [21]: %xmode context | ||
3869 | 180 | Exception reporting mode: Context | ||
3870 | 181 | |||
3871 | 182 | In [22]: %tb | ||
3872 | 183 | --------------------------------------------------------------------------- | ||
3873 | 184 | SystemExit Traceback (most recent call last) | ||
3874 | 185 | <BLANKLINE> | ||
3875 | 186 | ...<module>() | ||
3876 | 187 | 30 mode = 'div' | ||
3877 | 188 | 31 | ||
3878 | 189 | ---> 32 bar(mode) | ||
3879 | 190 | 33 | ||
3880 | 191 | 34 | ||
3881 | 192 | <BLANKLINE> | ||
3882 | 193 | ...bar(mode) | ||
3883 | 194 | 20 except: | ||
3884 | 195 | 21 stat = 1 | ||
3885 | 196 | ---> 22 sysexit(stat, mode) | ||
3886 | 197 | 23 else: | ||
3887 | 198 | 24 raise ValueError('Unknown mode') | ||
3888 | 199 | <BLANKLINE> | ||
3889 | 200 | ...sysexit(stat, mode) | ||
3890 | 201 | 9 | ||
3891 | 202 | 10 def sysexit(stat, mode): | ||
3892 | 203 | ---> 11 raise SystemExit(stat, 'Mode = %s' % mode) | ||
3893 | 204 | 12 | ||
3894 | 205 | 13 def bar(mode): | ||
3895 | 206 | <BLANKLINE> | ||
3896 | 207 | SystemExit: (2, 'Mode = exit') | ||
3897 | 208 | |||
3898 | 209 | In [23]: %xmode verbose | ||
3899 | 210 | Exception reporting mode: Verbose | ||
3900 | 211 | |||
3901 | 212 | In [24]: %tb | ||
3902 | 213 | --------------------------------------------------------------------------- | ||
3903 | 214 | SystemExit Traceback (most recent call last) | ||
3904 | 215 | <BLANKLINE> | ||
3905 | 216 | ... in <module>() | ||
3906 | 217 | 30 mode = 'div' | ||
3907 | 218 | 31 | ||
3908 | 219 | ---> 32 bar(mode) | ||
3909 | 220 | global bar = <function bar at ...> | ||
3910 | 221 | global mode = 'exit' | ||
3911 | 222 | 33 | ||
3912 | 223 | 34 | ||
3913 | 224 | <BLANKLINE> | ||
3914 | 225 | ... in bar(mode='exit') | ||
3915 | 226 | 20 except: | ||
3916 | 227 | 21 stat = 1 | ||
3917 | 228 | ---> 22 sysexit(stat, mode) | ||
3918 | 229 | global sysexit = <function sysexit at ...> | ||
3919 | 230 | stat = 2 | ||
3920 | 231 | mode = 'exit' | ||
3921 | 232 | 23 else: | ||
3922 | 233 | 24 raise ValueError('Unknown mode') | ||
3923 | 234 | <BLANKLINE> | ||
3924 | 235 | ... in sysexit(stat=2, mode='exit') | ||
3925 | 236 | 9 | ||
3926 | 237 | 10 def sysexit(stat, mode): | ||
3927 | 238 | ---> 11 raise SystemExit(stat, 'Mode = %s' % mode) | ||
3928 | 239 | global SystemExit = undefined | ||
3929 | 240 | stat = 2 | ||
3930 | 241 | mode = 'exit' | ||
3931 | 242 | 12 | ||
3932 | 243 | 13 def bar(mode): | ||
3933 | 244 | <BLANKLINE> | ||
3934 | 245 | SystemExit: (2, 'Mode = exit') | ||
3935 | 246 | """ | ||
3936 | 59 | 247 | ||
3937 | === modified file 'IPython/core/tests/test_magic.py' | |||
3938 | --- IPython/core/tests/test_magic.py 2009-09-18 02:40:20 +0000 | |||
3939 | +++ IPython/core/tests/test_magic.py 2010-01-18 01:17:11 +0000 | |||
3940 | @@ -2,22 +2,31 @@ | |||
3941 | 2 | 2 | ||
3942 | 3 | Needs to be run by nose (to make ipython session available). | 3 | Needs to be run by nose (to make ipython session available). |
3943 | 4 | """ | 4 | """ |
3945 | 5 | 5 | from __future__ import absolute_import | |
3946 | 6 | |||
3947 | 7 | #----------------------------------------------------------------------------- | ||
3948 | 8 | # Imports | ||
3949 | 9 | #----------------------------------------------------------------------------- | ||
3950 | 10 | |||
3951 | 11 | # stdlib | ||
3952 | 6 | import os | 12 | import os |
3953 | 7 | import sys | 13 | import sys |
3954 | 8 | import tempfile | 14 | import tempfile |
3955 | 9 | import types | 15 | import types |
3956 | 10 | from cStringIO import StringIO | 16 | from cStringIO import StringIO |
3957 | 11 | 17 | ||
3958 | 18 | # third-party | ||
3959 | 12 | import nose.tools as nt | 19 | import nose.tools as nt |
3960 | 13 | 20 | ||
3961 | 21 | # our own | ||
3962 | 22 | from IPython.utils import genutils | ||
3963 | 14 | from IPython.utils.platutils import find_cmd, get_long_path_name | 23 | from IPython.utils.platutils import find_cmd, get_long_path_name |
3964 | 15 | from IPython.testing import decorators as dec | 24 | from IPython.testing import decorators as dec |
3965 | 16 | from IPython.testing import tools as tt | 25 | from IPython.testing import tools as tt |
3966 | 17 | 26 | ||
3967 | 18 | #----------------------------------------------------------------------------- | 27 | #----------------------------------------------------------------------------- |
3968 | 19 | # Test functions begin | 28 | # Test functions begin |
3970 | 20 | 29 | #----------------------------------------------------------------------------- | |
3971 | 21 | def test_rehashx(): | 30 | def test_rehashx(): |
3972 | 22 | # clear up everything | 31 | # clear up everything |
3973 | 23 | _ip = get_ipython() | 32 | _ip = get_ipython() |
3974 | @@ -37,6 +46,19 @@ | |||
3975 | 37 | yield (nt.assert_true, len(scoms) > 10) | 46 | yield (nt.assert_true, len(scoms) > 10) |
3976 | 38 | 47 | ||
3977 | 39 | 48 | ||
3978 | 49 | def test_magic_parse_options(): | ||
3979 | 50 | """Test that we don't mangle paths when parsing magic options.""" | ||
3980 | 51 | ip = get_ipython() | ||
3981 | 52 | path = 'c:\\x' | ||
3982 | 53 | opts = ip.parse_options('-f %s' % path,'f:')[0] | ||
3983 | 54 | # argv splitting is os-dependent | ||
3984 | 55 | if os.name == 'posix': | ||
3985 | 56 | expected = 'c:x' | ||
3986 | 57 | else: | ||
3987 | 58 | expected = path | ||
3988 | 59 | nt.assert_equals(opts['f'], expected) | ||
3989 | 60 | |||
3990 | 61 | |||
3991 | 40 | def doctest_hist_f(): | 62 | def doctest_hist_f(): |
3992 | 41 | """Test %hist -f with temporary filename. | 63 | """Test %hist -f with temporary filename. |
3993 | 42 | 64 | ||
3994 | @@ -45,35 +67,93 @@ | |||
3995 | 45 | In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-') | 67 | In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-') |
3996 | 46 | 68 | ||
3997 | 47 | In [11]: %hist -n -f $tfile 3 | 69 | In [11]: %hist -n -f $tfile 3 |
3998 | 70 | |||
3999 | 71 | In [13]: import os; os.unlink(tfile) | ||
4000 | 48 | """ | 72 | """ |
4001 | 49 | 73 | ||
4002 | 50 | 74 | ||
4003 | 51 | def doctest_hist_r(): | 75 | def doctest_hist_r(): |
4004 | 52 | """Test %hist -r | 76 | """Test %hist -r |
4005 | 53 | 77 | ||
4029 | 54 | XXX - This test is not recording the output correctly. Not sure why... | 78 | XXX - This test is not recording the output correctly. For some reason, in |
4030 | 55 | 79 | testing mode the raw history isn't getting populated. No idea why. | |
4031 | 56 | In [20]: 'hist' in _ip.lsmagic() | 80 | Disabling the output checking for now, though at least we do run it. |
4032 | 57 | Out[20]: True | 81 | |
4033 | 58 | 82 | In [1]: 'hist' in _ip.lsmagic() | |
4034 | 59 | In [6]: x=1 | 83 | Out[1]: True |
4035 | 60 | 84 | ||
4036 | 61 | In [7]: %hist -n -r 2 | 85 | In [2]: x=1 |
4037 | 62 | x=1 # random | 86 | |
4038 | 63 | hist -n -r 2 # random | 87 | In [3]: %hist -r 2 |
4039 | 64 | """ | 88 | x=1 # random |
4040 | 65 | 89 | %hist -r 2 | |
4041 | 66 | # This test is known to fail on win32. | 90 | """ |
4042 | 67 | # See ticket https://bugs.launchpad.net/bugs/366334 | 91 | |
4043 | 68 | def test_obj_del(): | 92 | def doctest_hist_op(): |
4044 | 69 | _ip = get_ipython() | 93 | """Test %hist -op |
4045 | 70 | """Test that object's __del__ methods are called on exit.""" | 94 | |
4046 | 71 | test_dir = os.path.dirname(__file__) | 95 | In [1]: class b: |
4047 | 72 | del_file = os.path.join(test_dir,'obj_del.py') | 96 | ...: pass |
4048 | 73 | ipython_cmd = find_cmd('ipython') | 97 | ...: |
4049 | 74 | out = _ip.getoutput('%s %s' % (ipython_cmd, del_file)) | 98 | |
4050 | 75 | nt.assert_equals(out,'obj_del.py: object A deleted') | 99 | In [2]: class s(b): |
4051 | 76 | 100 | ...: def __str__(self): | |
4052 | 101 | ...: return 's' | ||
4053 | 102 | ...: | ||
4054 | 103 | |||
4055 | 104 | In [3]: | ||
4056 | 105 | |||
4057 | 106 | In [4]: class r(b): | ||
4058 | 107 | ...: def __repr__(self): | ||
4059 | 108 | ...: return 'r' | ||
4060 | 109 | ...: | ||
4061 | 110 | |||
4062 | 111 | In [5]: class sr(s,r): pass | ||
4063 | 112 | ...: | ||
4064 | 113 | |||
4065 | 114 | In [6]: | ||
4066 | 115 | |||
4067 | 116 | In [7]: bb=b() | ||
4068 | 117 | |||
4069 | 118 | In [8]: ss=s() | ||
4070 | 119 | |||
4071 | 120 | In [9]: rr=r() | ||
4072 | 121 | |||
4073 | 122 | In [10]: ssrr=sr() | ||
4074 | 123 | |||
4075 | 124 | In [11]: bb | ||
4076 | 125 | Out[11]: <...b instance at ...> | ||
4077 | 126 | |||
4078 | 127 | In [12]: ss | ||
4079 | 128 | Out[12]: <...s instance at ...> | ||
4080 | 129 | |||
4081 | 130 | In [13]: | ||
4082 | 131 | |||
4083 | 132 | In [14]: %hist -op | ||
4084 | 133 | >>> class b: | ||
4085 | 134 | ... pass | ||
4086 | 135 | ... | ||
4087 | 136 | >>> class s(b): | ||
4088 | 137 | ... def __str__(self): | ||
4089 | 138 | ... return 's' | ||
4090 | 139 | ... | ||
4091 | 140 | >>> | ||
4092 | 141 | >>> class r(b): | ||
4093 | 142 | ... def __repr__(self): | ||
4094 | 143 | ... return 'r' | ||
4095 | 144 | ... | ||
4096 | 145 | >>> class sr(s,r): pass | ||
4097 | 146 | >>> | ||
4098 | 147 | >>> bb=b() | ||
4099 | 148 | >>> ss=s() | ||
4100 | 149 | >>> rr=r() | ||
4101 | 150 | >>> ssrr=sr() | ||
4102 | 151 | >>> bb | ||
4103 | 152 | <...b instance at ...> | ||
4104 | 153 | >>> ss | ||
4105 | 154 | <...s instance at ...> | ||
4106 | 155 | >>> | ||
4107 | 156 | """ | ||
4108 | 77 | 157 | ||
4109 | 78 | def test_shist(): | 158 | def test_shist(): |
4110 | 79 | # Simple tests of ShadowHist class - test generator. | 159 | # Simple tests of ShadowHist class - test generator. |
4111 | @@ -97,8 +177,12 @@ | |||
4112 | 97 | yield nt.assert_equal,s.get(2),'world' | 177 | yield nt.assert_equal,s.get(2),'world' |
4113 | 98 | 178 | ||
4114 | 99 | shutil.rmtree(tfile) | 179 | shutil.rmtree(tfile) |
4115 | 180 | |||
4116 | 100 | 181 | ||
4118 | 101 | @dec.skipif_not_numpy | 182 | # XXX failing for now, until we get clearcmd out of quarantine. But we should |
4119 | 183 | # fix this and revert the skip to happen only if numpy is not around. | ||
4120 | 184 | #@dec.skipif_not_numpy | ||
4121 | 185 | @dec.skipknownfailure | ||
4122 | 102 | def test_numpy_clear_array_undec(): | 186 | def test_numpy_clear_array_undec(): |
4123 | 103 | from IPython.extensions import clearcmd | 187 | from IPython.extensions import clearcmd |
4124 | 104 | 188 | ||
4125 | @@ -109,162 +193,8 @@ | |||
4126 | 109 | yield (nt.assert_false, 'a' in _ip.user_ns) | 193 | yield (nt.assert_false, 'a' in _ip.user_ns) |
4127 | 110 | 194 | ||
4128 | 111 | 195 | ||
4129 | 112 | @dec.skip() | ||
4130 | 113 | def test_fail_dec(*a,**k): | ||
4131 | 114 | yield nt.assert_true, False | ||
4132 | 115 | |||
4133 | 116 | @dec.skip('This one shouldn not run') | ||
4134 | 117 | def test_fail_dec2(*a,**k): | ||
4135 | 118 | yield nt.assert_true, False | ||
4136 | 119 | |||
4137 | 120 | @dec.skipknownfailure | ||
4138 | 121 | def test_fail_dec3(*a,**k): | ||
4139 | 122 | yield nt.assert_true, False | ||
4140 | 123 | |||
4141 | 124 | |||
4142 | 125 | def doctest_refbug(): | ||
4143 | 126 | """Very nasty problem with references held by multiple runs of a script. | ||
4144 | 127 | See: https://bugs.launchpad.net/ipython/+bug/269966 | ||
4145 | 128 | |||
4146 | 129 | In [1]: _ip.clear_main_mod_cache() | ||
4147 | 130 | |||
4148 | 131 | In [2]: run refbug | ||
4149 | 132 | |||
4150 | 133 | In [3]: call_f() | ||
4151 | 134 | lowercased: hello | ||
4152 | 135 | |||
4153 | 136 | In [4]: run refbug | ||
4154 | 137 | |||
4155 | 138 | In [5]: call_f() | ||
4156 | 139 | lowercased: hello | ||
4157 | 140 | lowercased: hello | ||
4158 | 141 | """ | ||
4159 | 142 | |||
4160 | 143 | #----------------------------------------------------------------------------- | ||
4161 | 144 | # Tests for %run | ||
4162 | 145 | #----------------------------------------------------------------------------- | ||
4163 | 146 | |||
4164 | 147 | # %run is critical enough that it's a good idea to have a solid collection of | ||
4165 | 148 | # tests for it, some as doctests and some as normal tests. | ||
4166 | 149 | |||
4167 | 150 | def doctest_run_ns(): | ||
4168 | 151 | """Classes declared %run scripts must be instantiable afterwards. | ||
4169 | 152 | |||
4170 | 153 | In [11]: run tclass foo | ||
4171 | 154 | |||
4172 | 155 | In [12]: isinstance(f(),foo) | ||
4173 | 156 | Out[12]: True | ||
4174 | 157 | """ | ||
4175 | 158 | |||
4176 | 159 | |||
4177 | 160 | def doctest_run_ns2(): | ||
4178 | 161 | """Classes declared %run scripts must be instantiable afterwards. | ||
4179 | 162 | |||
4180 | 163 | In [4]: run tclass C-first_pass | ||
4181 | 164 | |||
4182 | 165 | In [5]: run tclass C-second_pass | ||
4183 | 166 | tclass.py: deleting object: C-first_pass | ||
4184 | 167 | """ | ||
4185 | 168 | |||
4186 | 169 | def doctest_run_builtins(): | ||
4187 | 170 | """Check that %run doesn't damage __builtins__ via a doctest. | ||
4188 | 171 | |||
4189 | 172 | This is similar to the test_run_builtins, but I want *both* forms of the | ||
4190 | 173 | test to catch any possible glitches in our testing machinery, since that | ||
4191 | 174 | modifies %run somewhat. So for this, we have both a normal test (below) | ||
4192 | 175 | and a doctest (this one). | ||
4193 | 176 | |||
4194 | 177 | In [1]: import tempfile | ||
4195 | 178 | |||
4196 | 179 | In [2]: bid1 = id(__builtins__) | ||
4197 | 180 | |||
4198 | 181 | In [3]: fname = tempfile.mkstemp()[1] | ||
4199 | 182 | |||
4200 | 183 | In [3]: f = open(fname,'w') | ||
4201 | 184 | |||
4202 | 185 | In [4]: f.write('pass\\n') | ||
4203 | 186 | |||
4204 | 187 | In [5]: f.flush() | ||
4205 | 188 | |||
4206 | 189 | In [6]: print type(__builtins__) | ||
4207 | 190 | <type 'module'> | ||
4208 | 191 | |||
4209 | 192 | In [7]: %run "$fname" | ||
4210 | 193 | |||
4211 | 194 | In [7]: f.close() | ||
4212 | 195 | |||
4213 | 196 | In [8]: bid2 = id(__builtins__) | ||
4214 | 197 | |||
4215 | 198 | In [9]: print type(__builtins__) | ||
4216 | 199 | <type 'module'> | ||
4217 | 200 | |||
4218 | 201 | In [10]: bid1 == bid2 | ||
4219 | 202 | Out[10]: True | ||
4220 | 203 | |||
4221 | 204 | In [12]: try: | ||
4222 | 205 | ....: os.unlink(fname) | ||
4223 | 206 | ....: except: | ||
4224 | 207 | ....: pass | ||
4225 | 208 | ....: | ||
4226 | 209 | """ | ||
4227 | 210 | |||
4228 | 211 | # For some tests, it will be handy to organize them in a class with a common | ||
4229 | 212 | # setup that makes a temp file | ||
4230 | 213 | |||
4231 | 214 | class TestMagicRun(object): | ||
4232 | 215 | |||
4233 | 216 | def setup(self): | ||
4234 | 217 | """Make a valid python temp file.""" | ||
4235 | 218 | fname = tempfile.mkstemp()[1] | ||
4236 | 219 | f = open(fname,'w') | ||
4237 | 220 | f.write('pass\n') | ||
4238 | 221 | f.flush() | ||
4239 | 222 | self.tmpfile = f | ||
4240 | 223 | self.fname = fname | ||
4241 | 224 | |||
4242 | 225 | def run_tmpfile(self): | ||
4243 | 226 | _ip = get_ipython() | ||
4244 | 227 | # This fails on Windows if self.tmpfile.name has spaces or "~" in it. | ||
4245 | 228 | # See below and ticket https://bugs.launchpad.net/bugs/366353 | ||
4246 | 229 | _ip.magic('run "%s"' % self.fname) | ||
4247 | 230 | |||
4248 | 231 | def test_builtins_id(self): | ||
4249 | 232 | """Check that %run doesn't damage __builtins__ """ | ||
4250 | 233 | _ip = get_ipython() | ||
4251 | 234 | # Test that the id of __builtins__ is not modified by %run | ||
4252 | 235 | bid1 = id(_ip.user_ns['__builtins__']) | ||
4253 | 236 | self.run_tmpfile() | ||
4254 | 237 | bid2 = id(_ip.user_ns['__builtins__']) | ||
4255 | 238 | tt.assert_equals(bid1, bid2) | ||
4256 | 239 | |||
4257 | 240 | def test_builtins_type(self): | ||
4258 | 241 | """Check that the type of __builtins__ doesn't change with %run. | ||
4259 | 242 | |||
4260 | 243 | However, the above could pass if __builtins__ was already modified to | ||
4261 | 244 | be a dict (it should be a module) by a previous use of %run. So we | ||
4262 | 245 | also check explicitly that it really is a module: | ||
4263 | 246 | """ | ||
4264 | 247 | _ip = get_ipython() | ||
4265 | 248 | self.run_tmpfile() | ||
4266 | 249 | tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys)) | ||
4267 | 250 | |||
4268 | 251 | def test_prompts(self): | ||
4269 | 252 | """Test that prompts correctly generate after %run""" | ||
4270 | 253 | self.run_tmpfile() | ||
4271 | 254 | _ip = get_ipython() | ||
4272 | 255 | p2 = str(_ip.outputcache.prompt2).strip() | ||
4273 | 256 | nt.assert_equals(p2[:3], '...') | ||
4274 | 257 | |||
4275 | 258 | def teardown(self): | ||
4276 | 259 | self.tmpfile.close() | ||
4277 | 260 | try: | ||
4278 | 261 | os.unlink(self.fname) | ||
4279 | 262 | except: | ||
4280 | 263 | # On Windows, even though we close the file, we still can't delete | ||
4281 | 264 | # it. I have no clue why | ||
4282 | 265 | pass | ||
4283 | 266 | |||
4284 | 267 | # Multiple tests for clipboard pasting | 196 | # Multiple tests for clipboard pasting |
4285 | 197 | @dec.parametric | ||
4286 | 268 | def test_paste(): | 198 | def test_paste(): |
4287 | 269 | _ip = get_ipython() | 199 | _ip = get_ipython() |
4288 | 270 | def paste(txt, flags='-q'): | 200 | def paste(txt, flags='-q'): |
4289 | @@ -286,11 +216,11 @@ | |||
4290 | 286 | # Run tests with fake clipboard function | 216 | # Run tests with fake clipboard function |
4291 | 287 | user_ns.pop('x', None) | 217 | user_ns.pop('x', None) |
4292 | 288 | paste('x=1') | 218 | paste('x=1') |
4294 | 289 | yield (nt.assert_equal, user_ns['x'], 1) | 219 | yield nt.assert_equal(user_ns['x'], 1) |
4295 | 290 | 220 | ||
4296 | 291 | user_ns.pop('x', None) | 221 | user_ns.pop('x', None) |
4297 | 292 | paste('>>> x=2') | 222 | paste('>>> x=2') |
4299 | 293 | yield (nt.assert_equal, user_ns['x'], 2) | 223 | yield nt.assert_equal(user_ns['x'], 2) |
4300 | 294 | 224 | ||
4301 | 295 | paste(""" | 225 | paste(""" |
4302 | 296 | >>> x = [1,2,3] | 226 | >>> x = [1,2,3] |
4303 | @@ -299,14 +229,14 @@ | |||
4304 | 299 | ... y.append(i**2) | 229 | ... y.append(i**2) |
4305 | 300 | ... | 230 | ... |
4306 | 301 | """) | 231 | """) |
4309 | 302 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) | 232 | yield nt.assert_equal(user_ns['x'], [1,2,3]) |
4310 | 303 | yield (nt.assert_equal, user_ns['y'], [1,4,9]) | 233 | yield nt.assert_equal(user_ns['y'], [1,4,9]) |
4311 | 304 | 234 | ||
4312 | 305 | # Now, test that paste -r works | 235 | # Now, test that paste -r works |
4313 | 306 | user_ns.pop('x', None) | 236 | user_ns.pop('x', None) |
4315 | 307 | yield (nt.assert_false, 'x' in user_ns) | 237 | yield nt.assert_false('x' in user_ns) |
4316 | 308 | _ip.magic('paste -r') | 238 | _ip.magic('paste -r') |
4318 | 309 | yield (nt.assert_equal, user_ns['x'], [1,2,3]) | 239 | yield nt.assert_equal(user_ns['x'], [1,2,3]) |
4319 | 310 | 240 | ||
4320 | 311 | # Also test paste echoing, by temporarily faking the writer | 241 | # Also test paste echoing, by temporarily faking the writer |
4321 | 312 | w = StringIO() | 242 | w = StringIO() |
4322 | @@ -320,12 +250,29 @@ | |||
4323 | 320 | out = w.getvalue() | 250 | out = w.getvalue() |
4324 | 321 | finally: | 251 | finally: |
4325 | 322 | _ip.write = writer | 252 | _ip.write = writer |
4329 | 323 | yield (nt.assert_equal, user_ns['a'], 100) | 253 | yield nt.assert_equal(user_ns['a'], 100) |
4330 | 324 | yield (nt.assert_equal, user_ns['b'], 200) | 254 | yield nt.assert_equal(user_ns['b'], 200) |
4331 | 325 | yield (nt.assert_equal, out, code+"\n## -- End pasted text --\n") | 255 | yield nt.assert_equal(out, code+"\n## -- End pasted text --\n") |
4332 | 326 | 256 | ||
4333 | 327 | finally: | 257 | finally: |
4334 | 328 | # This should be in a finally clause, instead of the bare except above. | 258 | # This should be in a finally clause, instead of the bare except above. |
4335 | 329 | # Restore original hook | 259 | # Restore original hook |
4336 | 330 | hooks.clipboard_get = original_clip | 260 | hooks.clipboard_get = original_clip |
4337 | 331 | 261 | ||
4338 | 262 | |||
4339 | 263 | def test_time(): | ||
4340 | 264 | _ip.magic('time None') | ||
4341 | 265 | |||
4342 | 266 | |||
4343 | 267 | def doctest_time(): | ||
4344 | 268 | """ | ||
4345 | 269 | In [10]: %time None | ||
4346 | 270 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s | ||
4347 | 271 | Wall time: 0.00 s | ||
4348 | 272 | """ | ||
4349 | 273 | |||
4350 | 274 | def test_doctest_mode(): | ||
4351 | 275 | "Toggle doctest_mode twice, it should be a no-op and run without error" | ||
4352 | 276 | _ip.magic('doctest_mode') | ||
4353 | 277 | _ip.magic('doctest_mode') | ||
4354 | 278 | |||
4355 | 332 | 279 | ||
4356 | === added file 'IPython/core/tests/test_prefilter.py' | |||
4357 | --- IPython/core/tests/test_prefilter.py 1970-01-01 00:00:00 +0000 | |||
4358 | +++ IPython/core/tests/test_prefilter.py 2010-01-18 01:17:11 +0000 | |||
4359 | @@ -0,0 +1,34 @@ | |||
4360 | 1 | """Tests for input manipulation machinery.""" | ||
4361 | 2 | |||
4362 | 3 | #----------------------------------------------------------------------------- | ||
4363 | 4 | # Imports | ||
4364 | 5 | #----------------------------------------------------------------------------- | ||
4365 | 6 | import nose.tools as nt | ||
4366 | 7 | |||
4367 | 8 | from IPython.testing import tools as tt, decorators as dec | ||
4368 | 9 | |||
4369 | 10 | #----------------------------------------------------------------------------- | ||
4370 | 11 | # Tests | ||
4371 | 12 | #----------------------------------------------------------------------------- | ||
4372 | 13 | @dec.parametric | ||
4373 | 14 | def test_prefilter(): | ||
4374 | 15 | """Test user input conversions""" | ||
4375 | 16 | |||
4376 | 17 | # pairs of (raw, expected correct) input | ||
4377 | 18 | pairs = [ ('2+2','2+2'), | ||
4378 | 19 | ('>>> 2+2','2+2'), | ||
4379 | 20 | ('>>> # This is a comment\n' | ||
4380 | 21 | '... 2+2', | ||
4381 | 22 | '# This is a comment\n' | ||
4382 | 23 | '2+2'), | ||
4383 | 24 | # Some IPython input | ||
4384 | 25 | ('In [1]: 1', '1'), | ||
4385 | 26 | ('In [2]: for i in range(5):\n' | ||
4386 | 27 | ' ...: print i,', | ||
4387 | 28 | 'for i in range(5):\n' | ||
4388 | 29 | ' print i,'), | ||
4389 | 30 | ] | ||
4390 | 31 | |||
4391 | 32 | ip = get_ipython() | ||
4392 | 33 | for raw, correct in pairs: | ||
4393 | 34 | yield nt.assert_equals(ip.prefilter(raw), correct) | ||
4394 | 0 | 35 | ||
4395 | === added file 'IPython/core/tests/test_run.py' | |||
4396 | --- IPython/core/tests/test_run.py 1970-01-01 00:00:00 +0000 | |||
4397 | +++ IPython/core/tests/test_run.py 2010-01-18 01:17:11 +0000 | |||
4398 | @@ -0,0 +1,174 @@ | |||
4399 | 1 | """Tests for code execution (%run and related), which is particularly tricky. | ||
4400 | 2 | |||
4401 | 3 | Because of how %run manages namespaces, and the fact that we are trying here to | ||
4402 | 4 | verify subtle object deletion and reference counting issues, the %run tests | ||
4403 | 5 | will be kept in this separate file. This makes it easier to aggregate in one | ||
4404 | 6 | place the tricks needed to handle it; most other magics are much easier to test | ||
4405 | 7 | and we do so in a common test_magic file. | ||
4406 | 8 | """ | ||
4407 | 9 | from __future__ import absolute_import | ||
4408 | 10 | |||
4409 | 11 | #----------------------------------------------------------------------------- | ||
4410 | 12 | # Imports | ||
4411 | 13 | #----------------------------------------------------------------------------- | ||
4412 | 14 | |||
4413 | 15 | # stdlib | ||
4414 | 16 | import os | ||
4415 | 17 | import sys | ||
4416 | 18 | import tempfile | ||
4417 | 19 | |||
4418 | 20 | # third-party | ||
4419 | 21 | import nose.tools as nt | ||
4420 | 22 | |||
4421 | 23 | # our own | ||
4422 | 24 | from IPython.utils.platutils import find_cmd | ||
4423 | 25 | from IPython.utils import genutils | ||
4424 | 26 | from IPython.testing import decorators as dec | ||
4425 | 27 | from IPython.testing import tools as tt | ||
4426 | 28 | |||
4427 | 29 | #----------------------------------------------------------------------------- | ||
4428 | 30 | # Test functions begin | ||
4429 | 31 | #----------------------------------------------------------------------------- | ||
4430 | 32 | |||
4431 | 33 | def doctest_refbug(): | ||
4432 | 34 | """Very nasty problem with references held by multiple runs of a script. | ||
4433 | 35 | See: https://bugs.launchpad.net/ipython/+bug/269966 | ||
4434 | 36 | |||
4435 | 37 | In [1]: _ip.clear_main_mod_cache() | ||
4436 | 38 | # random | ||
4437 | 39 | |||
4438 | 40 | In [2]: %run refbug | ||
4439 | 41 | |||
4440 | 42 | In [3]: call_f() | ||
4441 | 43 | lowercased: hello | ||
4442 | 44 | |||
4443 | 45 | In [4]: %run refbug | ||
4444 | 46 | |||
4445 | 47 | In [5]: call_f() | ||
4446 | 48 | lowercased: hello | ||
4447 | 49 | lowercased: hello | ||
4448 | 50 | """ | ||
4449 | 51 | |||
4450 | 52 | |||
4451 | 53 | def doctest_run_builtins(): | ||
4452 | 54 | r"""Check that %run doesn't damage __builtins__. | ||
4453 | 55 | |||
4454 | 56 | In [1]: import tempfile | ||
4455 | 57 | |||
4456 | 58 | In [2]: bid1 = id(__builtins__) | ||
4457 | 59 | |||
4458 | 60 | In [3]: fname = tempfile.mkstemp('.py')[1] | ||
4459 | 61 | |||
4460 | 62 | In [3]: f = open(fname,'w') | ||
4461 | 63 | |||
4462 | 64 | In [4]: f.write('pass\n') | ||
4463 | 65 | |||
4464 | 66 | In [5]: f.flush() | ||
4465 | 67 | |||
4466 | 68 | In [6]: t1 = type(__builtins__) | ||
4467 | 69 | |||
4468 | 70 | In [7]: %run $fname | ||
4469 | 71 | |||
4470 | 72 | In [7]: f.close() | ||
4471 | 73 | |||
4472 | 74 | In [8]: bid2 = id(__builtins__) | ||
4473 | 75 | |||
4474 | 76 | In [9]: t2 = type(__builtins__) | ||
4475 | 77 | |||
4476 | 78 | In [10]: t1 == t2 | ||
4477 | 79 | Out[10]: True | ||
4478 | 80 | |||
4479 | 81 | In [10]: bid1 == bid2 | ||
4480 | 82 | Out[10]: True | ||
4481 | 83 | |||
4482 | 84 | In [12]: try: | ||
4483 | 85 | ....: os.unlink(fname) | ||
4484 | 86 | ....: except: | ||
4485 | 87 | ....: pass | ||
4486 | 88 | ....: | ||
4487 | 89 | """ | ||
4488 | 90 | |||
4489 | 91 | # For some tests, it will be handy to organize them in a class with a common | ||
4490 | 92 | # setup that makes a temp file | ||
4491 | 93 | |||
4492 | 94 | class TestMagicRunPass(tt.TempFileMixin): | ||
4493 | 95 | |||
4494 | 96 | def setup(self): | ||
4495 | 97 | """Make a valid python temp file.""" | ||
4496 | 98 | self.mktmp('pass\n') | ||
4497 | 99 | |||
4498 | 100 | def run_tmpfile(self): | ||
4499 | 101 | _ip = get_ipython() | ||
4500 | 102 | # This fails on Windows if self.tmpfile.name has spaces or "~" in it. | ||
4501 | 103 | # See below and ticket https://bugs.launchpad.net/bugs/366353 | ||
4502 | 104 | _ip.magic('run %s' % self.fname) | ||
4503 | 105 | |||
4504 | 106 | def test_builtins_id(self): | ||
4505 | 107 | """Check that %run doesn't damage __builtins__ """ | ||
4506 | 108 | _ip = get_ipython() | ||
4507 | 109 | # Test that the id of __builtins__ is not modified by %run | ||
4508 | 110 | bid1 = id(_ip.user_ns['__builtins__']) | ||
4509 | 111 | self.run_tmpfile() | ||
4510 | 112 | bid2 = id(_ip.user_ns['__builtins__']) | ||
4511 | 113 | tt.assert_equals(bid1, bid2) | ||
4512 | 114 | |||
4513 | 115 | def test_builtins_type(self): | ||
4514 | 116 | """Check that the type of __builtins__ doesn't change with %run. | ||
4515 | 117 | |||
4516 | 118 | However, the above could pass if __builtins__ was already modified to | ||
4517 | 119 | be a dict (it should be a module) by a previous use of %run. So we | ||
4518 | 120 | also check explicitly that it really is a module: | ||
4519 | 121 | """ | ||
4520 | 122 | _ip = get_ipython() | ||
4521 | 123 | self.run_tmpfile() | ||
4522 | 124 | tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys)) | ||
4523 | 125 | |||
4524 | 126 | def test_prompts(self): | ||
4525 | 127 | """Test that prompts correctly generate after %run""" | ||
4526 | 128 | self.run_tmpfile() | ||
4527 | 129 | _ip = get_ipython() | ||
4528 | 130 | p2 = str(_ip.outputcache.prompt2).strip() | ||
4529 | 131 | nt.assert_equals(p2[:3], '...') | ||
4530 | 132 | |||
4531 | 133 | |||
4532 | 134 | class TestMagicRunSimple(tt.TempFileMixin): | ||
4533 | 135 | |||
4534 | 136 | def test_simpledef(self): | ||
4535 | 137 | """Test that simple class definitions work.""" | ||
4536 | 138 | src = ("class foo: pass\n" | ||
4537 | 139 | "def f(): return foo()") | ||
4538 | 140 | self.mktmp(src) | ||
4539 | 141 | _ip.magic('run %s' % self.fname) | ||
4540 | 142 | _ip.runlines('t = isinstance(f(), foo)') | ||
4541 | 143 | nt.assert_true(_ip.user_ns['t']) | ||
4542 | 144 | |||
4543 | 145 | # We have to skip these in win32 because genutils.getoutputerr() crashes, | ||
4544 | 146 | # due to the fact that subprocess does not support close_fds when | ||
4545 | 147 | # redirecting stdout/err. So unless someone who knows more tells us how to | ||
4546 | 148 | # implement genutils.getoutputerr() in win32, we're stuck avoiding these. | ||
4547 | 149 | @dec.skip_win32 | ||
4548 | 150 | def test_obj_del(self): | ||
4549 | 151 | """Test that object's __del__ methods are called on exit.""" | ||
4550 | 152 | |||
4551 | 153 | # This test is known to fail on win32. | ||
4552 | 154 | # See ticket https://bugs.launchpad.net/bugs/366334 | ||
4553 | 155 | src = ("class A(object):\n" | ||
4554 | 156 | " def __del__(self):\n" | ||
4555 | 157 | " print 'object A deleted'\n" | ||
4556 | 158 | "a = A()\n") | ||
4557 | 159 | self.mktmp(src) | ||
4558 | 160 | tt.ipexec_validate(self.fname, 'object A deleted') | ||
4559 | 161 | |||
4560 | 162 | @dec.skip_win32 | ||
4561 | 163 | def test_tclass(self): | ||
4562 | 164 | mydir = os.path.dirname(__file__) | ||
4563 | 165 | tc = os.path.join(mydir, 'tclass') | ||
4564 | 166 | src = ("%%run '%s' C-first\n" | ||
4565 | 167 | "%%run '%s' C-second\n") % (tc, tc) | ||
4566 | 168 | self.mktmp(src, '.ipy') | ||
4567 | 169 | out = """\ | ||
4568 | 170 | ARGV 1-: ['C-first'] | ||
4569 | 171 | ARGV 1-: ['C-second'] | ||
4570 | 172 | tclass.py: deleting object: C-first | ||
4571 | 173 | """ | ||
4572 | 174 | tt.ipexec_validate(self.fname, out) | ||
4573 | 0 | 175 | ||
4574 | === modified file 'IPython/core/ultratb.py' | |||
4575 | --- IPython/core/ultratb.py 2009-08-27 22:40:52 +0000 | |||
4576 | +++ IPython/core/ultratb.py 2010-01-18 01:17:11 +0000 | |||
4577 | @@ -88,7 +88,6 @@ | |||
4578 | 88 | from inspect import getsourcefile, getfile, getmodule,\ | 88 | from inspect import getsourcefile, getfile, getmodule,\ |
4579 | 89 | ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode | 89 | ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode |
4580 | 90 | 90 | ||
4581 | 91 | |||
4582 | 92 | # IPython's own modules | 91 | # IPython's own modules |
4583 | 93 | # Modified pdb which doesn't damage IPython's readline handling | 92 | # Modified pdb which doesn't damage IPython's readline handling |
4584 | 94 | from IPython.utils import PyColorize | 93 | from IPython.utils import PyColorize |
4585 | @@ -263,7 +262,7 @@ | |||
4586 | 263 | 262 | ||
4587 | 264 | _parser = PyColorize.Parser() | 263 | _parser = PyColorize.Parser() |
4588 | 265 | 264 | ||
4590 | 266 | def _formatTracebackLines(lnum, index, lines, Colors, lvals=None,scheme=None): | 265 | def _format_traceback_lines(lnum, index, lines, Colors, lvals=None,scheme=None): |
4591 | 267 | numbers_width = INDENT_SIZE - 1 | 266 | numbers_width = INDENT_SIZE - 1 |
4592 | 268 | res = [] | 267 | res = [] |
4593 | 269 | i = lnum - index | 268 | i = lnum - index |
4594 | @@ -313,6 +312,15 @@ | |||
4595 | 313 | class TBTools: | 312 | class TBTools: |
4596 | 314 | """Basic tools used by all traceback printer classes.""" | 313 | """Basic tools used by all traceback printer classes.""" |
4597 | 315 | 314 | ||
4598 | 315 | #: Default output stream, can be overridden at call time. A special value | ||
4599 | 316 | #: of 'stdout' *as a string* can be given to force extraction of sys.stdout | ||
4600 | 317 | #: at runtime. This allows testing exception printing with doctests, that | ||
4601 | 318 | #: swap sys.stdout just at execution time. | ||
4602 | 319 | #: Warning: be VERY careful to set this to one of the Term streams, NEVER | ||
4603 | 320 | #: directly to sys.stdout/err, because under win32 the Term streams come from | ||
4604 | 321 | #: pyreadline and know how to handle color correctly, whie stdout/err don't. | ||
4605 | 322 | out_stream = Term.cerr | ||
4606 | 323 | |||
4607 | 316 | def __init__(self,color_scheme = 'NoColor',call_pdb=False): | 324 | def __init__(self,color_scheme = 'NoColor',call_pdb=False): |
4608 | 317 | # Whether to call the interactive pdb debugger after printing | 325 | # Whether to call the interactive pdb debugger after printing |
4609 | 318 | # tracebacks or not | 326 | # tracebacks or not |
4610 | @@ -376,16 +384,31 @@ | |||
4611 | 376 | 384 | ||
4612 | 377 | def __call__(self, etype, value, elist): | 385 | def __call__(self, etype, value, elist): |
4613 | 378 | Term.cout.flush() | 386 | Term.cout.flush() |
4619 | 379 | print >> Term.cerr, self.text(etype,value,elist) | 387 | Term.cerr.writeln(self.text(etype,value,elist)) |
4620 | 380 | Term.cerr.flush() | 388 | |
4621 | 381 | 389 | def text(self, etype, value, elist, context=5): | |
4622 | 382 | def text(self,etype, value, elist,context=5): | 390 | """Return a color formatted string with the traceback info. |
4623 | 383 | """Return a color formatted string with the traceback info.""" | 391 | |
4624 | 392 | Parameters | ||
4625 | 393 | ---------- | ||
4626 | 394 | etype : exception type | ||
4627 | 395 | Type of the exception raised. | ||
4628 | 396 | |||
4629 | 397 | value : object | ||
4630 | 398 | Data stored in the exception | ||
4631 | 399 | |||
4632 | 400 | elist : list | ||
4633 | 401 | List of frames, see class docstring for details. | ||
4634 | 402 | |||
4635 | 403 | Returns | ||
4636 | 404 | ------- | ||
4637 | 405 | String with formatted exception. | ||
4638 | 406 | """ | ||
4639 | 384 | 407 | ||
4640 | 385 | Colors = self.Colors | 408 | Colors = self.Colors |
4642 | 386 | out_string = ['%s%s%s\n' % (Colors.topline,'-'*60,Colors.Normal)] | 409 | out_string = [] |
4643 | 387 | if elist: | 410 | if elist: |
4645 | 388 | out_string.append('Traceback %s(most recent call last)%s:' % \ | 411 | out_string.append('Traceback %s(most recent call last)%s:' % |
4646 | 389 | (Colors.normalEm, Colors.Normal) + '\n') | 412 | (Colors.normalEm, Colors.Normal) + '\n') |
4647 | 390 | out_string.extend(self._format_list(elist)) | 413 | out_string.extend(self._format_list(elist)) |
4648 | 391 | lines = self._format_exception_only(etype, value) | 414 | lines = self._format_exception_only(etype, value) |
4649 | @@ -492,15 +515,29 @@ | |||
4650 | 492 | else: | 515 | else: |
4651 | 493 | list.append('%s\n' % str(stype)) | 516 | list.append('%s\n' % str(stype)) |
4652 | 494 | 517 | ||
4654 | 495 | # vds:>> | 518 | # sync with user hooks |
4655 | 496 | if have_filedata: | 519 | if have_filedata: |
4656 | 497 | ipinst = ipapi.get() | 520 | ipinst = ipapi.get() |
4657 | 498 | if ipinst is not None: | 521 | if ipinst is not None: |
4658 | 499 | ipinst.hooks.synchronize_with_editor(filename, lineno, 0) | 522 | ipinst.hooks.synchronize_with_editor(filename, lineno, 0) |
4659 | 500 | # vds:<< | ||
4660 | 501 | 523 | ||
4661 | 502 | return list | 524 | return list |
4662 | 503 | 525 | ||
4663 | 526 | def show_exception_only(self, etype, value): | ||
4664 | 527 | """Only print the exception type and message, without a traceback. | ||
4665 | 528 | |||
4666 | 529 | Parameters | ||
4667 | 530 | ---------- | ||
4668 | 531 | etype : exception type | ||
4669 | 532 | value : exception value | ||
4670 | 533 | """ | ||
4671 | 534 | # This method needs to use __call__ from *this* class, not the one from | ||
4672 | 535 | # a subclass whose signature or behavior may be different | ||
4673 | 536 | Term.cout.flush() | ||
4674 | 537 | ostream = sys.stdout if self.out_stream == 'stdout' else Term.cerr | ||
4675 | 538 | ostream.write(ListTB.text(self, etype, value, [])) | ||
4676 | 539 | ostream.flush() | ||
4677 | 540 | |||
4678 | 504 | def _some_str(self, value): | 541 | def _some_str(self, value): |
4679 | 505 | # Lifted from traceback.py | 542 | # Lifted from traceback.py |
4680 | 506 | try: | 543 | try: |
4681 | @@ -781,8 +818,8 @@ | |||
4682 | 781 | frames.append(level) | 818 | frames.append(level) |
4683 | 782 | else: | 819 | else: |
4684 | 783 | frames.append('%s%s' % (level,''.join( | 820 | frames.append('%s%s' % (level,''.join( |
4687 | 784 | _formatTracebackLines(lnum,index,lines,Colors,lvals, | 821 | _format_traceback_lines(lnum,index,lines,Colors,lvals, |
4688 | 785 | col_scheme)))) | 822 | col_scheme)))) |
4689 | 786 | 823 | ||
4690 | 787 | # Get (safely) a string form of the exception info | 824 | # Get (safely) a string form of the exception info |
4691 | 788 | try: | 825 | try: |
4692 | @@ -854,11 +891,11 @@ | |||
4693 | 854 | with display_trap: | 891 | with display_trap: |
4694 | 855 | self.pdb.reset() | 892 | self.pdb.reset() |
4695 | 856 | # Find the right frame so we don't pop up inside ipython itself | 893 | # Find the right frame so we don't pop up inside ipython itself |
4697 | 857 | if hasattr(self,'tb'): | 894 | if hasattr(self,'tb') and self.tb is not None: |
4698 | 858 | etb = self.tb | 895 | etb = self.tb |
4699 | 859 | else: | 896 | else: |
4700 | 860 | etb = self.tb = sys.last_traceback | 897 | etb = self.tb = sys.last_traceback |
4702 | 861 | while self.tb.tb_next is not None: | 898 | while self.tb is not None and self.tb.tb_next is not None: |
4703 | 862 | self.tb = self.tb.tb_next | 899 | self.tb = self.tb.tb_next |
4704 | 863 | if etb and etb.tb_next: | 900 | if etb and etb.tb_next: |
4705 | 864 | etb = etb.tb_next | 901 | etb = etb.tb_next |
4706 | @@ -872,8 +909,7 @@ | |||
4707 | 872 | (etype, evalue, etb) = info or sys.exc_info() | 909 | (etype, evalue, etb) = info or sys.exc_info() |
4708 | 873 | self.tb = etb | 910 | self.tb = etb |
4709 | 874 | Term.cout.flush() | 911 | Term.cout.flush() |
4712 | 875 | print >> Term.cerr, self.text(etype, evalue, etb) | 912 | Term.cerr.writeln(self.text(etype, evalue, etb)) |
4711 | 876 | Term.cerr.flush() | ||
4713 | 877 | 913 | ||
4714 | 878 | # Changed so an instance can just be called as VerboseTB_inst() and print | 914 | # Changed so an instance can just be called as VerboseTB_inst() and print |
4715 | 879 | # out the right info on its own. | 915 | # out the right info on its own. |
4716 | @@ -980,6 +1016,7 @@ | |||
4717 | 980 | except: | 1016 | except: |
4718 | 981 | AutoTB() # or AutoTB(out=logfile) where logfile is an open file object | 1017 | AutoTB() # or AutoTB(out=logfile) where logfile is an open file object |
4719 | 982 | """ | 1018 | """ |
4720 | 1019 | |||
4721 | 983 | def __call__(self,etype=None,evalue=None,etb=None, | 1020 | def __call__(self,etype=None,evalue=None,etb=None, |
4722 | 984 | out=None,tb_offset=None): | 1021 | out=None,tb_offset=None): |
4723 | 985 | """Print out a formatted exception traceback. | 1022 | """Print out a formatted exception traceback. |
4724 | @@ -990,16 +1027,18 @@ | |||
4725 | 990 | - tb_offset: the number of frames to skip over in the stack, on a | 1027 | - tb_offset: the number of frames to skip over in the stack, on a |
4726 | 991 | per-call basis (this overrides temporarily the instance's tb_offset | 1028 | per-call basis (this overrides temporarily the instance's tb_offset |
4727 | 992 | given at initialization time. """ | 1029 | given at initialization time. """ |
4729 | 993 | 1030 | ||
4730 | 994 | if out is None: | 1031 | if out is None: |
4732 | 995 | out = Term.cerr | 1032 | out = sys.stdout if self.out_stream=='stdout' else self.out_stream |
4733 | 996 | Term.cout.flush() | 1033 | Term.cout.flush() |
4734 | 997 | if tb_offset is not None: | 1034 | if tb_offset is not None: |
4735 | 998 | tb_offset, self.tb_offset = self.tb_offset, tb_offset | 1035 | tb_offset, self.tb_offset = self.tb_offset, tb_offset |
4737 | 999 | print >> out, self.text(etype, evalue, etb) | 1036 | out.write(self.text(etype, evalue, etb)) |
4738 | 1037 | out.write('\n') | ||
4739 | 1000 | self.tb_offset = tb_offset | 1038 | self.tb_offset = tb_offset |
4740 | 1001 | else: | 1039 | else: |
4742 | 1002 | print >> out, self.text(etype, evalue, etb) | 1040 | out.write(self.text(etype, evalue, etb)) |
4743 | 1041 | out.write('\n') | ||
4744 | 1003 | out.flush() | 1042 | out.flush() |
4745 | 1004 | try: | 1043 | try: |
4746 | 1005 | self.debugger() | 1044 | self.debugger() |
4747 | 1006 | 1045 | ||
4748 | === modified file 'IPython/core/usage.py' | |||
4749 | --- IPython/core/usage.py 2009-11-09 01:49:24 +0000 | |||
4750 | +++ IPython/core/usage.py 2010-01-18 01:17:11 +0000 | |||
4751 | @@ -1,338 +1,47 @@ | |||
4752 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
4755 | 2 | #***************************************************************************** | 2 | """Usage information for the main IPython applications. |
4756 | 3 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> | 3 | """ |
4757 | 4 | #----------------------------------------------------------------------------- | ||
4758 | 5 | # Copyright (C) 2008-2010 The IPython Development Team | ||
4759 | 6 | # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu> | ||
4760 | 4 | # | 7 | # |
4761 | 5 | # Distributed under the terms of the BSD License. The full license is in | 8 | # Distributed under the terms of the BSD License. The full license is in |
4762 | 6 | # the file COPYING, distributed as part of this software. | 9 | # the file COPYING, distributed as part of this software. |
4764 | 7 | #***************************************************************************** | 10 | #----------------------------------------------------------------------------- |
4765 | 8 | 11 | ||
4766 | 9 | import sys | 12 | import sys |
4767 | 10 | from IPython.core import release | 13 | from IPython.core import release |
4768 | 11 | 14 | ||
4769 | 12 | __doc__ = """ | ||
4770 | 13 | IPython -- An enhanced Interactive Python | ||
4771 | 14 | ========================================= | ||
4772 | 15 | |||
4773 | 16 | A Python shell with automatic history (input and output), dynamic object | ||
4774 | 17 | introspection, easier configuration, command completion, access to the system | ||
4775 | 18 | shell and more. | ||
4776 | 19 | |||
4777 | 20 | IPython can also be embedded in running programs. See EMBEDDING below. | ||
4778 | 21 | |||
4779 | 22 | |||
4780 | 23 | USAGE | ||
4781 | 24 | ipython [options] files | ||
4782 | 25 | |||
4783 | 26 | If invoked with no options, it executes all the files listed in | ||
4784 | 27 | sequence and drops you into the interpreter while still acknowledging | ||
4785 | 28 | any options you may have set in your ipythonrc file. This behavior is | ||
4786 | 29 | different from standard Python, which when called as python -i will | ||
4787 | 30 | only execute one file and will ignore your configuration setup. | ||
4788 | 31 | |||
4789 | 32 | Please note that some of the configuration options are not available at | ||
4790 | 33 | the command line, simply because they are not practical here. Look into | ||
4791 | 34 | your ipythonrc configuration file for details on those. This file | ||
4792 | 35 | typically installed in the $HOME/.ipython directory. | ||
4793 | 36 | |||
4794 | 37 | For Windows users, $HOME resolves to C:\\Documents and | ||
4795 | 38 | Settings\\YourUserName in most instances, and _ipython is used instead | ||
4796 | 39 | of .ipython, since some Win32 programs have problems with dotted names | ||
4797 | 40 | in directories. | ||
4798 | 41 | |||
4799 | 42 | In the rest of this text, we will refer to this directory as | ||
4800 | 43 | IPYTHON_DIR. | ||
4801 | 44 | |||
4802 | 45 | REGULAR OPTIONS | ||
4803 | 46 | After the above threading options have been given, regular options can | ||
4804 | 47 | follow in any order. All options can be abbreviated to their shortest | ||
4805 | 48 | non-ambiguous form and are case-sensitive. One or two dashes can be | ||
4806 | 49 | used. Some options have an alternate short form, indicated after a |. | ||
4807 | 50 | |||
4808 | 51 | Most options can also be set from your ipythonrc configuration file. | ||
4809 | 52 | See the provided examples for assistance. Options given on the comman- | ||
4810 | 53 | dline override the values set in the ipythonrc file. | ||
4811 | 54 | |||
4812 | 55 | All options with a [no] prepended can be specified in negated form | ||
4813 | 56 | (using -nooption instead of -option) to turn the feature off. | ||
4814 | 57 | |||
4815 | 58 | -h, --help | ||
4816 | 59 | Show summary of options. | ||
4817 | 60 | |||
4818 | 61 | -autocall <val> | ||
4819 | 62 | Make IPython automatically call any callable object even if you | ||
4820 | 63 | didn't type explicit parentheses. For example, 'str 43' becomes | ||
4821 | 64 | 'str(43)' automatically. The value can be '0' to disable the | ||
4822 | 65 | feature, '1' for 'smart' autocall, where it is not applied if | ||
4823 | 66 | there are no more arguments on the line, and '2' for 'full' | ||
4824 | 67 | autocall, where all callable objects are automatically called | ||
4825 | 68 | (even if no arguments are present). The default is '1'. | ||
4826 | 69 | |||
4827 | 70 | -[no]autoindent | ||
4828 | 71 | Turn automatic indentation on/off. | ||
4829 | 72 | |||
4830 | 73 | -[no]automagic | ||
4831 | 74 | Make magic commands automatic (without needing their first char- | ||
4832 | 75 | acter to be %). Type %magic at the IPython prompt for more | ||
4833 | 76 | information. | ||
4834 | 77 | |||
4835 | 78 | -[no]autoedit_syntax | ||
4836 | 79 | When a syntax error occurs after editing a file, automatically | ||
4837 | 80 | open the file to the trouble causing line for convenient fixing. | ||
4838 | 81 | |||
4839 | 82 | -[no]banner | ||
4840 | 83 | Print the intial information banner (default on). | ||
4841 | 84 | |||
4842 | 85 | -c <command> | ||
4843 | 86 | Execute the given command string, and set sys.argv to ['c']. | ||
4844 | 87 | This is similar to the -c option in the normal Python inter- | ||
4845 | 88 | preter. | ||
4846 | 89 | |||
4847 | 90 | -cache_size|cs <n> | ||
4848 | 91 | Size of the output cache (maximum number of entries to hold in | ||
4849 | 92 | memory). The default is 1000, you can change it permanently in | ||
4850 | 93 | your config file. Setting it to 0 completely disables the | ||
4851 | 94 | caching system, and the minimum value accepted is 20 (if you | ||
4852 | 95 | provide a value less than 20, it is reset to 0 and a warning is | ||
4853 | 96 | issued). This limit is defined because otherwise you'll spend | ||
4854 | 97 | more time re-flushing a too small cache than working. | ||
4855 | 98 | |||
4856 | 99 | -classic|cl | ||
4857 | 100 | Gives IPython a similar feel to the classic Python prompt. | ||
4858 | 101 | |||
4859 | 102 | -colors <scheme> | ||
4860 | 103 | Color scheme for prompts and exception reporting. Currently | ||
4861 | 104 | implemented: NoColor, Linux, and LightBG. | ||
4862 | 105 | |||
4863 | 106 | -[no]color_info | ||
4864 | 107 | IPython can display information about objects via a set of func- | ||
4865 | 108 | tions, and optionally can use colors for this, syntax highlight- | ||
4866 | 109 | ing source code and various other elements. However, because | ||
4867 | 110 | this information is passed through a pager (like 'less') and | ||
4868 | 111 | many pagers get confused with color codes, this option is off by | ||
4869 | 112 | default. You can test it and turn it on permanently in your | ||
4870 | 113 | ipythonrc file if it works for you. As a reference, the 'less' | ||
4871 | 114 | pager supplied with Mandrake 8.2 works ok, but that in RedHat | ||
4872 | 115 | 7.2 doesn't. | ||
4873 | 116 | |||
4874 | 117 | Test it and turn it on permanently if it works with your system. | ||
4875 | 118 | The magic function @color_info allows you to toggle this inter- | ||
4876 | 119 | actively for testing. | ||
4877 | 120 | |||
4878 | 121 | -[no]confirm_exit | ||
4879 | 122 | Set to confirm when you try to exit IPython with an EOF (Con- | ||
4880 | 123 | trol-D in Unix, Control-Z/Enter in Windows). Note that using the | ||
4881 | 124 | magic functions @Exit or @Quit you can force a direct exit, | ||
4882 | 125 | bypassing any confirmation. | ||
4883 | 126 | |||
4884 | 127 | -[no]debug | ||
4885 | 128 | Show information about the loading process. Very useful to pin | ||
4886 | 129 | down problems with your configuration files or to get details | ||
4887 | 130 | about session restores. | ||
4888 | 131 | |||
4889 | 132 | -[no]deep_reload | ||
4890 | 133 | IPython can use the deep_reload module which reloads changes in | ||
4891 | 134 | modules recursively (it replaces the reload() function, so you | ||
4892 | 135 | don't need to change anything to use it). deep_reload() forces a | ||
4893 | 136 | full reload of modules whose code may have changed, which the | ||
4894 | 137 | default reload() function does not. | ||
4895 | 138 | |||
4896 | 139 | When deep_reload is off, IPython will use the normal reload(), | ||
4897 | 140 | but deep_reload will still be available as dreload(). This fea- | ||
4898 | 141 | ture is off by default [which means that you have both normal | ||
4899 | 142 | reload() and dreload()]. | ||
4900 | 143 | |||
4901 | 144 | -editor <name> | ||
4902 | 145 | Which editor to use with the @edit command. By default, IPython | ||
4903 | 146 | will honor your EDITOR environment variable (if not set, vi is | ||
4904 | 147 | the Unix default and notepad the Windows one). Since this editor | ||
4905 | 148 | is invoked on the fly by IPython and is meant for editing small | ||
4906 | 149 | code snippets, you may want to use a small, lightweight editor | ||
4907 | 150 | here (in case your default EDITOR is something like Emacs). | ||
4908 | 151 | |||
4909 | 152 | -ipythondir <name> | ||
4910 | 153 | The name of your IPython configuration directory IPYTHON_DIR. | ||
4911 | 154 | This can also be specified through the environment variable | ||
4912 | 155 | IPYTHON_DIR. | ||
4913 | 156 | |||
4914 | 157 | -log|l Generate a log file of all input. The file is named | ||
4915 | 158 | ipython_log.py in your current directory (which prevents logs | ||
4916 | 159 | from multiple IPython sessions from trampling each other). You | ||
4917 | 160 | can use this to later restore a session by loading your logfile | ||
4918 | 161 | as a file to be executed with option -logplay (see below). | ||
4919 | 162 | |||
4920 | 163 | -logfile|lf | ||
4921 | 164 | Specify the name of your logfile. | ||
4922 | 165 | |||
4923 | 166 | -logplay|lp | ||
4924 | 167 | Replay a previous log. For restoring a session as close as pos- | ||
4925 | 168 | sible to the state you left it in, use this option (don't just | ||
4926 | 169 | run the logfile). With -logplay, IPython will try to reconstruct | ||
4927 | 170 | the previous working environment in full, not just execute the | ||
4928 | 171 | commands in the logfile. | ||
4929 | 172 | When a session is restored, logging is automatically turned on | ||
4930 | 173 | again with the name of the logfile it was invoked with (it is | ||
4931 | 174 | read from the log header). So once you've turned logging on for | ||
4932 | 175 | a session, you can quit IPython and reload it as many times as | ||
4933 | 176 | you want and it will continue to log its history and restore | ||
4934 | 177 | from the beginning every time. | ||
4935 | 178 | |||
4936 | 179 | Caveats: there are limitations in this option. The history vari- | ||
4937 | 180 | ables _i*,_* and _dh don't get restored properly. In the future | ||
4938 | 181 | we will try to implement full session saving by writing and | ||
4939 | 182 | retrieving a failed because of inherent limitations of Python's | ||
4940 | 183 | Pickle module, so this may have to wait. | ||
4941 | 184 | |||
4942 | 185 | -[no]messages | ||
4943 | 186 | Print messages which IPython collects about its startup process | ||
4944 | 187 | (default on). | ||
4945 | 188 | |||
4946 | 189 | -[no]pdb | ||
4947 | 190 | Automatically call the pdb debugger after every uncaught excep- | ||
4948 | 191 | tion. If you are used to debugging using pdb, this puts you | ||
4949 | 192 | automatically inside of it after any call (either in IPython or | ||
4950 | 193 | in code called by it) which triggers an exception which goes | ||
4951 | 194 | uncaught. | ||
4952 | 195 | |||
4953 | 196 | -[no]pprint | ||
4954 | 197 | IPython can optionally use the pprint (pretty printer) module | ||
4955 | 198 | for displaying results. pprint tends to give a nicer display of | ||
4956 | 199 | nested data structures. If you like it, you can turn it on per- | ||
4957 | 200 | manently in your config file (default off). | ||
4958 | 201 | |||
4959 | 202 | -profile|p <name> | ||
4960 | 203 | Assume that your config file is ipythonrc-<name> (looks in cur- | ||
4961 | 204 | rent dir first, then in IPYTHON_DIR). This is a quick way to keep | ||
4962 | 205 | and load multiple config files for different tasks, especially | ||
4963 | 206 | if you use the include option of config files. You can keep a | ||
4964 | 207 | basic IPYTHON_DIR/ipythonrc file and then have other 'profiles' | ||
4965 | 208 | which include this one and load extra things for particular | ||
4966 | 209 | tasks. For example: | ||
4967 | 210 | |||
4968 | 211 | 1) $HOME/.ipython/ipythonrc : load basic things you always want. | ||
4969 | 212 | 2) $HOME/.ipython/ipythonrc-math : load (1) and basic math- | ||
4970 | 213 | related modules. | ||
4971 | 214 | 3) $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and | ||
4972 | 215 | plotting modules. | ||
4973 | 216 | |||
4974 | 217 | Since it is possible to create an endless loop by having circu- | ||
4975 | 218 | lar file inclusions, IPython will stop if it reaches 15 recur- | ||
4976 | 219 | sive inclusions. | ||
4977 | 220 | |||
4978 | 221 | -prompt_in1|pi1 <string> | ||
4979 | 222 | Specify the string used for input prompts. Note that if you are | ||
4980 | 223 | using numbered prompts, the number is represented with a '\#' in | ||
4981 | 224 | the string. Don't forget to quote strings with spaces embedded | ||
4982 | 225 | in them. Default: 'In [\#]: '. | ||
4983 | 226 | |||
4984 | 227 | Most bash-like escapes can be used to customize IPython's | ||
4985 | 228 | prompts, as well as a few additional ones which are IPython-spe- | ||
4986 | 229 | cific. All valid prompt escapes are described in detail in the | ||
4987 | 230 | Customization section of the IPython HTML/PDF manual. | ||
4988 | 231 | |||
4989 | 232 | -prompt_in2|pi2 <string> | ||
4990 | 233 | Similar to the previous option, but used for the continuation | ||
4991 | 234 | prompts. The special sequence '\D' is similar to '\#', but with | ||
4992 | 235 | all digits replaced dots (so you can have your continuation | ||
4993 | 236 | prompt aligned with your input prompt). Default: ' .\D.: ' | ||
4994 | 237 | (note three spaces at the start for alignment with 'In [\#]'). | ||
4995 | 238 | |||
4996 | 239 | -prompt_out|po <string> | ||
4997 | 240 | String used for output prompts, also uses numbers like | ||
4998 | 241 | prompt_in1. Default: 'Out[\#]:'. | ||
4999 | 242 | |||
5000 | 243 | -quick Start in bare bones mode (no config file loaded). |
Ready for review, right now it fixes the pylab support and a few other things.
Highlights:
%pylab [GUINAME]
works at any time as a magic. -pylab and -*thread also work like they used to.