Repository: altair-viz/altair
Pull request #756 (2018-04-13 15:46:56)

Rename alt.theme to alt.themes for consistency
Related to https://github.com/altair-viz/altair/pull/740#issuecomment-381158406


Patch:
diff --git a/altair/sphinxext/altairgallery.py b/altair/sphinxext/altairgallery.py
index dfb1bd98..0c0166b4 100644
--- a/altair/sphinxext/altairgallery.py
+++ b/altair/sphinxext/altairgallery.py
@@ -160,6 +160,7 @@ class AltairMiniGalleryDirective(Directive):
     has_content = False
 
     option_spec = {'size': int,
+                   'names': str,
                    'indices': lambda x: list(map(int, x.split())),
                    'shuffle': flag,
                    'seed': int,
@@ -168,6 +169,7 @@ class AltairMiniGalleryDirective(Directive):
 
     def run(self):
         size = self.options.get('size', 15)
+        names = [name.strip() for name in self.options.get('names', '').split(',')]
         indices = self.options.get('indices', [])
         shuffle = 'shuffle' in self.options
         seed = self.options.get('seed', 42)
@@ -181,13 +183,20 @@ class AltairMiniGalleryDirective(Directive):
 
         examples = populate_examples()
 
-        if indices:
-            examples = [examples[i] for i in indices]
-        if shuffle:
-            random.seed(seed)
-            random.shuffle(examples)
-        if size:
-            examples = examples[:size]
+        if names:
+            if len(names) < size:
+                raise ValueError("altair-minigallery: if names are specified, "
+                                 "the list must be at least as long as size.")
+            mapping = {example['name']: example for example in examples}
+            examples = [mapping[name] for name in names]
+        else:
+            if indices:
+                examples = [examples[i] for i in indices]
+            if shuffle:
+                random.seed(seed)
+                random.shuffle(examples)
+            if size:
+                examples = examples[:size]
 
         include = MINIGALLERY_TEMPLATE.render(image_dir='/_static',
                                               gallery_dir=gallery_dir,
diff --git a/altair/vegalite/v1/api.py b/altair/vegalite/v1/api.py
index 0119924d..cd05ddb0 100644
--- a/altair/vegalite/v1/api.py
+++ b/altair/vegalite/v1/api.py
@@ -14,7 +14,7 @@ from .schema import core, channels, Undefined, SCHEMA_URL
 from .data import data_transformers, pipe
 from ... import utils
 from .display import renderers, VEGALITE_VERSION, VEGA_VERSION, VEGAEMBED_VERSION
-from .theme import theme
+from .theme import themes
 
 
 def _get_channels_mapping():
@@ -89,7 +89,7 @@ class TopLevelMixin(object):
                 dct['$schema'] = SCHEMA_URL
 
             # apply theme from theme registry
-            dct = utils.update_nested(theme.get(), dct, copy=True)
+            dct = utils.update_nested(themes.get(), dct, copy=True)
         return dct
 
     def savechart(self, fp, format=None, **kwargs):
diff --git a/altair/vegalite/v1/theme.py b/altair/vegalite/v1/theme.py
index d78f373d..dfb126a9 100644
--- a/altair/vegalite/v1/theme.py
+++ b/altair/vegalite/v1/theme.py
@@ -10,8 +10,8 @@ ENTRY_POINT_GROUP = 'altair.vegalite.v1.theme'  # type: str
 class ThemeRegistry(PluginRegistry[dict]):
     pass
     
-theme = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP)
+themes = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP)
 
-theme.register('default', {"width": 400, "height": 300})
-theme.register('none', {})
-theme.enable('default')
+themes.register('default', {"width": 400, "height": 300})
+themes.register('none', {})
+themes.enable('default')
diff --git a/altair/vegalite/v2/api.py b/altair/vegalite/v2/api.py
index f99c78e7..fe1ac47d 100644
--- a/altair/vegalite/v2/api.py
+++ b/altair/vegalite/v2/api.py
@@ -9,7 +9,7 @@ from .schema import core, channels, mixins, Undefined, SCHEMA_URL
 from .data import data_transformers, pipe
 from ... import utils, expr
 from .display import renderers, VEGALITE_VERSION, VEGAEMBED_VERSION, VEGA_VERSION
-from .theme import theme
+from .theme import themes
 
 # ------------------------------------------------------------------------
 # Data Utilities
@@ -343,7 +343,7 @@ class TopLevelMixin(mixins.ConfigMethodMixin):
                 dct['$schema'] = SCHEMA_URL
 
             # apply theme from theme registry
-            dct = utils.update_nested(theme.get(), dct, copy=True)
+            dct = utils.update_nested(themes.get(), dct, copy=True)
 
         return dct
 
diff --git a/altair/vegalite/v2/theme.py b/altair/vegalite/v2/theme.py
index 0ebc6bfd..173a7a83 100644
--- a/altair/vegalite/v2/theme.py
+++ b/altair/vegalite/v2/theme.py
@@ -10,10 +10,10 @@ ENTRY_POINT_GROUP = 'altair.vegalite.v2.theme'  # type: str
 class ThemeRegistry(PluginRegistry[dict]):
     pass
 
-theme = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP)
+themes = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP)
 
-theme.register('default', {"config": {"view": {"width": 400, "height": 300}}})
-theme.register('opaque', {"config": {"background": "white",
-                                     "view": {"width": 400, "height": 300}}})
-theme.register('none', {})
-theme.enable('default')
+themes.register('default', {"config": {"view": {"width": 400, "height": 300}}})
+themes.register('opaque', {"config": {"background": "white",
+                                      "view": {"width": 400, "height": 300}}})
+themes.register('none', {})
+themes.enable('default')
diff --git a/doc/index.rst b/doc/index.rst
index 72293891..bfdc8b70 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -2,9 +2,8 @@ Altair: Declarative Visualization in Python
 ===========================================
 
 .. altair-minigallery::
+   :names: one_dot_per_zipcode, horizon_graph, world_projections, candlestick_chart, falkensee, scatter_linked_brush, layered_heatmap_text, natural_disasters, streamgraph, multiline_tooltip, select_detail, choropleth, interactive_cross_highlight, seattle_weather_interactive, london_tube
    :size: 15
-   :shuffle:
-   :seed: 31415
 
 Altair is a declarative statistical visualization library for Python, based on
 Vega_ and Vega-Lite_, and the source is available on
diff --git a/setup.py b/setup.py
index 67ee9a95..cae3d690 100644
--- a/setup.py
+++ b/setup.py
@@ -104,7 +104,6 @@ INSTALL_REQUIRES    = ['entrypoints',
                        'pytest',
                        'six',
                        'toolz',
-                       'typing',
                        'vega_datasets']
 VERSION             = version('altair/__init__.py')
 


Test patch:
diff --git a/altair/vegalite/tests/test_common.py b/altair/vegalite/tests/test_common.py
index 6b9949b9..36093121 100644
--- a/altair/vegalite/tests/test_common.py
+++ b/altair/vegalite/tests/test_common.py
@@ -62,10 +62,10 @@ def test_basic_chart_from_dict(alt, basic_spec):
 
 @pytest.mark.parametrize('alt', [v1, v2])
 def test_theme_enable(alt):
-    active_theme = alt.theme.active
+    active_theme = alt.themes.active
 
     try:
-        alt.theme.enable('none')
+        alt.themes.enable('none')
 
         chart = alt.Chart.from_dict(basic_spec)
         dct = chart.to_dict()
@@ -78,4 +78,4 @@ def test_theme_enable(alt):
         assert dct == basic_spec
     finally:
         # reset the theme to its initial value
-        alt.theme.enable(active_theme)
+        alt.themes.enable(active_theme)
diff --git a/altair/vegalite/v2/examples/mutli_series_line.py b/altair/vegalite/v2/examples/multi_series_line.py
similarity index 100%
rename from altair/vegalite/v2/examples/mutli_series_line.py
rename to altair/vegalite/v2/examples/multi_series_line.py
diff --git a/altair/vegalite/v2/tests/test_api.py b/altair/vegalite/v2/tests/test_api.py
index addb93e6..d42f5b7d 100644
--- a/altair/vegalite/v2/tests/test_api.py
+++ b/altair/vegalite/v2/tests/test_api.py
@@ -303,19 +303,19 @@ def test_LookupData():
 
 def test_themes():
     chart = alt.Chart('foo.txt').mark_point()
-    active = alt.theme.active
+    active = alt.themes.active
 
     try:
-        alt.theme.enable('default')
+        alt.themes.enable('default')
         assert chart.to_dict()['config'] == {"view": {"width": 400, "height": 300}}
 
-        alt.theme.enable('opaque')
+        alt.themes.enable('opaque')
         assert chart.to_dict()['config'] == {"background": "white",
                                              "view": {"width": 400, "height": 300}}
 
-        alt.theme.enable('none')
+        alt.themes.enable('none')
         assert 'config' not in chart.to_dict()
 
     finally:
         # re-enable the original active theme
-        alt.theme.enable(active)
+        alt.themes.enable(active)