Repository: sphinx-gallery/sphinx-gallery

Issue:
Cell marker causes pycodestyle error
I was wondering why [`#%%` is recommended](https://sphinx-gallery.github.io/stable/tutorials/plot_parse.html#sphx-glr-tutorials-plot-parse-py), because stickler-CI complains that it doesn't satisfy pycodestyle because there's no space after the comment marker. I hate to be pedantic (["... hobgoblin of little minds."](https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds)) but we depend on the CIs to review PRs so if there's an exception it's more challenging to review, sorry.

I'm really sorry if this issue is redundant. I looked through the existing issues searching for "cell" & "space" but couldn't find a relevant issue. I am just getting started with Sphinx gallery, and it's really awesome, thanks so much.

 Thanks!!!

Discussion:

Patch:
diff --git a/doc/advanced.rst b/doc/advanced.rst
index eb77abf..ee03a44 100644
--- a/doc/advanced.rst
+++ b/doc/advanced.rst
@@ -330,3 +330,13 @@ the ``reset_modules`` configuration key. For the function defined above::
           standard behavior that users will experience when manually running
           examples themselves is discouraged due to the inconsistency
           that results between the rendered examples and local outputs.
+
+Using (only) Sphinx-gallery styles
+==================================
+
+If you just want to make use of sphinx-gallery CSS files, instead of using
+the ``sphinx_gallery.gen_gallery`` extension, you can use in ``conf.py``::
+
+    extensions = ['sphinx_gallery.load_style']
+
+This will only cause the ``gallery.css`` file to be added to your build.
diff --git a/doc/syntax.rst b/doc/syntax.rst
index 57bb56b..ccef82c 100644
--- a/doc/syntax.rst
+++ b/doc/syntax.rst
@@ -43,9 +43,9 @@ be rendered in-line with the Python code and its outputs, similar to how
 Jupyter Notebooks are structured (in fact, Sphinx-Gallery also **creates** a
 Jupyter Notebook for each example that is built).
 
-You can embed rST in your Python examples by including a line of  >= 20 ``#``
-symbols or ``#%%``. For compatibility reasons, ``# %%`` (with a space) can also
-be used but ``#%%`` is recommended for consistency. If using ``#``'s, we
+You can embed rST in your Python examples by including a line of >= 20 ``#`` 
+symbols, ``#%%``, or ``# %%``. For consistency, it is recommended that you use
+only one of the above three options in your project. If using ``#``'s, we
 recommend using 79 ``#``'s, like this::
 
   ###############################################################################
diff --git a/sphinx_gallery/load_style.py b/sphinx_gallery/load_style.py
new file mode 100644
index 0000000..f68c935
--- /dev/null
+++ b/sphinx_gallery/load_style.py
@@ -0,0 +1,24 @@
+"""
+Only load CSS and modify html_static_path
+=========================================
+
+This should not be used at the same time as sphinx_gallery.gen_gallery.
+
+"""
+from . import __version__, glr_path_static
+
+
+def config_inited(app, config):
+    path = glr_path_static()
+    if path not in config.html_static_path:
+        config.html_static_path.append(path)
+    app.add_css_file('gallery.css')
+
+
+def setup(app):
+    app.require_sphinx('1.8')
+    app.connect('config-inited', config_inited)
+    return {
+        'parallel_read_safe': True,
+        'version': __version__,
+    }
diff --git a/tutorials/plot_parse.py b/tutorials/plot_parse.py
index 02f504e..36c6e2c 100644
--- a/tutorials/plot_parse.py
+++ b/tutorials/plot_parse.py
@@ -28,10 +28,10 @@ import matplotlib.pyplot as plt
 # text blocks only shows as a new lines between text, in the rendered output.
 
 #############################################
-# You can separate blocks using either a single line of ``#``'s (>=20 columns)
-# or ``#%%``. For compatibility reasons ``# %%`` (with a space) can also be used
-# but we recommend only using ``#%%`` for consistency. All future 
-# 'block splitters' used in the source ``.py`` document will be ``#%%``.
+# You can separate blocks using either a single line of ``#``'s (>=20 columns),
+# ``#%%``, or ``# %%``. For consistency, it is recommend that you use only one
+# of the above three options in your project. All future 'block splitters' used
+# in the sphinx-gallery source ``.py`` documents will be ``#%%``.
 
 def dummy():
     """This should not be part of a 'text' block'"""


Test patch:
diff --git a/sphinx_gallery/tests/conftest.py b/sphinx_gallery/tests/conftest.py
index 40e1d29..d290b6e 100644
--- a/sphinx_gallery/tests/conftest.py
+++ b/sphinx_gallery/tests/conftest.py
@@ -5,10 +5,16 @@ Pytest fixtures
 from __future__ import division, absolute_import, print_function
 
 import collections
+from contextlib import contextmanager
+from io import StringIO
+import os
+import shutil
 
 import pytest
 
 import sphinx
+from sphinx.application import Sphinx
+from sphinx.util.docutils import docutils_namespace
 from sphinx_gallery import (docs_resolv, gen_gallery, gen_rst, utils,
                             sphinx_compatibility, py_source_parser)
 from sphinx_gallery.scrapers import _import_matplotlib
@@ -152,3 +158,86 @@ def req_pil():
         _get_image()
     except RuntimeError:
         pytest.skip('Test requires pillow')
+
+
+@pytest.fixture
+def conf_file(request):
+    try:
+        env = request.node.get_closest_marker('conf_file')
+    except AttributeError:  # old pytest
+        env = request.node.get_marker('conf_file')
+    kwargs = env.kwargs if env else {}
+    result = {
+        'content': "",
+        'extensions': ['sphinx_gallery.gen_gallery'],
+    }
+    result.update(kwargs)
+
+    return result
+
+
+class SphinxAppWrapper(object):
+    """Wrapper for sphinx.application.Application.
+
+    This allows control over when the sphinx application is initialized, since
+    part of the sphinx-gallery build is done in
+    sphinx.application.Application.__init__ and the remainder is done in
+    sphinx.application.Application.build.
+
+    """
+
+    def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
+                 **kwargs):
+        self.srcdir = srcdir
+        self.confdir = confdir
+        self.outdir = outdir
+        self.doctreedir = doctreedir
+        self.buildername = buildername
+        self.kwargs = kwargs
+
+    def create_sphinx_app(self):
+        # Avoid warnings about re-registration, see:
+        # https://github.com/sphinx-doc/sphinx/issues/5038
+        with self.create_sphinx_app_context() as app:
+            pass
+        return app
+
+    @contextmanager
+    def create_sphinx_app_context(self):
+        with docutils_namespace():
+            app = Sphinx(self.srcdir, self.confdir, self.outdir,
+                         self.doctreedir, self.buildername, **self.kwargs)
+            sphinx_compatibility._app = app
+            yield app
+
+    def build_sphinx_app(self, *args, **kwargs):
+        with self.create_sphinx_app_context() as app:
+            # building should be done in the same docutils_namespace context
+            app.build(*args, **kwargs)
+        return app
+
+
+@pytest.fixture
+def sphinx_app_wrapper(tmpdir, conf_file, req_mpl, req_pil):
+    _fixturedir = os.path.join(os.path.dirname(__file__), 'testconfs')
+    srcdir = os.path.join(str(tmpdir), "config_test")
+    shutil.copytree(_fixturedir, srcdir)
+    shutil.copytree(os.path.join(_fixturedir, "src"),
+                    os.path.join(str(tmpdir), "examples"))
+
+    base_config = """
+import os
+import sphinx_gallery
+extensions = %r
+exclude_patterns = ['_build']
+source_suffix = '.rst'
+master_doc = 'index'
+# General information about the project.
+project = u'Sphinx-Gallery <Tests>'\n\n
+""" % (conf_file['extensions'],)
+    with open(os.path.join(srcdir, "conf.py"), "w") as conffile:
+        conffile.write(base_config + conf_file['content'])
+
+    return SphinxAppWrapper(
+        srcdir, srcdir, os.path.join(srcdir, "_build"),
+        os.path.join(srcdir, "_build", "toctree"), "html", warning=StringIO())
diff --git a/sphinx_gallery/tests/reference_parse.txt b/sphinx_gallery/tests/reference_parse.txt
index 378aa51..76c3b04 100644
--- a/sphinx_gallery/tests/reference_parse.txt
+++ b/sphinx_gallery/tests/reference_parse.txt
@@ -33,11 +33,12 @@
   26),
  ('text',
   "You can separate blocks using either a single line of ``#``'s (>=20 "
-  'columns)\n'
-  'or ``#%%``. For compatibility reasons ``# %%`` (with a space) can also be '
-  'used\n'
-  'but we recommend only using ``#%%`` for consistency. All future \n'
-  "'block splitters' used in the source ``.py`` document will be ``#%%``.\n",
+  'columns),\n'
+  '``#%%``, or ``# %%``. For consistency, it is recommend that you use '
+  'only one\n'
+  "of the above three options in your project. All future 'block "
+  "splitters' used\n"
+  "in the sphinx-gallery source ``.py`` documents will be ``#%%``.\n",
   31),
  ('code',
   '\n'
@@ -101,4 +102,4 @@
   '.. literalinclude:: plot_parse.py\n'
   '\n'
   '\n',
-  89)]
\ No newline at end of file
+  89)]
diff --git a/sphinx_gallery/tests/test_gen_gallery.py b/sphinx_gallery/tests/test_gen_gallery.py
index 43f7da6..c50d752 100644
--- a/sphinx_gallery/tests/test_gen_gallery.py
+++ b/sphinx_gallery/tests/test_gen_gallery.py
@@ -8,107 +8,18 @@ Test Sphinx-Gallery
 from __future__ import (division, absolute_import, print_function,
                         unicode_literals)
 import codecs
-from contextlib import contextmanager
-from io import StringIO
 import os
 import sys
 import re
-import shutil
 
 import pytest
 
-from sphinx.application import Sphinx
 from sphinx.errors import ExtensionError
-from sphinx.util.docutils import docutils_namespace
-
-from sphinx_gallery import sphinx_compatibility
 from sphinx_gallery.gen_gallery import (check_duplicate_filenames,
                                         collect_gallery_files,
                                         write_computation_times)
 
 
-@pytest.fixture
-def conf_file(request):
-    try:
-        env = request.node.get_closest_marker('conf_file')
-    except AttributeError:  # old pytest
-        env = request.node.get_marker('conf_file')
-    kwargs = env.kwargs if env else {}
-    result = {
-        'content': "",
-    }
-    result.update(kwargs)
-
-    return result
-
-
-class SphinxAppWrapper(object):
-    """Wrapper for sphinx.application.Application.
-
-    This allows to control when the sphinx application is initialized, since
-    part of the sphinx-gallery build is done in
-    sphinx.application.Application.__init__ and the remainder is done in
-    sphinx.application.Application.build.
-
-    """
-
-    def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
-                 **kwargs):
-        self.srcdir = srcdir
-        self.confdir = confdir
-        self.outdir = outdir
-        self.doctreedir = doctreedir
-        self.buildername = buildername
-        self.kwargs = kwargs
-
-    def create_sphinx_app(self):
-        # Avoid warnings about re-registration, see:
-        # https://github.com/sphinx-doc/sphinx/issues/5038
-        with self.create_sphinx_app_context() as app:
-            pass
-        return app
-
-    @contextmanager
-    def create_sphinx_app_context(self):
-        with docutils_namespace():
-            app = Sphinx(self.srcdir, self.confdir, self.outdir,
-                         self.doctreedir, self.buildername, **self.kwargs)
-            sphinx_compatibility._app = app
-            yield app
-
-    def build_sphinx_app(self, *args, **kwargs):
-        with self.create_sphinx_app_context() as app:
-            # building should be done in the same docutils_namespace context
-            app.build(*args, **kwargs)
-        return app
-
-
-@pytest.fixture
-def sphinx_app_wrapper(tmpdir, conf_file, req_mpl, req_pil):
-    _fixturedir = os.path.join(os.path.dirname(__file__), 'testconfs')
-    srcdir = os.path.join(str(tmpdir), "config_test")
-    shutil.copytree(_fixturedir, srcdir)
-    shutil.copytree(os.path.join(_fixturedir, "src"),
-                    os.path.join(str(tmpdir), "examples"))
-
-    base_config = """
-import os
-import sphinx_gallery
-extensions = ['sphinx_gallery.gen_gallery']
-exclude_patterns = ['_build']
-source_suffix = '.rst'
-master_doc = 'index'
-# General information about the project.
-project = u'Sphinx-Gallery <Tests>'\n\n
-"""
-    with open(os.path.join(srcdir, "conf.py"), "w") as conffile:
-        conffile.write(base_config + conf_file['content'])
-
-    return SphinxAppWrapper(
-        srcdir, srcdir, os.path.join(srcdir, "_build"),
-        os.path.join(srcdir, "_build", "toctree"), "html", warning=StringIO())
-
-
 def test_default_config(sphinx_app_wrapper):
     """Test the default Sphinx-Gallery configuration is loaded
 
diff --git a/sphinx_gallery/tests/test_load_style.py b/sphinx_gallery/tests/test_load_style.py
new file mode 100644
index 0000000..0826b29
--- /dev/null
+++ b/sphinx_gallery/tests/test_load_style.py
@@ -0,0 +1,18 @@
+import os
+import pytest
+
+
+@pytest.mark.conf_file(extensions=['sphinx_gallery.load_style'])
+def test_load_style(sphinx_app_wrapper):
+    """Testing that style loads properly."""
+    sphinx_app = sphinx_app_wrapper.build_sphinx_app()
+    cfg = sphinx_app.config
+    assert cfg.project == "Sphinx-Gallery <Tests>"
+    build_warn = sphinx_app._warning.getvalue()
+    assert build_warn == ''
+    index_html = os.path.join(
+        sphinx_app_wrapper.outdir, 'index.html')
+    assert os.path.isfile(index_html)
+    with open(index_html, 'r') as fid:
+        content = fid.read()
+    assert 'link rel="stylesheet" type="text/css" href="_static/gallery.css"' in content  # noqa: E501