Opened 8 years ago
Closed 8 years ago
#14188 closed enhancement (fixed)
IPython 0.13: merge user configuration with Sage configuration
Reported by:  jhpalmieri  Owned by:  jason 

Priority:  minor  Milestone:  sage5.8 
Component:  misc  Keywords:  IPython config 
Cc:  vbraun, jason  Merged in:  sage5.8.beta3 
Authors:  John Palmieri, Volker Braun  Reviewers:  Volker Braun, William Stein, John Palmieri 
Report Upstream:  N/A  Work issues:  
Branch:  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
After #12719, user configuration files (in .sage/ipython0.12/profile_default/
and .../profile_sage/
) seem to be effectively ignored: I think they are read after the Sage terminal app has already been initialized, at which point it is too late.
The attached patch remedies this, reading the configuration from .sage/ipython0.12/profile_default/ipython_config.py
during the initialization. Question: should it read from this directory or from profile_sage
?
Apply trac_14188_vb.patch and trac_14188_docfix.patch
Attachments (2)
Change History (25)
comment:1 Changed 8 years ago by
comment:2 Changed 8 years ago by
 Status changed from new to needs_review
comment:3 Changed 8 years ago by
Here's a new version which reads from profile_sage
.
comment:4 Changed 8 years ago by
I changed your code to override load_config_file()
instead of stuffing it in the ctor. Now the configuration is only loaded once, as one can easily check by putting a print statement into ipython_config.py
.
Also, after discussion with Jason and William we decided to default to colors in the terminal. For simplicity I just added this into this patch.
comment:5 Changed 8 years ago by
 Description modified (diff)
 Reviewers set to Volker Braun, William Stein
And I agree with your changes, of course. Feel free to set it to positive review if you are happy with it.
comment:6 Changed 8 years ago by
 Reviewers changed from Volker Braun, William Stein to Volker Braun, William Stein, John Palmieri
 Status changed from needs_review to positive_review
comment:7 Changed 8 years ago by
Apply trac_14188_vb.patch
comment:8 Changed 8 years ago by
 Description modified (diff)
And IPython is of course not smart enough to turn off colors when the output is a pipe, thanks a bunch. The second patch is the oneline fix to do it by hand.
comment:9 Changed 8 years ago by
 Status changed from positive_review to needs_work
comment:10 Changed 8 years ago by
 Description modified (diff)
 Status changed from needs_work to needs_review
Second patch needs review.
comment:11 Changed 8 years ago by
If someone customizes their IPython configuration, this can cause doctests to fail (for example, if you turn on an output prompt like "Out[1]:", interfaces/sage0.py fails). I think this is okay, but I'm going to post at #12415 about it.
comment:12 Changed 8 years ago by
 Status changed from needs_review to positive_review
All tests passed.
comment:13 Changed 8 years ago by
 Status changed from positive_review to needs_work
I see doctest failures on OS X 10.6: http://build.sagemath.org/sage/builders/UW%20bsd%20%28OSX%2010.6%20x86_64%29/builds/214/steps/shell_8/logs/stdio
comment:14 Changed 8 years ago by
Same problem on lena (Fedora 16 x86_64): http://build.sagemath.org/sage/builders/Skynet%20lena%20%28Fedora%2016%20x86_64%29/builds/113/steps/shell_7/logs/stdio
comment:15 Changed 8 years ago by
I see this on bsd.math.washington.edu (OS X 10.6), but I have no problems on lena.
comment:16 followup: ↓ 18 Changed 8 years ago by
A typical failure on OS X 10.6:
sage: subsage = Sage() sage: s = ZZ(subsage('initial_seed()')) <boom>
It looks like when running Sage as a subprocess on this platform, sys.stdout.isatty()
returns True
, even while doctesting. How else can we detect this situation?
comment:17 Changed 8 years ago by
Pexpect runs in a pty, so on any platform isatty() will return true. This is why we explicitly disable colors when starting a sageinsage session. My current theory is that the pty gets messed up somehow by the ansi codes since we disable colors by sending %colors NoColor
, so at least one colored prompt will be displayed. I'm currently trying if disabling color via command line switch works...
comment:18 in reply to: ↑ 16 Changed 8 years ago by
Replying to jhpalmieri:
How else can we detect this situation?
pexpect children have the environment variable TERM
unset (#12221, similar: #12263). We did this precisely to solve problems like this where the terminal did strange things.
sage: "TERM" in os.environ True sage: sage0('"TERM" in os.environ') False
comment:19 Changed 8 years ago by
A change like this fixes the failures on bsd.math.washington.edu. I haven't run a full test suite yet.

sage/misc/interpreter.py
diff git a/sage/misc/interpreter.py b/sage/misc/interpreter.py
a b 660 660 verbose_crash = True), 661 661 TerminalInteractiveShell = Config( 662 662 ast_node_interactivity = 'all', 663 colors = 'LightBG' if sys.stdout.isatty() else 'NoColor',663 colors = 'LightBG' if (sys.stdout.isatty() and 'TERM' in os.environ) else 'NoColor', 664 664 confirm_exit = False, 665 665 separate_in = ''), 666 666 # The extension is *always* loaded for SageTerminalApp
comment:20 Changed 8 years ago by
I'd rather always turn off colors in the sage<>sage interface than rely on the TERM
variable. The updated patch fixes sage0 on OSX (bsd.math) for me.
comment:21 Changed 8 years ago by
 Status changed from needs_work to needs_review
comment:22 Changed 8 years ago by
 Status changed from needs_review to positive_review
This passes tests for me on bsd.
comment:23 Changed 8 years ago by
 Merged in set to sage5.8.beta3
 Resolution set to fixed
 Status changed from positive_review to closed
It should read from
/profile_sage/ipython_config.py
for sure.