Browse Source

Fix lint

pull/340/merge
Florian Mounier 7 years ago
parent
commit
80a6809403
  1. 1
      .gitignore
  2. 1
      .travis.yml
  3. 2
      Makefile
  4. 355
      pygal/config.py
  5. 3
      pygal/svg.py
  6. 2
      setup.cfg

1
.gitignore vendored

@ -13,3 +13,4 @@ docs/_build
build build
.env* .env*
.eggs .eggs
.pytest_cache

1
.travis.yml

@ -1,7 +1,6 @@
language: python language: python
python: python:
- 2.7 - 2.7
- 3.3
- 3.4 - 3.4
- 3.5 - 3.5
- 3.6 - 3.6

2
Makefile

@ -5,7 +5,7 @@ all: install lint check check-outdated
install: install:
test -d $(VENV) || virtualenv $(VENV) -p $(PYTHON_VERSION) test -d $(VENV) || virtualenv $(VENV) -p $(PYTHON_VERSION)
$(PIP) install --upgrade --no-cache --no-use-wheel pip setuptools -e .[test,docs] devcore $(PIP) install --upgrade --no-cache --no-binary :all: pip setuptools -e .[test,docs] devcore
clean: clean:
rm -fr $(VENV) rm -fr $(VENV)

355
pygal/config.py

@ -29,7 +29,6 @@ callable = type(lambda: 1)
class Key(object): class Key(object):
""" """
Represents a config parameter. Represents a config parameter.
@ -44,8 +43,8 @@ class Key(object):
_categories = [] _categories = []
def __init__( def __init__(
self, default_value, type_, category, doc, self, default_value, type_, category, doc, subdoc="", subtype=None
subdoc="", subtype=None): ):
"""Create a configuration key""" """Create a configuration key"""
self.value = default_value self.value = default_value
self.type = type_ self.type = type_
@ -69,10 +68,8 @@ class Key(object):
Default: %r      Default: %r     
%s%s %s%s
""" % ( """ % (
self.type.__name__, self.type.__name__, (' of %s' % self.subtype.__name__)
(' of %s' % self.subtype.__name__) if self.subtype else '', if self.subtype else '', self.value, self.doc,
self.value,
self.doc,
(' %s' % self.subdoc) if self.subdoc else '' (' %s' % self.subdoc) if self.subdoc else ''
) )
@ -107,9 +104,8 @@ class Key(object):
return value return value
elif self.type == list: elif self.type == list:
return self.type( return self.type(
map( map(self.subtype, map(lambda x: x.strip(), value.split(',')))
self.subtype, map( )
lambda x: x.strip(), value.split(','))))
elif self.type == dict: elif self.type == dict:
rv = {} rv = {}
for pair in value.split(','): for pair in value.split(','):
@ -118,14 +114,13 @@ class Key(object):
val = val.strip() val = val.strip()
try: try:
rv[key] = self.subtype(val) rv[key] = self.subtype(val)
except: except Exception:
rv[key] = val rv[key] = val
return rv return rv
return self.type(value) return self.type(value)
class MetaConfig(type): class MetaConfig(type):
"""Config metaclass. Used to get the key name and set it on the value.""" """Config metaclass. Used to get the key name and set it on the value."""
def __new__(mcs, classname, bases, classdict): def __new__(mcs, classname, bases, classdict):
@ -138,7 +133,6 @@ class MetaConfig(type):
class BaseConfig(MetaConfig('ConfigBase', (object, ), {})): class BaseConfig(MetaConfig('ConfigBase', (object, ), {})):
""" """
This class holds the common method for configs. This class holds the common method for configs.
@ -150,9 +144,8 @@ class BaseConfig(MetaConfig('ConfigBase', (object,), {})):
"""Can be instanciated with config kwargs""" """Can be instanciated with config kwargs"""
for k in dir(self): for k in dir(self):
v = getattr(self, k) v = getattr(self, k)
if (k not in self.__dict__ and not if (k not in self.__dict__ and not k.startswith('_')
k.startswith('_') and not and not hasattr(v, '__call__')):
hasattr(v, '__call__')):
if isinstance(v, Key): if isinstance(v, Key):
if v.is_list and v.value is not None: if v.is_list and v.value is not None:
v = list(v.value) v = list(v.value)
@ -170,9 +163,10 @@ class BaseConfig(MetaConfig('ConfigBase', (object,), {})):
from pygal.util import merge from pygal.util import merge
dir_self_set = set(dir(self)) dir_self_set = set(dir(self))
merge( merge(
self.__dict__, dict([ self.__dict__,
(k, v) for (k, v) in kwargs.items() dict([(k, v) for (k, v) in kwargs.items()
if not k.startswith('_') and k in dir_self_set])) if not k.startswith('_') and k in dir_self_set])
)
def to_dict(self): def to_dict(self):
"""Export a JSON serializable dictionary of the config""" """Export a JSON serializable dictionary of the config"""
@ -192,314 +186,317 @@ class BaseConfig(MetaConfig('ConfigBase', (object,), {})):
class CommonConfig(BaseConfig): class CommonConfig(BaseConfig):
"""Class holding options used in both chart and serie configuration""" """Class holding options used in both chart and serie configuration"""
stroke = Key( stroke = Key(
True, bool, "Look", True, bool, "Look", "Line dots (set it to false to get a scatter plot)"
"Line dots (set it to false to get a scatter plot)") )
show_dots = Key(True, bool, "Look", "Set to false to remove dots") show_dots = Key(True, bool, "Look", "Set to false to remove dots")
show_only_major_dots = Key( show_only_major_dots = Key(
False, bool, "Look", False, bool, "Look",
"Set to true to show only major dots according to their majored label") "Set to true to show only major dots according to their majored label"
)
dots_size = Key(2.5, float, "Look", "Radius of the dots") dots_size = Key(2.5, float, "Look", "Radius of the dots")
fill = Key( fill = Key(False, bool, "Look", "Fill areas under lines")
False, bool, "Look", "Fill areas under lines")
stroke_style = Key(None, dict, "Look", "Stroke style of serie element.", stroke_style = Key(
None, dict, "Look", "Stroke style of serie element.",
"This is a dict which can contain a " "This is a dict which can contain a "
"'width', 'linejoin', 'linecap', 'dasharray' " "'width', 'linejoin', 'linecap', 'dasharray' "
"and 'dashoffset'") "and 'dashoffset'"
)
rounded_bars = Key( rounded_bars = Key(
None, int, "Look", None, int, "Look",
"Set this to the desired radius in px (for Bar-like charts)") "Set this to the desired radius in px (for Bar-like charts)"
)
inner_radius = Key( inner_radius = Key(
0, float, "Look", "Piechart inner radius (donut), must be <.9") 0, float, "Look", "Piechart inner radius (donut), must be <.9"
)
allow_interruptions = Key( allow_interruptions = Key(
False, bool, "Look", "Break lines on None values") False, bool, "Look", "Break lines on None values"
)
formatter = Key( formatter = Key(
None, callable, "Value", None, callable, "Value",
"A function to convert raw value to strings for this chart or serie", "A function to convert raw value to strings for this chart or serie",
"Default to value_formatter in most charts, it depends on dual charts." "Default to value_formatter in most charts, it depends on dual charts."
"(Can be overriden by value with the formatter metadata.)") "(Can be overriden by value with the formatter metadata.)"
)
class Config(CommonConfig): class Config(CommonConfig):
"""Class holding config values""" """Class holding config values"""
style = Key( style = Key(
DefaultStyle, Style, "Style", "Style holding values injected in css") DefaultStyle, Style, "Style", "Style holding values injected in css"
)
css = Key( css = Key(
('file://style.css', 'file://graph.css'), list, "Style", ('file://style.css', 'file://graph.css'), list, "Style",
"List of css file", "List of css file",
"It can be any uri from file:///tmp/style.css to //domain/style.css", "It can be any uri from file:///tmp/style.css to //domain/style.css",
str) str
)
classes = Key( classes = Key(('pygal-chart', ), list, "Style",
('pygal-chart',), "Classes of the root svg node", str)
list, "Style", "Classes of the root svg node",
str)
defs = Key( defs = Key([], list, "Misc", "Extraneous defs to be inserted in svg",
[], "Useful for adding gradients / patterns…", str)
list, "Misc", "Extraneous defs to be inserted in svg",
"Useful for adding gradients / patterns…",
str)
# Look # # Look #
title = Key( title = Key(
None, str, "Look", None, str, "Look", "Graph title.", "Leave it to None to disable title."
"Graph title.", "Leave it to None to disable title.") )
x_title = Key( x_title = Key(
None, str, "Look", None, str, "Look", "Graph X-Axis title.",
"Graph X-Axis title.", "Leave it to None to disable X-Axis title.") "Leave it to None to disable X-Axis title."
)
y_title = Key( y_title = Key(
None, str, "Look", None, str, "Look", "Graph Y-Axis title.",
"Graph Y-Axis title.", "Leave it to None to disable Y-Axis title.") "Leave it to None to disable Y-Axis title."
)
width = Key( width = Key(800, int, "Look", "Graph width")
800, int, "Look", "Graph width")
height = Key( height = Key(600, int, "Look", "Graph height")
600, int, "Look", "Graph height")
show_x_guides = Key(False, bool, "Look", show_x_guides = Key(
"Set to true to always show x guide lines") False, bool, "Look", "Set to true to always show x guide lines"
)
show_y_guides = Key(True, bool, "Look", show_y_guides = Key(
"Set to false to hide y guide lines") True, bool, "Look", "Set to false to hide y guide lines"
)
show_legend = Key( show_legend = Key(True, bool, "Look", "Set to false to remove legend")
True, bool, "Look", "Set to false to remove legend")
legend_at_bottom = Key( legend_at_bottom = Key(
False, bool, "Look", "Set to true to position legend at bottom") False, bool, "Look", "Set to true to position legend at bottom"
)
legend_at_bottom_columns = Key( legend_at_bottom_columns = Key(
None, int, "Look", "Set to true to position legend at bottom") None, int, "Look", "Set to true to position legend at bottom"
)
legend_box_size = Key( legend_box_size = Key(12, int, "Look", "Size of legend boxes")
12, int, "Look", "Size of legend boxes")
rounded_bars = Key( rounded_bars = Key(
None, int, "Look", "Set this to the desired radius in px") None, int, "Look", "Set this to the desired radius in px"
)
stack_from_top = Key( stack_from_top = Key(
False, bool, "Look", "Stack from top to zero, this makes the stacked " False, bool, "Look", "Stack from top to zero, this makes the stacked "
"data match the legend order") "data match the legend order"
)
spacing = Key( spacing = Key(10, int, "Look", "Space between titles/legend/axes")
10, int, "Look",
"Space between titles/legend/axes")
margin = Key( margin = Key(20, int, "Look", "Margin around chart")
20, int, "Look",
"Margin around chart")
margin_top = Key( margin_top = Key(None, int, "Look", "Margin around top of chart")
None, int, "Look",
"Margin around top of chart")
margin_right = Key( margin_right = Key(None, int, "Look", "Margin around right of chart")
None, int, "Look",
"Margin around right of chart")
margin_bottom = Key( margin_bottom = Key(None, int, "Look", "Margin around bottom of chart")
None, int, "Look",
"Margin around bottom of chart")
margin_left = Key( margin_left = Key(None, int, "Look", "Margin around left of chart")
None, int, "Look",
"Margin around left of chart")
tooltip_border_radius = Key(0, int, "Look", "Tooltip border radius") tooltip_border_radius = Key(0, int, "Look", "Tooltip border radius")
tooltip_fancy_mode = Key( tooltip_fancy_mode = Key(
True, bool, "Look", "Fancy tooltips", True, bool, "Look", "Fancy tooltips",
"Print legend, x label in tooltip and use serie color for value.") "Print legend, x label in tooltip and use serie color for value."
)
inner_radius = Key( inner_radius = Key(
0, float, "Look", "Piechart inner radius (donut), must be <.9") 0, float, "Look", "Piechart inner radius (donut), must be <.9"
)
half_pie = Key( half_pie = Key(False, bool, "Look", "Create a half-pie chart")
False, bool, "Look", "Create a half-pie chart")
x_labels = Key( x_labels = Key(
None, list, "Label", None, list, "Label", "X labels, must have same len than data.",
"X labels, must have same len than data.", "Leave it to None to disable x labels display.", str
"Leave it to None to disable x labels display.", )
str)
x_labels_major = Key( x_labels_major = Key(
None, list, "Label", None,
list,
"Label",
"X labels that will be marked major.", "X labels that will be marked major.",
subtype=str) subtype=str
)
x_labels_major_every = Key( x_labels_major_every = Key(
None, int, "Label", None, int, "Label", "Mark every n-th x label as major."
"Mark every n-th x label as major.") )
x_labels_major_count = Key( x_labels_major_count = Key(
None, int, "Label", None, int, "Label", "Mark n evenly distributed labels as major."
"Mark n evenly distributed labels as major.") )
show_x_labels = Key( show_x_labels = Key(True, bool, "Label", "Set to false to hide x-labels")
True, bool, "Label", "Set to false to hide x-labels")
show_minor_x_labels = Key( show_minor_x_labels = Key(
True, bool, "Label", "Set to false to hide x-labels not marked major") True, bool, "Label", "Set to false to hide x-labels not marked major"
)
y_labels = Key( y_labels = Key(
None, list, "Label", None, list, "Label", "You can specify explicit y labels",
"You can specify explicit y labels", "Must be a list of numbers", float
"Must be a list of numbers", float) )
y_labels_major = Key( y_labels_major = Key(
None, list, "Label", None,
list,
"Label",
"Y labels that will be marked major. Default: auto", "Y labels that will be marked major. Default: auto",
subtype=str) subtype=str
)
y_labels_major_every = Key( y_labels_major_every = Key(
None, int, "Label", None, int, "Label", "Mark every n-th y label as major."
"Mark every n-th y label as major.") )
y_labels_major_count = Key( y_labels_major_count = Key(
None, int, "Label", None, int, "Label", "Mark n evenly distributed y labels as major."
"Mark n evenly distributed y labels as major.") )
show_minor_y_labels = Key( show_minor_y_labels = Key(
True, bool, "Label", "Set to false to hide y-labels not marked major") True, bool, "Label", "Set to false to hide y-labels not marked major"
)
show_y_labels = Key( show_y_labels = Key(True, bool, "Label", "Set to false to hide y-labels")
True, bool, "Label", "Set to false to hide y-labels")
x_label_rotation = Key( x_label_rotation = Key(
0, int, "Label", "Specify x labels rotation angles", "in degrees") 0, int, "Label", "Specify x labels rotation angles", "in degrees"
)
y_label_rotation = Key( y_label_rotation = Key(
0, int, "Label", "Specify y labels rotation angles", "in degrees") 0, int, "Label", "Specify y labels rotation angles", "in degrees"
)
missing_value_fill_truncation = Key( missing_value_fill_truncation = Key(
"x", str, "Look", "x", str, "Look",
"Filled series with missing x and/or y values at the end of a series " "Filled series with missing x and/or y values at the end of a series "
"are closed at the first value with a missing " "are closed at the first value with a missing "
"'x' (default), 'y' or 'either'") "'x' (default), 'y' or 'either'"
)
# Value # # Value #
x_value_formatter = Key( x_value_formatter = Key(
formatters.default, callable, "Value", formatters.default, callable, "Value",
"A function to convert abscissa numeric value to strings " "A function to convert abscissa numeric value to strings "
"(used in XY and Date charts)") "(used in XY and Date charts)"
)
value_formatter = Key( value_formatter = Key(
formatters.default, callable, "Value", formatters.default, callable, "Value",
"A function to convert ordinate numeric value to strings") "A function to convert ordinate numeric value to strings"
)
logarithmic = Key( logarithmic = Key(
False, bool, "Value", "Display values in logarithmic scale") False, bool, "Value", "Display values in logarithmic scale"
)
interpolate = Key( interpolate = Key(
None, str, "Value", "Interpolation", None, str, "Value", "Interpolation",
"May be %s" % ' or '.join(INTERPOLATIONS)) "May be %s" % ' or '.join(INTERPOLATIONS)
)
interpolation_precision = Key( interpolation_precision = Key(
250, int, "Value", "Number of interpolated points between two values") 250, int, "Value", "Number of interpolated points between two values"
)
interpolation_parameters = Key( interpolation_parameters = Key(
{}, dict, "Value", "Various parameters for parametric interpolations", {}, dict, "Value", "Various parameters for parametric interpolations",
"ie: For hermite interpolation, you can set the cardinal tension with" "ie: For hermite interpolation, you can set the cardinal tension with"
"{'type': 'cardinal', 'c': .5}", int) "{'type': 'cardinal', 'c': .5}", int
)
box_mode = Key( box_mode = Key(
'extremes', str, "Value", "Sets the mode to be used. " 'extremes', str, "Value", "Sets the mode to be used. "
"(Currently only supported on box plot)", "(Currently only supported on box plot)", "May be %s" %
"May be %s" % ' or '.join([ ' or '.join(["1.5IQR", "extremes", "tukey", "stdev", "pstdev"])
"1.5IQR", "extremes", "tukey", "stdev", "pstdev"])) )
order_min = Key( order_min = Key(
None, int, "Value", None, int, "Value", "Minimum order of scale, defaults to None"
"Minimum order of scale, defaults to None") )
min_scale = Key( min_scale = Key(
4, int, "Value", 4, int, "Value", "Minimum number of scale graduation for auto scaling"
"Minimum number of scale graduation for auto scaling") )
max_scale = Key( max_scale = Key(
16, int, "Value", 16, int, "Value", "Maximum number of scale graduation for auto scaling"
"Maximum number of scale graduation for auto scaling") )
range = Key( range = Key(
None, list, "Value", "Explicitly specify min and max of values", None, list, "Value", "Explicitly specify min and max of values",
"(ie: (0, 100))", int) "(ie: (0, 100))", int
)
secondary_range = Key( secondary_range = Key(
None, list, "Value", None, list, "Value",
"Explicitly specify min and max of secondary values", "Explicitly specify min and max of secondary values", "(ie: (0, 100))",
"(ie: (0, 100))", int) int
)
xrange = Key( xrange = Key(
None, list, "Value", "Explicitly specify min and max of x values " None, list, "Value", "Explicitly specify min and max of x values "
"(used in XY and Date charts)", "(used in XY and Date charts)", "(ie: (0, 100))", int
"(ie: (0, 100))", int) )
include_x_axis = Key( include_x_axis = Key(False, bool, "Value", "Always include x axis")
False, bool, "Value", "Always include x axis")
zero = Key( zero = Key(
0, int, "Value", 0, int, "Value", "Set the ordinate zero value",
"Set the ordinate zero value", "Useful for filling to another base than abscissa"
"Useful for filling to another base than abscissa") )
# Text # # Text #
no_data_text = Key( no_data_text = Key(
"No data", str, "Text", "Text to display when no data is given") "No data", str, "Text", "Text to display when no data is given"
)
print_values = Key( print_values = Key(False, bool, "Text", "Display values as text over plot")
False, bool,
"Text", "Display values as text over plot")
dynamic_print_values = Key( dynamic_print_values = Key(
False, bool, False, bool, "Text", "Show values only on hover"
"Text", "Show values only on hover") )
print_values_position = Key( print_values_position = Key(
'center', str, 'center', str, "Text", "Customize position of `print_values`. "
"Text", "Customize position of `print_values`. " "(For bars: `top`, `center` or `bottom`)"
"(For bars: `top`, `center` or `bottom`)") )
print_zeroes = Key( print_zeroes = Key(True, bool, "Text", "Display zero values as well")
True, bool,
"Text", "Display zero values as well")
print_labels = Key( print_labels = Key(False, bool, "Text", "Display value labels")
False, bool,
"Text", "Display value labels")
truncate_legend = Key( truncate_legend = Key(
None, int, "Text", None, int, "Text", "Legend string length truncation threshold",
"Legend string length truncation threshold", "None = auto, Negative for none"
"None = auto, Negative for none") )
truncate_label = Key( truncate_label = Key(
None, int, "Text", None, int, "Text", "Label string length truncation threshold",
"Label string length truncation threshold", "None = auto, Negative for none"
"None = auto, Negative for none") )
# Misc # # Misc #
js = Key( js = Key(('//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js', ),
('//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js',),
list, "Misc", "List of js file", list, "Misc", "List of js file",
"It can be any uri from file:///tmp/ext.js to //domain/ext.js", "It can be any uri from file:///tmp/ext.js to //domain/ext.js",
str) str)
@ -507,39 +504,37 @@ class Config(CommonConfig):
disable_xml_declaration = Key( disable_xml_declaration = Key(
False, bool, "Misc", False, bool, "Misc",
"Don't write xml declaration and return str instead of string", "Don't write xml declaration and return str instead of string",
"useful for writing output directly in html") "useful for writing output directly in html"
)
force_uri_protocol = Key( force_uri_protocol = Key(
'https', str, "Misc", 'https', str, "Misc", "Default uri protocol",
"Default uri protocol",
"Default protocol for external files. " "Default protocol for external files. "
"Can be set to None to use a // uri") "Can be set to None to use a // uri"
)
explicit_size = Key( explicit_size = Key(
False, bool, "Misc", "Write width and height attributes") False, bool, "Misc", "Write width and height attributes"
)
pretty_print = Key( pretty_print = Key(False, bool, "Misc", "Pretty print the svg")
False, bool, "Misc", "Pretty print the svg")
strict = Key( strict = Key(
False, bool, "Misc", False, bool, "Misc", "If True don't try to adapt / filter wrong values"
"If True don't try to adapt / filter wrong values") )
no_prefix = Key( no_prefix = Key(False, bool, "Misc", "Don't prefix css")
False, bool, "Misc",
"Don't prefix css")
inverse_y_axis = Key(False, bool, "Misc", "Inverse Y axis direction") inverse_y_axis = Key(False, bool, "Misc", "Inverse Y axis direction")
class SerieConfig(CommonConfig): class SerieConfig(CommonConfig):
"""Class holding serie config values""" """Class holding serie config values"""
title = Key( title = Key(
None, str, "Look", None, str, "Look", "Serie title.", "Leave it to None to disable title."
"Serie title.", "Leave it to None to disable title.") )
secondary = Key( secondary = Key(
False, bool, "Misc", False, bool, "Misc", "Set it to put the serie in a second axis"
"Set it to put the serie in a second axis") )

3
pygal/svg.py

@ -494,5 +494,6 @@ class Svg(object):
for secondary_serie in self.graph.secondary_series: for secondary_serie in self.graph.secondary_series:
if secondary_serie.stroke_style is not None: if secondary_serie.stroke_style is not None:
css.append(stroke_dict_to_css(secondary_serie.stroke_style, secondary_serie.index)) css.append(stroke_dict_to_css(
secondary_serie.stroke_style, secondary_serie.index))
return '\n'.join(css) return '\n'.join(css)

2
setup.cfg

@ -3,7 +3,7 @@ universal = 1
[pytest] [pytest]
flake8-ignore = flake8-ignore =
*.py E731 E402 *.py E731 E402 E741
pygal/__init__.py F401 pygal/__init__.py F401
pygal/_compat.py F821 F401 pygal/_compat.py F821 F401
docs/conf.py ALL docs/conf.py ALL

Loading…
Cancel
Save