11#!/usr/bin/env python3
2- #------------------------------------------------------------------------------#
32# Import everything into the top-level module namespace
4- # Have sepearate files for various categories, so we don't end up with a
5- # single enormous 12,000-line file
6- #------------------------------------------------------------------------------#
7- # Monkey patch warnings format for warnings issued by ProPlot, make sure to
8- # detect if this is just a matplotlib warning traced back to ProPlot code
9- # See: https://stackoverflow.com/a/2187390/4970632
10- # For internal warning call signature: https://docs.python.org/3/library/warnings.html#warnings.showwarning
11- # For default warning source code see: https://github.com/python/cpython/blob/master/Lib/warnings.py
3+ # Make sure to load styletools early so we can try to update TTFPATH before
4+ # the fontManager is loaded by other modules (requiring a rebuild)
5+ import os as _os
126import warnings as _warnings
7+ import pkg_resources as _pkg
8+ from .utils import _benchmark
9+ with _benchmark ('total time' ):
10+ from .utils import *
11+ with _benchmark ('styletools' ):
12+ from .styletools import *
13+ with _benchmark ('rctools' ):
14+ from .rctools import *
15+ with _benchmark ('axistools' ):
16+ from .axistools import *
17+ with _benchmark ('wrappers' ):
18+ from .wrappers import *
19+ with _benchmark ('projs' ):
20+ from .projs import *
21+ with _benchmark ('axes' ):
22+ from .axes import *
23+ with _benchmark ('subplots' ):
24+ from .subplots import *
25+
26+
1327def _warning_proplot (message , category , filename , lineno , line = None ):
28+ """
29+ Format for warnings issued by ProPlot. If this is
30+ just a matplotlib warning traced back to ProPlot code the *default*
31+ warning format is used.
32+ See the `internal warning call signature
33+ <https://docs.python.org/3/library/warnings.html#warnings.showwarning>`__
34+ and the `default warning source code
35+ <https://github.com/python/cpython/blob/master/Lib/warnings.py>`__.
36+ """
1437 if line is None :
1538 try :
1639 import linecache
@@ -22,13 +45,17 @@ def _warning_proplot(message, category, filename, lineno, line=None):
2245 else :
2346 string = f'{ filename } :{ lineno } : { category .__name__ } : { message } '
2447 if line is not None :
25- string += ('\n ' + line ) # default behavior
26- return (string + '\n ' ) # must end in newline or not shown in IPython
48+ string += ('\n ' + line ) # default behavior
49+ return (string + '\n ' ) # must end in newline or not shown in IPython
50+
51+
52+ # Apply monkeypatch
53+ # See: https://stackoverflow.com/a/2187390/4970632
2754if _warnings .formatwarning is not _warning_proplot :
2855 _warnings .formatwarning = _warning_proplot
2956
57+
3058# Initialize customization folders
31- import os as _os
3259_rc_folder = _os .path .join (_os .path .expanduser ('~' ), '.proplot' )
3360if not _os .path .isdir (_rc_folder ):
3461 _os .mkdir (_rc_folder )
@@ -45,35 +72,15 @@ def _warning_proplot(message, category, filename, lineno, line=None):
4572 lines = '' .join (
4673 '# ' + line if line .strip () and line [0 ] != '#' else line
4774 for line in f .readlines ()
48- )
75+ )
4976 with open (_rc_file , 'x' ) as f :
50- f .write ('# User default settings\n '
51- + '# See https://proplot.readthedocs.io/en/latest/rctools.html\n '
52- + lines )
53-
54- # Import stuff in reverse dependency order
55- # Make sure to load styletools early so we can try to update TTFPATH before
56- # the fontManager is loaded by other modules (requiring a rebuild)
57- from .utils import _benchmark
58- with _benchmark ('total time' ):
59- from .utils import *
60- with _benchmark ('styletools' ):
61- from .styletools import *
62- with _benchmark ('rctools' ):
63- from .rctools import *
64- with _benchmark ('axistools' ):
65- from .axistools import *
66- with _benchmark ('wrappers' ):
67- from .wrappers import *
68- with _benchmark ('projs' ):
69- from .projs import *
70- with _benchmark ('axes' ):
71- from .axes import *
72- with _benchmark ('subplots' ):
73- from .subplots import *
77+ f .write (
78+ '# User default settings\n '
79+ '# See https://proplot.readthedocs.io/en/latest/rctools.html\n '
80+ + lines
81+ )
7482
7583# SCM versioning
76- import pkg_resources as _pkg
7784name = 'proplot'
7885try :
7986 version = __version__ = _pkg .get_distribution (__name__ ).version
0 commit comments