New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
utils.io.Term.cin/out/err -> utils.io.stdin/out/err #397
Conversation
I don't like this, but it is probably OK until we figure out a better way of initializing stuff like this. At some level, things like this and logging need to be setup at the Application level - IE, before things like InteractiveShell are created. |
What is the argument against We need to ensure one of the following:
And we do neither, but code assumes we have done 2. You are right that it should be configured at the application level like logging, but it should also be like logging and not raise an error if used prior to configuration. logging is silent if unconfigured, and I think sys.stdin/out/err is the most reasonable default for our object that's an abstraction of exactly those streams. |
I think that stdout/stdin/stderr are fine defaults, I am just not excited about hardcoding defaults into a top-level module variable. Sort of goes against our model of defaults and configuration. I guess it would make sense to have a model that is similar to that of logging though, maybe have a get_term function in io.py. I do agree that it should work even before configuration like logging does. The most important aspect of Term is that other modules that need to use Term should get it in a way that is robust. The old, from io import Term is horrible because if io.Term changes, the code doesn't see that. That is why we removed io.Term in the first place. So maybe the logging model does make sense. |
What about having top-level stdin/out/err like sys? (or cin/out/err, if that's preferable for some reason). Then it's quite familiar that the top-level object (
Side question: Is there a reason that io.Term is capitalized? |
I like the idea of echoing the design of sys.stdout and friends with io.stdout|stdin|stderr and I think this is probably the way to go. The naming of "Term" is historical and even the name term (which suggests "terminal" is horrible at this point. I don't see any reason to not move to this new API. |
Okay, this has now been updated, such that The |
This is wonderful. The changes are pretty simple. Have you tested the qt console with this branch as we point things to zmq enabled out streams? I don't see any issues though. Some things we should look at after this is merged:
|
Min, have you tested this on Windows? If not, could you do that (I don't have a Windows VM setup right now). Fernando wanted to make sure that the terminal still works with colors (try 1/0 to make sure colored exceptions are working) before merging. I need to get a VM setup for this stuff... |
I didn't change how anything works on the inside of the IOStream class, so it should behave the same. I did test on Windows, and 1/0 does produce the expected colorful output. As there is no color related code in utils.io, I presume it is the linking of stdout/err to readline._outputfile that allows colors on Windows? That code is the same as before. I'll just rebase on master, and it should be ready then. |
Behavior is now the same as sys.stdin/out/err, and defaults to those streams.
This allows io.stdout/err to be captured during tests
rebased on master, tests passing, colors working. |
Great, I will merge shortly On Wed, Apr 27, 2011 at 11:41 AM, minrk
Brian E. Granger |
utils.io.Term.cin/out/err -> utils.io.stdin/out/err
utils.io.Term.cin/out/err -> utils.io.stdin/out/err
There are a variety of methods that depend on
io.Term
existing, and some of these can be called before io.Term is created, and none of them check for its existence.Possible solutions are:
io.Term
always exists, but may be overriddenio.Term
before using itThis PR implements 1., by adding simple
Term=IOTerm()
inutils.io.py
.An example of the failure: missing readline.
init_readline()
can display warnings viautils.warn
, which depends onio.Term
. However,init_io()
must be called afterinit_readline()
, so these warnings will always crash IPython.