Stephen Walton wrote:
>> Fernando Perez wrote:
>>> Well, it could be something like $HOME/.tex.cache, where $HOME
>>> can be determined via a routine like the below (this is what
>>> ipython uses to try and guess a sensible value for $HOME):
>> I *like* it.
> Though I'd personally vote for matplotlib holding
> $HOME/.matplotlib/ as a directory, and putting in there
> a tex.cache dir, the matplotlibrc file, and anything
> else it may need in the future.
I am in the process of moving all of matplotlib's config files and
outputs to HOME/.matplotlib.
I want to issue a warning to users if I find a .matplotlibrc file (the
new name is matplotlibrc (no hidden "dot") and the default location is
HOME/.matplotlib/matplotlibrc. As before, you can put an rc file in
the current dir.
I am using warnings.warn to issue the warning
home = get_home()
oldname = os.path.join( home, '.matplotlibrc')
if os.path.exists(oldname):
warnings.warn('Old rc filename "%s" found and ignored; new default rc file name is HOME/.matplotlib/matplotlibrc"'%oldname)
But this results in a warning that looks like this
> python ~/python/projects/matplotlib/examples/subplot_demo.py
/usr/lib/python2.4/site-packages/matplotlib/__init__.py:737: UserWarning: Old rc filename "/home/jdhunter/.matplotlibrc" found and ignored; new default rc file name is HOME/.matplotlib/matplotlibrc"
warnings.warn('Old rc filename "%s" found and ignored; new default rc file name is HOME/.matplotlib/matplotlibrc"'%oldname)
which I find hard to read. I can add a stacklevel=0 argument to warn
which is slightly more legible
> python ~/python/projects/matplotlib/examples/subplot_demo.py
/usr/lib/python2.4/warnings.py:41: UserWarning: Old rc filename "/home/jdhunter/.matplotlibrc" found and ignored; new default rc file name is HOME/.matplotlib/matplotlibrc"
lineno = caller.f_lineno
but still has the annoying "lineno = caller.f_lineno"
what I am really after is a simple print >> sys.stderr. Is there
anything wrong with using sys.stderr for this kind of thing, error
mavens? I know when we discussed this many moons ago we converged on
using exceptions and the warnings module everywhere. But now I am a
bit confounded by the inability to make the warnings print pretty
messages that the typical user will read and understand. Or is there
a way to tell warning.warn to just print the error message with no
lineno/traceback info?
JDH