sphinxcontrib-seqdiag-0.6.0/ 0000755 0001750 0001750 00000000000 12224001757 017236 5 ustar katsuwo katsuwo 0000000 0000000 sphinxcontrib-seqdiag-0.6.0/PKG-INFO 0000644 0001750 0001750 00000002553 12224001757 020340 0 ustar katsuwo katsuwo 0000000 0000000 Metadata-Version: 1.1
Name: sphinxcontrib-seqdiag
Version: 0.6.0
Summary: Sphinx "seqdiag" extension
Home-page: http://bitbucket.org/birkenfeld/sphinx-contrib
Author: Takeshi Komiya
Author-email: i.tkomiya@gmail.com
License: BSD
Download-URL: http://pypi.python.org/pypi/sphinxcontrib-seqdiag
Description:
This package contains the seqdiag Sphinx extension.
.. _Sphinx: http://sphinx.pocoo.org/
.. _seqdiag: http://blockdiag.com/en/seqdiag/
This extension enable you to insert sequence diagrams in your Sphinx document.
Following code is sample::
.. seqdiag::
diagram {
browser => webserver => database;
}
This module needs seqdiag_.
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Topic :: Documentation
Classifier: Topic :: Utilities
sphinxcontrib-seqdiag-0.6.0/setup.py 0000644 0001750 0001750 00000003131 12224001532 020735 0 ustar katsuwo katsuwo 0000000 0000000 # -*- coding: utf-8 -*-
from setuptools import setup, find_packages
long_desc = '''
This package contains the seqdiag Sphinx extension.
.. _Sphinx: http://sphinx.pocoo.org/
.. _seqdiag: http://blockdiag.com/en/seqdiag/
This extension enable you to insert sequence diagrams in your Sphinx document.
Following code is sample::
.. seqdiag::
diagram {
browser => webserver => database;
}
This module needs seqdiag_.
'''
requires = ['seqdiag>=0.9.0', 'Sphinx>=0.6', 'setuptools']
setup(
name='sphinxcontrib-seqdiag',
version='0.6.0',
url='http://bitbucket.org/birkenfeld/sphinx-contrib',
download_url='http://pypi.python.org/pypi/sphinxcontrib-seqdiag',
license='BSD',
author='Takeshi Komiya',
author_email='i.tkomiya@gmail.com',
description='Sphinx "seqdiag" extension',
long_description=long_desc,
zip_safe=False,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'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',
'Topic :: Documentation',
'Topic :: Utilities',
],
platforms='any',
packages=find_packages(),
include_package_data=True,
install_requires=requires,
namespace_packages=['sphinxcontrib'],
)
sphinxcontrib-seqdiag-0.6.0/setup.cfg 0000644 0001750 0001750 00000000141 12224001757 021053 0 ustar katsuwo katsuwo 0000000 0000000 [egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
[aliases]
release = egg_info -RDb ''
sphinxcontrib-seqdiag-0.6.0/sphinxcontrib/ 0000755 0001750 0001750 00000000000 12224001757 022130 5 ustar katsuwo katsuwo 0000000 0000000 sphinxcontrib-seqdiag-0.6.0/sphinxcontrib/__init__.py 0000644 0001750 0001750 00000000556 12223754402 024250 0 ustar katsuwo katsuwo 0000000 0000000 # -*- coding: utf-8 -*-
"""
sphinxcontrib
~~~~~~~~~~~~~
This package is a namespace package that contains all extensions
distributed in the ``sphinx-contrib`` distribution.
:copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
__import__('pkg_resources').declare_namespace(__name__)
sphinxcontrib-seqdiag-0.6.0/sphinxcontrib/seqdiag.py 0000644 0001750 0001750 00000022007 12223755012 024117 0 ustar katsuwo katsuwo 0000000 0000000 # -*- coding: utf-8 -*-
"""
seqdiag.sphinx_ext
~~~~~~~~~~~~~~~~~~~~
Allow seqdiag-formatted diagrams to be included in Sphinx-generated
documents inline.
:copyright: Copyright 2010 by Takeshi Komiya.
:license: BSDL.
"""
import io
import os
import posixpath
import traceback
from collections import namedtuple
try:
from hashlib import sha1 as sha
except ImportError:
from sha import sha
from docutils import nodes
from sphinx.errors import SphinxError
from sphinx.util.osutil import ensuredir
import seqdiag_sphinxhelper as seqdiag
class SeqdiagError(SphinxError):
category = 'Seqdiag error'
class Seqdiag(seqdiag.utils.rst.directives.SeqdiagDirective):
def run(self):
try:
return super(Seqdiag, self).run()
except seqdiag.core.parser.ParseException as e:
if self.content:
msg = '[%s] ParseError: %s\n%s' % (self.name, e, "\n".join(self.content))
else:
msg = '[%s] ParseError: %s\n%r' % (self.name, e, self.arguments[0])
reporter = self.state.document.reporter
return [reporter.warning(msg, line=self.lineno)]
def node2image(self, node, diagram):
return node
def get_image_filename(self, code, format, options, prefix='seqdiag'):
"""
Get path of output file.
"""
if format.upper() not in ('PNG', 'PDF', 'SVG'):
raise SeqdiagError('seqdiag error:\nunknown format: %s\n' % format)
if format.upper() == 'PDF':
try:
import reportlab
except ImportError:
msg = 'seqdiag error:\n' + \
'colud not output PDF format; Install reportlab\n'
raise SeqdiagError(msg)
hashkey = (code + str(options)).encode('utf-8')
fname = '%s-%s.%s' % (prefix, sha(hashkey).hexdigest(), format.lower())
if hasattr(self.builder, 'imgpath'):
# HTML
relfn = posixpath.join(self.builder.imgpath, fname)
outfn = os.path.join(self.builder.outdir, '_images', fname)
else:
# LaTeX
relfn = fname
outfn = os.path.join(self.builder.outdir, fname)
if os.path.isfile(outfn):
return relfn, outfn
ensuredir(os.path.dirname(outfn))
return relfn, outfn
def get_fontmap(self):
FontMap = seqdiag.utils.fontmap.FontMap
try:
fontmappath = self.builder.config.seqdiag_fontmap
fontmap = FontMap(fontmappath)
except:
attrname = '_seqdiag_fontmap_warned'
if not hasattr(self.builder, attrname):
msg = ('seqdiag cannot load "%s" as fontmap file, '
'check the seqdiag_fontmap setting' % fontmappath)
self.builder.warn(msg)
setattr(self.builder, attrname, True)
fontmap = FontMap(None)
try:
fontpath = self.builder.config.seqdiag_fontpath
if isinstance(fontpath, seqdiag.utils.compat.string_types):
fontpath = [fontpath]
if fontpath:
config = namedtuple('Config', 'font')(fontpath)
_fontpath = seqdiag.utils.bootstrap.detectfont(config)
fontmap.set_default_font(_fontpath)
except:
attrname = '_seqdiag_fontpath_warned'
if not hasattr(self.builder, attrname):
msg = ('seqdiag cannot load "%s" as truetype font, '
'check the seqdiag_fontpath setting' % fontpath)
self.builder.warn(msg)
setattr(self.builder, attrname, True)
return fontmap
def create_seqdiag(self, code, format, filename, options, prefix='seqdiag'):
"""
Render seqdiag code into a PNG output file.
"""
draw = None
fontmap = get_fontmap(self)
try:
tree = seqdiag.core.parser.parse_string(code)
diagram = seqdiag.core.builder.ScreenNodeBuilder.build(tree)
antialias = self.builder.config.seqdiag_antialias
draw = seqdiag.core.drawer.DiagramDraw(format, diagram, filename,
fontmap=fontmap, antialias=antialias)
except Exception as e:
if self.builder.config.seqdiag_debug:
traceback.print_exc()
raise SeqdiagError('seqdiag error:\n%s\n' % e)
return draw
def make_svgtag(self, image, relfn, trelfn, outfn,
alt, thumb_size, image_size):
svgtag_format = """"""
code = io.open(outfn, 'r', encoding='utf-8-sig').read()
return (svgtag_format %
(alt, image_size[0], image_size[1], code))
def make_imgtag(self, image, relfn, trelfn, outfn,
alt, thumb_size, image_size):
result = ""
imgtag_format = '\n'
if trelfn:
result += ('' % relfn)
result += (imgtag_format %
(trelfn, alt, thumb_size[0], thumb_size[1]))
result += ('')
else:
result += (imgtag_format %
(relfn, alt, image_size[0], image_size[1]))
return result
def render_dot_html(self, node, code, options, prefix='seqdiag',
imgcls=None, alt=None):
trelfn = None
thumb_size = None
try:
format = self.builder.config.seqdiag_html_image_format
relfn, outfn = get_image_filename(self, code, format, options, prefix)
image = create_seqdiag(self, code, format, outfn, options, prefix)
if not os.path.isfile(outfn):
image.draw()
image.save()
# generate thumbnails
image_size = image.pagesize()
if 'maxwidth' in options and options['maxwidth'] < image_size[0]:
thumb_prefix = prefix + '_thumb'
trelfn, toutfn = get_image_filename(self, code, format,
options, thumb_prefix)
ratio = float(options['maxwidth']) / image_size[0]
thumb_size = (options['maxwidth'], image_size[1] * ratio)
if not os.path.isfile(toutfn):
image.filename = toutfn
image.save(thumb_size)
except UnicodeEncodeError:
msg = ("seqdiag error: UnicodeEncodeError caught "
"(check your font settings)")
self.builder.warn(msg)
raise nodes.SkipNode
except SeqdiagError as exc:
self.builder.warn('dot code %r: ' % code + str(exc))
raise nodes.SkipNode
self.body.append(self.starttag(node, 'p', CLASS='seqdiag'))
if relfn is None:
self.body.append(self.encode(code))
else:
if alt is None:
alt = node.get('alt', self.encode(code).strip())
if format.upper() == 'SVG':
tagfunc = make_svgtag
else:
tagfunc = make_imgtag
self.body.append(tagfunc(self, image, relfn, trelfn, outfn, alt,
thumb_size, image_size))
self.body.append('