Skip to content

Commit

Permalink
Drop sphinx-1.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Dec 8, 2019
1 parent d1e2e6b commit 469bda8
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

.coverage
.tox/
.mypy_cache/
bin/
include/
lib/
34 changes: 16 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
language: python
python: 3.5
env:
matrix:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py33
- TOXENV=py32
- TOXENV=py34
- TOXENV=py35
- TOXENV=sphinx1.0
- TOXENV=sphinx1.1
- TOXENV=sphinx1.2
- TOXENV=blockdiag_dev
- TOXENV=coverage
cache:
directories:
- $HOME/.cache/pip
install: pip install docutils tox
dist: xenial
cache: pip
matrix:
include:
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.8
env: TOXENV=py38
- env: TOXENV=sphinx2.0
- env: TOXENV=blockdiag_dev
- env: TOXENV=coverage
install: pip install -U docutils tox
script: tox
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ restructuredtext = 1

[flake8]
max-line-length=120
ignore=_
ignore=W504
exclude=tests/docs/
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from setuptools import setup, find_packages


requires = ['blockdiag>=1.5.0', 'Sphinx>=0.6']
requires = ['blockdiag>=1.5.0', 'Sphinx>=2.0']

setup(
name='sphinxcontrib-blockdiag',
Expand All @@ -24,12 +23,12 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Documentation',
'Topic :: Documentation :: Sphinx',
'Topic :: Utilities',
Expand Down
29 changes: 11 additions & 18 deletions sphinxcontrib/blockdiag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import namedtuple
from docutils import nodes
from sphinx import addnodes
from sphinx.util import logging
from sphinx.util.osutil import ensuredir

import blockdiag.utils.rst.nodes
Expand All @@ -32,6 +33,8 @@
# fontconfig; it will be initialized on `builder-inited` event.
fontmap = None

logger = logging.getLogger(__name__)


class blockdiag_node(blockdiag.utils.rst.nodes.blockdiag):
def to_drawer(self, image_format, builder, **kwargs):
Expand All @@ -56,11 +59,7 @@ def get_relpath(self, image_format, builder):
fontmap=builder.config.blockdiag_fontmap,
format=image_format,
transparency=builder.config.blockdiag_transparency)
if hasattr(builder, 'imgpath'): # Sphinx (<= 1.2.x) or HTML writer
outputdir = builder.imgpath
else:
outputdir = ''
return posixpath.join(outputdir, self.get_path(**options))
return posixpath.join(builder.imgpath, self.get_path(**options))

def get_abspath(self, image_format, builder):
options = dict(antialias=builder.config.blockdiag_antialias,
Expand All @@ -69,13 +68,7 @@ def get_abspath(self, image_format, builder):
format=image_format,
transparency=builder.config.blockdiag_transparency)

if hasattr(builder, 'imagedir'): # Sphinx (>= 1.3.x)
outputdir = os.path.join(builder.outdir, builder.imagedir)
elif hasattr(builder, 'imgpath'): # Sphinx (<= 1.2.x) and HTML writer
outputdir = os.path.join(builder.outdir, '_images')
else:
outputdir = builder.outdir
path = os.path.join(outputdir, self.get_path(**options))
path = os.path.join(builder.outdir, builder.imagedir, self.get_path(**options))
ensuredir(os.path.dirname(path))

return path
Expand Down Expand Up @@ -110,7 +103,7 @@ def resolve_reference(builder, href):
else:
return xref['refuri']
else:
builder.warn('undefined label: %s' % refid)
logger.warning('undefined label: %s', refid)
return None


Expand Down Expand Up @@ -213,13 +206,13 @@ def html_visit_blockdiag(self, node):

msg = ("blockdiag error: UnicodeEncodeError caught "
"(check your font settings)")
self.builder.warn(msg)
logger.warning(msg)
raise nodes.SkipNode
except Exception as exc:
if self.builder.config.blockdiag_debug:
traceback.print_exc()

self.builder.warn('dot code %r: %s' % (node['code'], str(exc)))
logger.warning('dot code %r: %s', node['code'], exc)
raise nodes.SkipNode


Expand Down Expand Up @@ -254,7 +247,7 @@ def get_image_format_for(builder):
def on_builder_inited(self):
# show deprecated message
if self.builder.config.blockdiag_tex_image_format:
self.builder.warn('blockdiag_tex_image_format is deprecated. Use blockdiag_latex_image_format.')
logger.warning('blockdiag_tex_image_format is deprecated. Use blockdiag_latex_image_format.')

# initialize fontmap
global fontmap
Expand Down Expand Up @@ -288,7 +281,7 @@ def on_doctree_resolved(self, doctree, docname):
if self.builder.config.blockdiag_debug:
traceback.print_exc()

self.builder.warn('blockdiag error: %s' % exc)
logger.warning('blockdiag error: %s', exc)
for node in doctree.traverse(blockdiag_node):
node.parent.remove(node)

Expand All @@ -309,7 +302,7 @@ def on_doctree_resolved(self, doctree, docname):
if self.builder.config.blockdiag_debug:
traceback.print_exc()

self.builder.warn('dot code %r: %s' % (node['code'], str(exc)))
logger.warning('dot code %r: %s', node['code'], exc)
node.parent.remove(node)


Expand Down
5 changes: 1 addition & 4 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from blockdiag.utils.compat import u

import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import unittest


class TestSphinxcontribBlockdiagErrors(unittest.TestCase):
Expand Down
11 changes: 2 additions & 9 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

from sphinx_testing import with_app

import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import unittest


with_png_app = with_app(srcdir='tests/docs/basic',
Expand Down Expand Up @@ -373,10 +369,7 @@ def test_missing_reftarget_in_href_on_svg(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'index.html').read_text(encoding='utf-8')
if sys.version_info < (3, 0):
self.assertNotRegexpMatches(source, '<a xlink:href="#hello-world">\\n\\s*<rect .*?>\\n\\s*</a>')
else:
self.assertNotRegex(source, '<a xlink:href="#hello-world">\\n\\s*<rect .*?>\\n\\s*</a>')
self.assertNotRegex(source, '<a xlink:href="#hello-world">\\n\\s*<rect .*?>\\n\\s*</a>')
self.assertIn('undefined label: unknown_target', warning.getvalue())

@with_svg_app
Expand Down
54 changes: 31 additions & 23 deletions tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from sphinx_testing import with_app
from blockdiag.utils.compat import u

import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import unittest

CR = "\r?\n"

blockdiag_fontpath = '/usr/share/fonts/truetype/ipafont/ipagp.ttf'
with_png_app = with_app(srcdir='tests/docs/basic',
Expand Down Expand Up @@ -46,10 +44,9 @@ def test_build_png_image(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.png}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{blockdiag-.*?}.png}')

@unittest.skipUnless(os.path.exists(blockdiag_fontpath), "TrueType font not found")
@unittest.skipIf(sys.version_info[:2] == (3, 2), "reportlab does not support python 3.2")
@with_pdf_app
def test_build_pdf_image1(self, app, status, warning):
"""
Expand All @@ -59,10 +56,9 @@ def test_build_pdf_image1(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.pdf}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{blockdiag-.*?}.pdf}')

@unittest.skipUnless(os.path.exists(blockdiag_fontpath), "TrueType font not found")
@unittest.skipIf(sys.version_info[:2] == (3, 2), "reportlab does not support python 3.2")
@with_oldpdf_app
def test_build_pdf_image2(self, app, status, warning):
"""
Expand All @@ -72,7 +68,7 @@ def test_build_pdf_image2(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.pdf}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{blockdiag-.*?}.pdf}')

@with_png_app
def test_width_option(self, app, status, warning):
Expand All @@ -84,7 +80,7 @@ def test_width_option(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics\\[width=3cm\\]{blockdiag-.*?.png}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[width=3cm\]{{blockdiag-.*?}.png}')

@with_png_app
def test_height_option(self, app, status, warning):
Expand All @@ -96,7 +92,7 @@ def test_height_option(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics\\[height=4cm\\]{blockdiag-.*?.png}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[height=4cm\]{{blockdiag-.*?}.png}')

@with_png_app
def test_scale_option(self, app, status, warning):
Expand All @@ -108,7 +104,7 @@ def test_scale_option(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\scalebox{0.500000}{\\\\includegraphics{blockdiag-.*?.png}}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[scale=0.5\]{{blockdiag-.*?}.png}')

@with_png_app
def test_align_option_left(self, app, status, warning):
Expand All @@ -120,7 +116,9 @@ def test_align_option_left(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '{\\\\includegraphics{blockdiag-.*?.png}\\\\hfill}')
self.assertRegexpMatches(source,
(r'{\\sphinxincludegraphics{{blockdiag-.*?}.png}'
r'\\hspace\*{\\fill}}'))

@with_png_app
def test_align_option_center(self, app, status, warning):
Expand All @@ -132,7 +130,10 @@ def test_align_option_center(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{blockdiag-.*?.png}\\\\hfill}')
self.assertRegexpMatches(source,
(r'{\\hspace\*{\\fill}'
r'\\sphinxincludegraphics{{blockdiag-.*?}.png}'
r'\\hspace\*{\\fill}}'))

@with_png_app
def test_align_option_right(self, app, status, warning):
Expand All @@ -144,7 +145,9 @@ def test_align_option_right(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{blockdiag-.*?.png}}')
self.assertRegexpMatches(source,
(r'{\\hspace\*{\\fill}'
r'\\sphinxincludegraphics{{blockdiag-.*?}.png}}'))

@with_png_app
def test_caption_option(self, app, status, warning):
Expand All @@ -156,10 +159,13 @@ def test_caption_option(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.png}')

figure = re.compile('\\\\begin{figure}\\[htbp\\]\r?\n\\\\centering.*?'
'\\\\caption{hello world}\\\\end{figure}', re.DOTALL)
figure = re.compile((r'\\begin{figure}\[htbp\]' + CR +
r'\\centering' + CR +
r'\\capstart' + CR + CR +
r'\\noindent\\sphinxincludegraphics{{blockdiag-.*?}.png}' + CR +
r'\\caption{hello world}\\label{\\detokenize{index:id1}}\\end{figure}'),
re.DOTALL)
self.assertRegexpMatches(source, figure)

@with_png_app
Expand All @@ -173,10 +179,12 @@ def test_caption_option_and_align_option(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.png}')

figure = re.compile('\\\\begin{figure}\\[htbp\\]\\\\begin{flushleft}.*?'
'\\\\caption{hello world}\\\\end{flushleft}\\\\end{figure}', re.DOTALL)
figure = re.compile((r'\\begin{wrapfigure}{l}{0pt}' + CR +
r'\\centering' + CR +
r'\\noindent\\sphinxincludegraphics{{blockdiag-.*?}.png}' + CR +
r'\\caption{hello world}\\label{\\detokenize{index:id1}}\\end{wrapfigure}'),
re.DOTALL)
self.assertRegexpMatches(source, figure)

@with_png_app
Expand All @@ -189,4 +197,4 @@ def test_href(self, app, status, warning):
"""
app.builder.build_all()
source = (app.outdir / 'test.tex').read_text(encoding='utf-8')
self.assertRegexpMatches(source, '\\\\includegraphics{blockdiag-.*?.png}')
self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{blockdiag-.*?}.png}')

0 comments on commit 469bda8

Please sign in to comment.