Skip to content

Commit

Permalink
added backend as configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
robdmc committed Jul 24, 2015
1 parent 5849109 commit 3ed0401
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
37 changes: 27 additions & 10 deletions pandashells/lib/config_lib.py
Expand Up @@ -6,16 +6,33 @@
CONFIG_FILE_NAME = '.pandashells'

# --- valid options (option_name, [valid, option, list])
CONFIG_OPTS = sorted([
('io_input_type', ['csv', 'table']),
('io_output_type', ['csv', 'table', 'html']),
('io_input_header', ['header', 'noheader']),
('io_output_header', ['header', 'noheader']),
('io_output_index', ['noindex', 'index']),
('io_output_na_rep', ['nan', 'NaN', '', '-']),
('plot_context', ['talk', 'poster', 'paper', 'notebook']),
('plot_theme', ['darkgrid', 'whitegrid', 'dark', 'white']),
('plot_palette', ['muted', 'deep', 'dark', 'colorblind', 'pastel'])])
CONFIG_OPTS = sorted(
[
('io_input_type', ['csv', 'table']),
('io_output_type', ['csv', 'table', 'html']),
('io_input_header', ['header', 'noheader']),
('io_output_header', ['header', 'noheader']),
('io_output_index', ['noindex', 'index']),
('io_output_na_rep', ['nan', 'NaN', '', '-']),
('plot_context', ['talk', 'poster', 'paper', 'notebook']),
('plot_theme', ['darkgrid', 'whitegrid', 'dark', 'white']),
('plot_palette', ['muted', 'deep', 'dark', 'colorblind', 'pastel']),
('plot_backend', [
'TkAgg',
'CocoaAgg',
'GTK',
'GTK3Cairo',
'GTKAgg',
'GTKCairo',
'MacOSX',
'Qt4Agg',
'WX',
'WXAgg'
'cairo',
]),

]
)

# --- create a dictionary out of the config options
DEFAULT_DICT = {t[0]: t[1][0] for t in CONFIG_OPTS}
Expand Down
7 changes: 6 additions & 1 deletion pandashells/lib/module_checker_lib.py
@@ -1,5 +1,6 @@
#! /usr/bin/env python
import importlib
from pandashells.lib import config_lib

# --- define the default error message to show when a module can't be found
HEADER = "\n\nThis tool requires packages that have not been installed.\n"
Expand Down Expand Up @@ -34,9 +35,13 @@ def check_for_modules(module_list):
msg = ''

# --- try importing all the required mojkdules
for module in module_list:
for module in sorted(module_list):
try:
importlib.import_module(module)
if module == 'matplotlib':
CONFIG = config_lib.get_config()
import matplotlib
matplotlib.use(CONFIG['plot_backend'])
except ImportError:
# --- add to error message for each bad module
msg = msg if msg else HEADER
Expand Down
1 change: 1 addition & 0 deletions pandashells/lib/plot_lib.py
Expand Up @@ -8,6 +8,7 @@
module_checker_lib.check_for_modules(
['matplotlib', 'dateutil', 'mpld3', 'seaborn'])


from dateutil.parser import parse
import matplotlib as mpl
import pylab as pl
Expand Down

0 comments on commit 3ed0401

Please sign in to comment.