diff --git a/pygal/config.py b/pygal/config.py
index a89239c..af2ef1e 100644
--- a/pygal/config.py
+++ b/pygal/config.py
@@ -23,7 +23,7 @@ Config module with all options
from copy import deepcopy
from pygal.style import Style, DefaultStyle
from pygal.interpolate import INTERPOLATIONS
-
+from pygal.css import style_css, graph_css
CONFIG_ITEMS = []
@@ -170,9 +170,9 @@ class Config(CommonConfig):
DefaultStyle, Style, "Style", "Style holding values injected in css")
css = Key(
- ('style.css', 'graph.css'), list, "Style",
+ (style_css, graph_css), list, "Style",
"List of css file",
- "It can be an absolute file path or an external link",
+ "It can be an absolute file path, an external link or a python module exporting the string variable data containing the .css style",
str)
# Look #
diff --git a/pygal/css/__init__.py b/pygal/css/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pygal/css/base.css b/pygal/css/base_css.py
similarity index 99%
rename from pygal/css/base.css
rename to pygal/css/base_css.py
index 8837ca4..f133990 100644
--- a/pygal/css/base.css
+++ b/pygal/css/base_css.py
@@ -1,3 +1,4 @@
+data = """\
/*
* This file is part of pygal
*
@@ -55,3 +56,4 @@
{{ id }}text.no_data {
font-size: {{ font_sizes.no_data }};
}
+"""
\ No newline at end of file
diff --git a/pygal/css/graph.css b/pygal/css/graph_css.py
similarity index 99%
rename from pygal/css/graph.css
rename to pygal/css/graph_css.py
index 095e7bc..a8dc0be 100644
--- a/pygal/css/graph.css
+++ b/pygal/css/graph_css.py
@@ -1,3 +1,4 @@
+data="""\
/*
* This file is part of pygal
*
@@ -126,3 +127,4 @@
{{ id }}.tooltip text tspan.label {
fill-opacity: .8;
}
+"""
\ No newline at end of file
diff --git a/pygal/css/style.css b/pygal/css/style_css.py
similarity index 99%
rename from pygal/css/style.css
rename to pygal/css/style_css.py
index 2c3f708..8c152b3 100644
--- a/pygal/css/style.css
+++ b/pygal/css/style_css.py
@@ -1,3 +1,4 @@
+data="""\
/*
* This file is part of pygal
*
@@ -139,3 +140,4 @@
{{ colors }}
+"""
\ No newline at end of file
diff --git a/pygal/graph/frenchmap.py b/pygal/graph/frenchmap.py
index 78125bb..e4479f4 100644
--- a/pygal/graph/frenchmap.py
+++ b/pygal/graph/frenchmap.py
@@ -169,12 +169,7 @@ REGIONS = {
'06': u("Mayotte")
}
-
-with open(os.path.join(
- os.path.dirname(__file__), 'maps',
- 'fr.departments.svg')) as file:
- DPT_MAP = file.read()
-
+from .maps.fr_departments_svg import data as DPT_MAP
class IntCodeMixin(object):
def adapt_code(self, area_code):
@@ -194,12 +189,7 @@ class FrenchMapDepartments(IntCodeMixin, BaseMap):
kind = 'departement'
svg_map = DPT_MAP
-
-with open(os.path.join(
- os.path.dirname(__file__), 'maps',
- 'fr.regions.svg')) as file:
- REG_MAP = file.read()
-
+from .maps.fr_regions_svg import data as REG_MAP
class FrenchMapRegions(IntCodeMixin, BaseMap):
"""French regions map"""
diff --git a/pygal/graph/maps/__init__.py b/pygal/graph/maps/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pygal/graph/maps/ch.cantons.svg b/pygal/graph/maps/ch_cantons_svg.py
similarity index 99%
rename from pygal/graph/maps/ch.cantons.svg
rename to pygal/graph/maps/ch_cantons_svg.py
index 7f016ad..ee0836e 100644
--- a/pygal/graph/maps/ch.cantons.svg
+++ b/pygal/graph/maps/ch_cantons_svg.py
@@ -1,3 +1,4 @@
+data = """\
-
+"""
diff --git a/pygal/graph/maps/fr.departments.svg b/pygal/graph/maps/fr_departments_svg.py
similarity index 99%
rename from pygal/graph/maps/fr.departments.svg
rename to pygal/graph/maps/fr_departments_svg.py
index 0d02fbd..c2b3384 100644
--- a/pygal/graph/maps/fr.departments.svg
+++ b/pygal/graph/maps/fr_departments_svg.py
@@ -1,3 +1,4 @@
+data="""\
+"""
\ No newline at end of file
diff --git a/pygal/graph/maps/fr.regions.svg b/pygal/graph/maps/fr_regions_svg.py
similarity index 99%
rename from pygal/graph/maps/fr.regions.svg
rename to pygal/graph/maps/fr_regions_svg.py
index 046c62d..4121d27 100644
--- a/pygal/graph/maps/fr.regions.svg
+++ b/pygal/graph/maps/fr_regions_svg.py
@@ -1,3 +1,4 @@
+data="""\
+"""
\ No newline at end of file
diff --git a/pygal/graph/maps/worldmap.svg b/pygal/graph/maps/worldmap_svg.py
similarity index 99%
rename from pygal/graph/maps/worldmap.svg
rename to pygal/graph/maps/worldmap_svg.py
index b024ce1..4546b28 100644
--- a/pygal/graph/maps/worldmap.svg
+++ b/pygal/graph/maps/worldmap_svg.py
@@ -1,3 +1,4 @@
+data="""\
+"""
\ No newline at end of file
diff --git a/pygal/graph/swissmap.py b/pygal/graph/swissmap.py
index 384cf05..19cc457 100644
--- a/pygal/graph/swissmap.py
+++ b/pygal/graph/swissmap.py
@@ -56,12 +56,7 @@ CANTONS = {
'kt-ge': u("Genf"),
}
-
-with open(os.path.join(
- os.path.dirname(__file__), 'maps',
- 'ch.cantons.svg')) as file:
- CNT_MAP = file.read()
-
+from .maps.ch_cantons_svg import data as CNT_MAP
class SwissMapCantons(BaseMap):
"""Swiss Cantons map"""
diff --git a/pygal/graph/worldmap.py b/pygal/graph/worldmap.py
index a98a2f7..9141bb9 100644
--- a/pygal/graph/worldmap.py
+++ b/pygal/graph/worldmap.py
@@ -27,12 +27,7 @@ from pygal.graph.map import BaseMap
from pygal.i18n import COUNTRIES, SUPRANATIONAL
import os
-
-with open(os.path.join(
- os.path.dirname(__file__), 'maps',
- 'worldmap.svg')) as file:
- WORLD_MAP = file.read()
-
+from .maps.worldmap_svg import data as WORLD_MAP
class Worldmap(BaseMap):
"""Worldmap graph"""
diff --git a/pygal/svg.py b/pygal/svg.py
index 169f33d..e98ebb8 100644
--- a/pygal/svg.py
+++ b/pygal/svg.py
@@ -32,6 +32,7 @@ from numbers import Number
from math import cos, sin, pi
from pygal.util import template, coord_format, minify_css
from pygal import __version__
+from pygal.css import base_css
class Svg(object):
@@ -83,36 +84,39 @@ class Svg(object):
"""Add the css to the svg"""
colors = self.graph.style.get_colors(self.id)
all_css = []
- for css in ['base.css'] + list(self.graph.css):
- if '://' in css:
+ for css in [base_css] + list(self.graph.css):
+ if type(css) == str and '://' in css:
self.processing_instructions.append(
etree.PI(
u('xml-stylesheet'), u('href="%s"' % css)))
else:
- if css.startswith('inline:'):
+ if type(css) == str and css.startswith('inline:'):
css_text = css[len('inline:'):]
else:
- if not os.path.exists(css):
- css = os.path.join(
- os.path.dirname(__file__), 'css', css)
+ if type(css) == str:
+ if not os.path.exists(css):
+ css = os.path.join(
+ os.path.dirname(__file__), 'css', css)
- class FontSizes(object):
- """Container for font sizes"""
- fs = FontSizes()
- for name in dir(self.graph.state):
- if name.endswith('_font_size'):
- setattr(
- fs,
- name.replace('_font_size', ''),
- ('%dpx' % getattr(self.graph, name)))
+ class FontSizes(object):
+ """Container for font sizes"""
+ fs = FontSizes()
+ for name in dir(self.graph.state):
+ if name.endswith('_font_size'):
+ setattr(
+ fs,
+ name.replace('_font_size', ''),
+ ('%dpx' % getattr(self.graph, name)))
- with io.open(css, encoding='utf-8') as f:
- css_text = template(
- f.read(),
- style=self.graph.style,
- colors=colors,
- font_sizes=fs,
- id=self.id)
+ with io.open(css, encoding='utf-8') as f:
+ css_text = template(
+ f.read(),
+ style=self.graph.style,
+ colors=colors,
+ font_sizes=fs,
+ id=self.id)
+ else:
+ css_text = css.data
if not self.graph.pretty_print:
css_text = minify_css(css_text)
all_css.append(css_text)
diff --git a/setup.py b/setup.py
index 6aab2bd..5b0564c 100644
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,7 @@ setup(
"svg", "chart", "graph", "diagram", "plot", "histogram", "kiviat"],
tests_require=["pytest", "pyquery", "flask", "cairosvg"],
cmdclass={'test': PyTest},
- package_data={'pygal': ['css/*', 'graph/maps/*.svg']},
+ #package_data={'pygal': ['css/*', 'graph/maps/*.svg']},
extras_require={
'lxml': ['lxml'],
'png': ['cairosvg']