Skip to content

Commit

Permalink
Move gallery to tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed Dec 28, 2019
1 parent 04aa073 commit 0867471
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/sources/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
base = 'autobuild.py-done'
if not os.path.exists(os.path.join(os.path.dirname(base_dir), base)):
import autobuild
import gallery
from kivy.tools import gallery
gallery.write_all_rst_pages()

# There are two options for replacing |today|: either, you set today to some
Expand Down
2 changes: 1 addition & 1 deletion kivy/tests/test_doc_gallery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doc.gallery import *
from kivy.tools.gallery import *


def test_parse_docstring_info():
Expand Down
21 changes: 11 additions & 10 deletions doc/gallery.py → kivy/tools/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from os.path import sep
from os.path import join as slash # just like that name better
from os.path import dirname, abspath
import kivy
from kivy.logger import Logger
import textwrap

# from here to the kivy top
base_dir = dirname(dirname(abspath(__file__)))
base_dir = dirname(dirname(abspath(kivy.__file__)))
examples_dir = slash(base_dir, 'examples')
screenshots_dir = slash(base_dir, 'doc/sources/images/examples')
generation_dir = slash(base_dir, 'doc/sources/examples')
Expand All @@ -28,7 +29,7 @@

# Info is a dict built up from
# straight filename information, more from reading the docstring,
# and more from parsing the description text. Errors are often
# and more from parsing the description text. Errors are often
# shown by setting the key 'error' with the value being the error message.
#
# It doesn't quite meet the requirements for a class, but is a vocabulary
Expand All @@ -37,7 +38,7 @@
def iter_filename_info(dir_name):
"""
Yield info (dict) of each matching screenshot found walking the
directory dir_name. A matching screenshot uses double underscores to
directory dir_name. A matching screenshot uses double underscores to
separate fields, i.e. path__to__filename__py.png as the screenshot for
examples/path/to/filename.py.
Expand Down Expand Up @@ -66,7 +67,7 @@ def iter_filename_info(dir_name):

def parse_docstring_info(text):
''' parse docstring from text (normal string with '\n's) and return an info
dict. A docstring should the first triple quoted string, have a title
dict. A docstring should the first triple quoted string, have a title
followed by a line of equal signs, and then a description at
least one sentence long.
Expand All @@ -87,7 +88,7 @@ def parse_docstring_info(text):

def iter_docstring_info(dir_name):
''' Iterate over screenshots in directory, yield info from the file
name and initial parse of the docstring. Errors are logged, but
name and initial parse of the docstring. Errors are logged, but
files with errors are skipped.
'''
for file_info in iter_filename_info(dir_name):
Expand Down Expand Up @@ -116,12 +117,12 @@ def enhance_info_description(info, line_length=79):
info['files'] is the source filename and any filenames referenced by the
magic words in the description, e.g. 'the file xxx.py' or
'The image this.png'. These are as written in the description, do
'The image this.png'. These are as written in the description, do
not allow ../dir notation, and are relative to the source directory.
info['enhanced_description'] is the description, as an array of
paragraphs where each paragraph is an array of lines wrapped to width
line_length. This enhanced description include the rst links to
line_length. This enhanced description include the rst links to
the files of info['files'].
'''

Expand Down Expand Up @@ -223,7 +224,7 @@ def t(left='', right=''):
a("\n.. |link{num}| replace:: :doc:`{source}<gen__{dunder}>`")
a("\n.. |pic{num}| image:: ../images/examples/{dunder}.png"
"\n :width: 216pt"
"\n :align: middle"
"\n :align: " " middle"
"\n :target: gen__{dunder}.html")
a("\n.. |title{num}| replace:: **{title}**")

Expand Down Expand Up @@ -274,14 +275,14 @@ def a(s=''):
a('\n.. _`' + full_name.replace(sep, '_') + '`:')
# double separator if building on windows (sphinx skips backslash)
if '\\' in full_name:
full_name = full_name.replace(sep, sep*2)
full_name = full_name.replace(sep, sep * 2)

if ext in ['.png', '.jpg', '.jpeg']:
title = 'Image **' + full_name + '**'
a('\n' + title)
a('~' * len(title))
a('\n.. image:: ../../../examples/' + full_name)
a(' :align: center')
a(' :align: ' ' center')
else: # code
title = 'File **' + full_name + '**'
a('\n' + title)
Expand Down

0 comments on commit 0867471

Please sign in to comment.