[blockdiag] 06/29: Import Upstream version 1.1.5
Andreas Tille
tille at debian.org
Tue Jan 10 21:35:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository blockdiag.
commit e5b151a154a40da457bea8f3b60e9eb53395aa88
Author: Andreas Tille <tille at debian.org>
Date: Tue Jan 10 11:08:02 2017 +0100
Import Upstream version 1.1.5
---
PKG-INFO | 7 +-
bootstrap.py | 108 +++++++++++----
src/README.txt | 5 +
src/blockdiag.egg-info/PKG-INFO | 7 +-
src/blockdiag/__init__.py | 2 +-
src/blockdiag/drawer.py | 3 +-
src/blockdiag/elements.py | 2 +-
src/blockdiag/imagedraw/simplesvg.py | 5 +
src/blockdiag/imagedraw/svg.py | 1 +
src/blockdiag/metrics.py | 4 +-
src/blockdiag/tests/test_boot_params.py | 19 ++-
src/blockdiag/tests/test_generate_diagram.py | 38 ++++++
src/blockdiag/tests/test_rst_directives.py | 197 ++++++++++++++++-----------
src/blockdiag/utils/bootstrap.py | 37 +++--
src/blockdiag/utils/rst/directives.py | 9 +-
15 files changed, 312 insertions(+), 132 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 6575733..ef8bcd9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: blockdiag
-Version: 1.1.4
+Version: 1.1.5
Summary: blockdiag generate block-diagram image file from spec-text file.
Home-page: http://blockdiag.com/
Author: Takeshi Komiya
@@ -121,6 +121,11 @@ Description: `blockdiag` generate block-diagram image file from spec-text file.
History
=======
+ 1.1.5 (2012-04-22)
+ ------------------
+ * Embed source code to SVG document as description
+ * Fix bugs
+
1.1.4 (2012-03-15)
------------------
* Add new edge.hstyles: oneone, onemany, manyone, manymany
diff --git a/bootstrap.py b/bootstrap.py
index 49c5f50..7647cbb 100644
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -18,23 +18,35 @@ The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
"""
-import os, shutil, sys, tempfile, textwrap, urllib, urllib2
+import os, shutil, sys, tempfile, urllib, urllib2, subprocess
from optparse import OptionParser
if sys.platform == 'win32':
def quote(c):
if ' ' in c:
- return '"%s"' % c # work around spawn lamosity on windows
+ return '"%s"' % c # work around spawn lamosity on windows
else:
return c
else:
quote = str
+# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
+stdout, stderr = subprocess.Popen(
+ [sys.executable, '-Sc',
+ 'try:\n'
+ ' import ConfigParser\n'
+ 'except ImportError:\n'
+ ' print 1\n'
+ 'else:\n'
+ ' print 0\n'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+has_broken_dash_S = bool(int(stdout.strip()))
+
# In order to be more robust in the face of system Pythons, we want to
# run without site-packages loaded. This is somewhat tricky, in
# particular because Python 2.6's distutils imports site, so starting
# with the -S flag is not sufficient. However, we'll start with that:
-if 'site' in sys.modules:
+if not has_broken_dash_S and 'site' in sys.modules:
# We will restart with python -S.
args = sys.argv[:]
args[0:0] = [sys.executable, '-S']
@@ -45,12 +57,13 @@ if 'site' in sys.modules:
# out any namespace packages from site-packages that might have been
# loaded by .pth files.
clean_path = sys.path[:]
-import site
+import site # imported because of its side effects
sys.path[:] = clean_path
for k, v in sys.modules.items():
- if (hasattr(v, '__path__') and
- len(v.__path__)==1 and
- not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
+ if k in ('setuptools', 'pkg_resources') or (
+ hasattr(v, '__path__') and
+ len(v.__path__) == 1 and
+ not os.path.exists(os.path.join(v.__path__[0], '__init__.py'))):
# This is a namespace package. Remove it.
sys.modules.pop(k)
@@ -59,10 +72,11 @@ is_jython = sys.platform.startswith('java')
setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
distribute_source = 'http://python-distribute.org/distribute_setup.py'
+
# parsing arguments
def normalize_to_url(option, opt_str, value, parser):
if value:
- if '://' not in value: # It doesn't smell like a URL.
+ if '://' not in value: # It doesn't smell like a URL.
value = 'file://%s' % (
urllib.pathname2url(
os.path.abspath(os.path.expanduser(value))),)
@@ -97,7 +111,7 @@ parser.add_option("--setup-source", action="callback", dest="setup_source",
help=("Specify a URL or file location for the setup file. "
"If you use Setuptools, this will default to " +
setuptools_source + "; if you use Distribute, this "
- "will default to " + distribute_source +"."))
+ "will default to " + distribute_source + "."))
parser.add_option("--download-base", action="callback", dest="download_base",
callback=normalize_to_url, nargs=1, type="string",
help=("Specify a URL or directory for downloading "
@@ -107,6 +121,15 @@ parser.add_option("--eggs",
help=("Specify a directory for storing eggs. Defaults to "
"a temporary directory that is deleted when the "
"bootstrap script completes."))
+parser.add_option("-t", "--accept-buildout-test-releases",
+ dest='accept_buildout_test_releases',
+ action="store_true", default=False,
+ help=("Normally, if you do not specify a --version, the "
+ "bootstrap script and buildout gets the newest "
+ "*final* versions of zc.buildout and its recipes and "
+ "extensions for you. If you use this flag, "
+ "bootstrap and buildout will get the newest releases "
+ "even if they are alphas or betas."))
parser.add_option("-c", None, action="store", dest="config_file",
help=("Specify the path to the buildout configuration "
"file to be used."))
@@ -128,12 +151,13 @@ if options.setup_source is None:
else:
options.setup_source = setuptools_source
-args = args + ['bootstrap']
-
+if options.accept_buildout_test_releases:
+ args.append('buildout:accept-buildout-test-releases=true')
+args.append('bootstrap')
try:
import pkg_resources
- import setuptools # A flag. Sometimes pkg_resources is installed alone.
+ import setuptools # A flag. Sometimes pkg_resources is installed alone.
if not hasattr(pkg_resources, '_distribute'):
raise ImportError
except ImportError:
@@ -147,7 +171,8 @@ except ImportError:
if options.use_distribute:
setup_args['no_fake'] = True
ez['use_setuptools'](**setup_args)
- reload(sys.modules['pkg_resources'])
+ if 'pkg_resources' in sys.modules:
+ reload(sys.modules['pkg_resources'])
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
@@ -161,28 +186,65 @@ cmd = [quote(sys.executable),
'-mqNxd',
quote(eggs_dir)]
-if options.download_base:
- cmd.extend(['-f', quote(options.download_base)])
+if not has_broken_dash_S:
+ cmd.insert(1, '-S')
-requirement = 'zc.buildout'
-if options.version:
- requirement = '=='.join((requirement, options.version))
-cmd.append(requirement)
+find_links = options.download_base
+if not find_links:
+ find_links = os.environ.get('bootstrap-testing-find-links')
+if find_links:
+ cmd.extend(['-f', quote(find_links)])
if options.use_distribute:
setup_requirement = 'distribute'
else:
setup_requirement = 'setuptools'
ws = pkg_resources.working_set
+setup_requirement_path = ws.find(
+ pkg_resources.Requirement.parse(setup_requirement)).location
env = dict(
os.environ,
- PYTHONPATH=ws.find(
- pkg_resources.Requirement.parse(setup_requirement)).location)
+ PYTHONPATH=setup_requirement_path)
+
+requirement = 'zc.buildout'
+version = options.version
+if version is None and not options.accept_buildout_test_releases:
+ # Figure out the most recent final version of zc.buildout.
+ import setuptools.package_index
+ _final_parts = '*final-', '*final'
+
+ def _final_version(parsed_version):
+ for part in parsed_version:
+ if (part[:1] == '*') and (part not in _final_parts):
+ return False
+ return True
+ index = setuptools.package_index.PackageIndex(
+ search_path=[setup_requirement_path])
+ if find_links:
+ index.add_find_links((find_links,))
+ req = pkg_resources.Requirement.parse(requirement)
+ if index.obtain(req) is not None:
+ best = []
+ bestv = None
+ for dist in index[req.project_name]:
+ distv = dist.parsed_version
+ if _final_version(distv):
+ if bestv is None or distv > bestv:
+ best = [dist]
+ bestv = distv
+ elif distv == bestv:
+ best.append(dist)
+ if best:
+ best.sort()
+ version = best[-1].version
+if version:
+ requirement = '=='.join((requirement, version))
+cmd.append(requirement)
if is_jython:
import subprocess
exitcode = subprocess.Popen(cmd, env=env).wait()
-else: # Windows prefers this, apparently; otherwise we would prefer subprocess
+else: # Windows prefers this, apparently; otherwise we would prefer subprocess
exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
if exitcode != 0:
sys.stdout.flush()
@@ -196,5 +258,5 @@ ws.add_entry(eggs_dir)
ws.require(requirement)
import zc.buildout.buildout
zc.buildout.buildout.main(args)
-if not options.eggs: # clean up temporary egg directory
+if not options.eggs: # clean up temporary egg directory
shutil.rmtree(eggs_dir)
diff --git a/src/README.txt b/src/README.txt
index cf3744b..3bffb00 100644
--- a/src/README.txt
+++ b/src/README.txt
@@ -113,6 +113,11 @@ Apache License 2.0
History
=======
+1.1.5 (2012-04-22)
+------------------
+* Embed source code to SVG document as description
+* Fix bugs
+
1.1.4 (2012-03-15)
------------------
* Add new edge.hstyles: oneone, onemany, manyone, manymany
diff --git a/src/blockdiag.egg-info/PKG-INFO b/src/blockdiag.egg-info/PKG-INFO
index 6575733..ef8bcd9 100644
--- a/src/blockdiag.egg-info/PKG-INFO
+++ b/src/blockdiag.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: blockdiag
-Version: 1.1.4
+Version: 1.1.5
Summary: blockdiag generate block-diagram image file from spec-text file.
Home-page: http://blockdiag.com/
Author: Takeshi Komiya
@@ -121,6 +121,11 @@ Description: `blockdiag` generate block-diagram image file from spec-text file.
History
=======
+ 1.1.5 (2012-04-22)
+ ------------------
+ * Embed source code to SVG document as description
+ * Fix bugs
+
1.1.4 (2012-03-15)
------------------
* Add new edge.hstyles: oneone, onemany, manyone, manymany
diff --git a/src/blockdiag/__init__.py b/src/blockdiag/__init__.py
index c070b78..3a85051 100644
--- a/src/blockdiag/__init__.py
+++ b/src/blockdiag/__init__.py
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-__version__ = '1.1.4'
+__version__ = '1.1.5'
diff --git a/src/blockdiag/drawer.py b/src/blockdiag/drawer.py
index 5c3b6bd..69e12de 100644
--- a/src/blockdiag/drawer.py
+++ b/src/blockdiag/drawer.py
@@ -48,7 +48,8 @@ class DiagramDraw(object):
else:
self.shadow = kwargs.get('shadow', (0, 0, 0))
- kwargs = dict(nodoctype=kwargs.get('nodoctype'),
+ kwargs = dict(code=kwargs.get('code'),
+ nodoctype=kwargs.get('nodoctype'),
scale_ratio=self.scale_ratio,
transparency=kwargs.get('transparency'))
drawer = imagedraw.create(self.format, self.filename,
diff --git a/src/blockdiag/elements.py b/src/blockdiag/elements.py
index c0a0982..22c424e 100644
--- a/src/blockdiag/elements.py
+++ b/src/blockdiag/elements.py
@@ -246,7 +246,7 @@ class DiagramNode(Element):
if value is None:
attrs.append(u"")
else:
- attrs.append(getattr(self, name))
+ attrs.append(value)
return attrs
diff --git a/src/blockdiag/imagedraw/simplesvg.py b/src/blockdiag/imagedraw/simplesvg.py
index ade3943..6a2e48c 100644
--- a/src/blockdiag/imagedraw/simplesvg.py
+++ b/src/blockdiag/imagedraw/simplesvg.py
@@ -109,6 +109,11 @@ class title(base):
super(title, self).__init__(text=_title)
+class desc(base):
+ def __init__(self, _title):
+ super(desc, self).__init__(text=_title)
+
+
class text(element):
def __init__(self, x, y, _text, **kwargs):
super(text, self).__init__(x, y, text=_text, **kwargs)
diff --git a/src/blockdiag/imagedraw/svg.py b/src/blockdiag/imagedraw/svg.py
index 122dea3..d5038ce 100644
--- a/src/blockdiag/imagedraw/svg.py
+++ b/src/blockdiag/imagedraw/svg.py
@@ -273,6 +273,7 @@ class SVGImageDraw(SVGImageDrawElement):
self.svg.addElement(d)
self.svg.addElement(title('blockdiag'))
+ self.svg.addElement(desc(kwargs.get('code')))
def save(self, filename, size, format):
# Ignore format parameter; compatibility for ImageDrawEx.
diff --git a/src/blockdiag/metrics.py b/src/blockdiag/metrics.py
index 7563cc7..0d36920 100644
--- a/src/blockdiag/metrics.py
+++ b/src/blockdiag/metrics.py
@@ -126,7 +126,6 @@ class DiagramMetrics(object):
node_padding = 4
line_spacing = 2
shadow_offset = XY(3, 6)
- font = None
page_margin = XY(0, 0)
page_padding = [0, 0, 0, 0]
node_width = cellsize * 16
@@ -193,7 +192,7 @@ class DiagramMetrics(object):
def textsize(self, string, width=65535, font=None):
try:
- if self.font is None:
+ if font is None:
from utils.TextFolder import TextFolder
elif self.format == 'PDF':
from utils.PDFTextFolder import PDFTextFolder as TextFolder
@@ -202,7 +201,6 @@ class DiagramMetrics(object):
except ImportError:
from utils.TextFolder import TextFolder
- font = font or self.font
lines = TextFolder((0, 0, width, 65535), string, font)
textbox = lines.outlinebox
return XY(textbox.width, textbox.height + self.line_spacing)
diff --git a/src/blockdiag/tests/test_boot_params.py b/src/blockdiag/tests/test_boot_params.py
index a4b1053..0b92330 100644
--- a/src/blockdiag/tests/test_boot_params.py
+++ b/src/blockdiag/tests/test_boot_params.py
@@ -17,19 +17,28 @@ class TestBootParams(unittest2.TestCase):
@argv_wrapper
def test_type_option(self):
sys.argv = ['', '-Tsvg', 'input.diag']
- self.parser.parse()
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.svg')
sys.argv = ['', '-TSVG', 'input.diag']
- self.parser.parse()
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.svg')
sys.argv = ['', '-TSvg', 'input.diag']
- self.parser.parse()
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.svg')
+
+ sys.argv = ['', '-TSvg', 'input.test.diag']
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.test.svg')
sys.argv = ['', '-Tpng', 'input.diag']
- self.parser.parse()
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.png')
sys.argv = ['', '-Tpdf', 'input.diag']
- self.parser.parse()
+ options = self.parser.parse()
+ self.assertEqual(options.output, 'input.pdf')
@assertRaises(RuntimeError)
@argv_wrapper
diff --git a/src/blockdiag/tests/test_generate_diagram.py b/src/blockdiag/tests/test_generate_diagram.py
index 6824f56..fe3c2a4 100644
--- a/src/blockdiag/tests/test_generate_diagram.py
+++ b/src/blockdiag/tests/test_generate_diagram.py
@@ -105,3 +105,41 @@ def not_exist_font_config_option_test():
sys.argv = ['', '-f', '/font_is_not_exist', '-f', fontpath, 'input.diag']
options = blockdiag.command.BlockdiagOptions(blockdiag).parse()
blockdiag.command.detectfont(options)
+
+
+ at argv_wrapper
+ at stderr_wrapper
+def svg_includes_source_code_tag_test():
+ from xml.etree import ElementTree
+
+ testdir = os.path.dirname(__file__)
+ diagpath = "%s/diagrams/single_edge.diag" % testdir
+ fontpath = get_fontpath()
+
+ try:
+ tmpdir = tempfile.mkdtemp()
+ tmpfile = tempfile.mkstemp(dir=tmpdir)
+ os.close(tmpfile[0])
+
+ sys.argv = ['blockdiag.py', '-T', 'SVG', '-o', tmpfile[1], diagpath]
+ if os.path.exists(fontpath):
+ sys.argv += ['-f', fontpath]
+
+ blockdiag.command.main()
+
+ if re.search('ERROR', sys.stderr.getvalue()):
+ raise RuntimeError(sys.stderr.getvalue())
+
+ # compare embeded source code
+ source_code = open(diagpath).read()
+ tree = ElementTree.parse(tmpfile[1])
+ desc = tree.find('{http://www.w3.org/2000/svg}desc')
+
+ # strip spaces
+ source_code = re.sub('\s+', ' ', source_code)
+ embeded = re.sub('\s+', ' ', desc.text)
+ assert source_code == embeded
+ finally:
+ for file in os.listdir(tmpdir):
+ os.unlink(tmpdir + "/" + file)
+ os.rmdir(tmpdir)
diff --git a/src/blockdiag/tests/test_rst_directives.py b/src/blockdiag/tests/test_rst_directives.py
index dcdb205..1d255ed 100644
--- a/src/blockdiag/tests/test_rst_directives.py
+++ b/src/blockdiag/tests/test_rst_directives.py
@@ -41,7 +41,7 @@ class TestRstDirectives(unittest2.TestCase):
if 'blockdiag' in docutils._directives:
del docutils._directives['blockdiag']
- def test_rst_directives_setup(self):
+ def test_setup(self):
directives.setup()
self.assertIn('blockdiag', docutils._directives)
@@ -51,7 +51,7 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(False, directives.antialias)
self.assertEqual(None, directives.fontpath)
- def test_rst_directives_setup_with_args(self):
+ def test_setup_with_args(self):
directives.setup(format='SVG', antialias=True, fontpath='/dev/null')
self.assertIn('blockdiag', docutils._directives)
@@ -63,14 +63,14 @@ class TestRstDirectives(unittest2.TestCase):
@stderr_wrapper
@setup_directive_base
- def test_rst_directives_base_noargs(self):
+ def test_base_noargs(self):
text = ".. blockdiag::"
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.system_message, type(doctree[0]))
@setup_directive_base
- def test_rst_directives_base_with_block(self):
+ def test_base_with_block(self):
text = ".. blockdiag::\n\n { A -> B }"
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
@@ -81,14 +81,14 @@ class TestRstDirectives(unittest2.TestCase):
@stderr_wrapper
@setup_directive_base
- def test_rst_directives_base_with_emptyblock(self):
+ def test_base_with_emptyblock(self):
text = ".. blockdiag::\n\n \n"
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.system_message, type(doctree[0]))
@setup_directive_base
- def test_rst_directives_base_with_filename(self):
+ def test_base_with_filename(self):
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, 'diagrams/node_attribute.diag')
text = ".. blockdiag:: %s" % filename
@@ -102,21 +102,21 @@ class TestRstDirectives(unittest2.TestCase):
@stderr_wrapper
@setup_directive_base
- def test_rst_directives_base_with_filename_not_exists(self):
+ def test_base_with_filename_not_exists(self):
text = ".. blockdiag:: unknown.diag"
doctree = publish_doctree(text)
self.assertEqual(nodes.system_message, type(doctree[0]))
@stderr_wrapper
@setup_directive_base
- def test_rst_directives_base_with_block_and_filename(self):
+ def test_base_with_block_and_filename(self):
text = ".. blockdiag:: unknown.diag\n\n { A -> B }"
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.system_message, type(doctree[0]))
@setup_directive_base
- def test_rst_directives_base_with_options(self):
+ def test_base_with_options(self):
text = ".. blockdiag::\n :alt: hello world\n :desctable:\n" + \
" :maxwidth: 100\n\n { A -> B }"
doctree = publish_doctree(text)
@@ -128,7 +128,7 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(100, doctree[0]['options']['maxwidth'])
@use_tmpdir
- def test_rst_directives_with_block(self, path):
+ def test_block(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n\n { A -> B }"
doctree = publish_doctree(text)
@@ -139,7 +139,7 @@ class TestRstDirectives(unittest2.TestCase):
self.assertFalse('target' in doctree[0])
@use_tmpdir
- def test_rst_directives_with_block_alt(self, path):
+ def test_block_alt(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :alt: hello world\n\n { A -> B }"
doctree = publish_doctree(text)
@@ -151,7 +151,7 @@ class TestRstDirectives(unittest2.TestCase):
@use_tmpdir
@assertRaises(RuntimeError)
- def test_rst_directives_with_block_fontpath1(self, path):
+ def test_block_fontpath1(self, path):
directives.setup(format='SVG', fontpath=['dummy.ttf'],
outputdir=path)
text = ".. blockdiag::\n :alt: hello world\n\n { A -> B }"
@@ -159,14 +159,14 @@ class TestRstDirectives(unittest2.TestCase):
@use_tmpdir
@assertRaises(RuntimeError)
- def test_rst_directives_with_block_fontpath2(self, path):
+ def test_block_fontpath2(self, path):
directives.setup(format='SVG', fontpath='dummy.ttf',
outputdir=path)
text = ".. blockdiag::\n :alt: hello world\n\n { A -> B }"
doctree = publish_doctree(text)
@use_tmpdir
- def test_rst_directives_with_block_maxwidth(self, path):
+ def test_block_maxwidth(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :maxwidth: 100\n\n { A -> B }"
doctree = publish_doctree(text)
@@ -177,17 +177,23 @@ class TestRstDirectives(unittest2.TestCase):
self.assertFalse(0, doctree[0]['target'].index(path))
@use_tmpdir
- def test_rst_directives_with_block_desctable(self, path):
+ def test_desctable_without_description(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :desctable:\n\n { A -> B }"
doctree = publish_doctree(text)
+ self.assertEqual(1, len(doctree))
+ self.assertEqual(nodes.image, type(doctree[0]))
+
+ @use_tmpdir
+ def test_desctable(self, path):
+ directives.setup(format='SVG', outputdir=path)
+ text = ".. blockdiag::\n :desctable:\n\n" + \
+ " { A [description = foo]; B [description = bar]; }"
+ doctree = publish_doctree(text)
self.assertEqual(2, len(doctree))
self.assertEqual(nodes.image, type(doctree[0]))
self.assertEqual(nodes.table, type(doctree[1]))
- self.assertEqual(1, len(doctree[1]))
- self.assertEqual(nodes.tgroup, type(doctree[1][0]))
-
# tgroup
self.assertEqual(4, len(doctree[1][0]))
self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
@@ -196,45 +202,30 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(nodes.tbody, type(doctree[1][0][3]))
# colspec
- self.assertEqual(0, len(doctree[1][0][0]))
self.assertEqual(50, doctree[1][0][0]['colwidth'])
-
- self.assertEqual(0, len(doctree[1][0][1]))
self.assertEqual(50, doctree[1][0][1]['colwidth'])
# thead
thead = doctree[1][0][2]
- self.assertEqual(1, len(thead))
self.assertEqual(2, len(thead[0]))
-
- self.assertEqual(1, len(thead[0][0]))
- self.assertEqual(1, len(thead[0][0][0]))
self.assertEqual('Name', thead[0][0][0][0])
-
- self.assertEqual(1, len(thead[0][1]))
- self.assertEqual(1, len(thead[0][1][0]))
self.assertEqual('Description', thead[0][1][0][0])
# tbody
tbody = doctree[1][0][3]
self.assertEqual(2, len(tbody))
-
- self.assertEqual(2, len(tbody[0]))
- self.assertEqual(1, len(tbody[0][0]))
- self.assertEqual(1, len(tbody[0][0][0]))
self.assertEqual('A', tbody[0][0][0][0])
- self.assertEqual(0, len(tbody[0][1]))
-
- self.assertEqual(2, len(tbody[1]))
- self.assertEqual(1, len(tbody[1][0]))
- self.assertEqual(1, len(tbody[1][0][0]))
+ self.assertEqual('foo', tbody[0][1][0][0])
self.assertEqual('B', tbody[1][0][0][0])
- self.assertEqual(0, len(tbody[1][1]))
+ self.assertEqual('bar', tbody[1][1][0][0])
@use_tmpdir
- def test_rst_directives_with_block_desctable_using_node_group(self, path):
+ def test_desctable_using_node_group(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :desctable:\n\n { A -> B; group { A } }"
+ text = ".. blockdiag::\n :desctable:\n\n" + \
+ " { A [description = foo]; B [description = bar]; " + \
+ " group { A } }"
doctree = publish_doctree(text)
self.assertEqual(2, len(doctree))
self.assertEqual(nodes.image, type(doctree[0]))
@@ -278,51 +269,18 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(1, len(tbody[0][0]))
self.assertEqual(1, len(tbody[0][0][0]))
self.assertEqual('A', tbody[0][0][0][0])
- self.assertEqual(0, len(tbody[0][1]))
+ self.assertEqual(1, len(tbody[0][1]))
+ self.assertEqual('foo', tbody[0][1][0][0])
self.assertEqual(2, len(tbody[1]))
self.assertEqual(1, len(tbody[1][0]))
self.assertEqual(1, len(tbody[1][0][0]))
self.assertEqual('B', tbody[1][0][0][0])
- self.assertEqual(0, len(tbody[1][1]))
-
- @use_tmpdir
- def test_rst_directives_with_block_desctable_with_description(self, path):
- directives.setup(format='SVG', outputdir=path)
- text = ".. blockdiag::\n :desctable:\n\n" + \
- " { A [description = foo]; B [description = bar]; }"
- doctree = publish_doctree(text)
- self.assertEqual(2, len(doctree))
- self.assertEqual(nodes.image, type(doctree[0]))
- self.assertEqual(nodes.table, type(doctree[1]))
-
- # tgroup
- self.assertEqual(4, len(doctree[1][0]))
- self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
- self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
- self.assertEqual(nodes.thead, type(doctree[1][0][2]))
- self.assertEqual(nodes.tbody, type(doctree[1][0][3]))
-
- # colspec
- self.assertEqual(50, doctree[1][0][0]['colwidth'])
- self.assertEqual(50, doctree[1][0][1]['colwidth'])
-
- # thead
- thead = doctree[1][0][2]
- self.assertEqual(2, len(thead[0]))
- self.assertEqual('Name', thead[0][0][0][0])
- self.assertEqual('Description', thead[0][1][0][0])
-
- # tbody
- tbody = doctree[1][0][3]
- self.assertEqual(2, len(tbody))
- self.assertEqual('A', tbody[0][0][0][0])
- self.assertEqual('foo', tbody[0][1][0][0])
- self.assertEqual('B', tbody[1][0][0][0])
+ self.assertEqual(1, len(tbody[1][1]))
self.assertEqual('bar', tbody[1][1][0][0])
@use_tmpdir
- def test_rst_directives_with_block_desctable_with_rest_markups(self, path):
+ def test_desctable_with_rest_markups(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :desctable:\n\n" + \
" { A [description = \"foo *bar* **baz**\"]; " + \
@@ -379,7 +337,7 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(' baz', str(tbody[1][1][0][3]))
@use_tmpdir
- def test_rst_directives_with_block_desctable_with_numbered(self, path):
+ def test_desctable_with_numbered(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :desctable:\n\n" + \
" { A [numbered = 2]; B [numbered = 1]; }"
@@ -389,6 +347,42 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(nodes.table, type(doctree[1]))
# tgroup
+ self.assertEqual(4, len(doctree[1][0]))
+ self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
+ self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
+ self.assertEqual(nodes.thead, type(doctree[1][0][2]))
+ self.assertEqual(nodes.tbody, type(doctree[1][0][3]))
+
+ # colspec
+ self.assertEqual(25, doctree[1][0][0]['colwidth'])
+ self.assertEqual(50, doctree[1][0][1]['colwidth'])
+
+ # thead
+ thead = doctree[1][0][2]
+ self.assertEqual(2, len(thead[0]))
+ self.assertEqual('No', thead[0][0][0][0])
+ self.assertEqual('Name', thead[0][1][0][0])
+
+ # tbody
+ tbody = doctree[1][0][3]
+ self.assertEqual(2, len(tbody))
+ self.assertEqual('1', tbody[0][0][0][0])
+ self.assertEqual('B', tbody[0][1][0][0])
+ self.assertEqual('2', tbody[1][0][0][0])
+ self.assertEqual('A', tbody[1][1][0][0])
+
+ @use_tmpdir
+ def test_desctable_with_numbered_and_description(self, path):
+ directives.setup(format='SVG', outputdir=path)
+ text = ".. blockdiag::\n :desctable:\n\n" + \
+ " { A [description = foo, numbered = 2]; " + \
+ " B [description = bar, numbered = 1]; }"
+ doctree = publish_doctree(text)
+ self.assertEqual(2, len(doctree))
+ self.assertEqual(nodes.image, type(doctree[0]))
+ self.assertEqual(nodes.table, type(doctree[1]))
+
+ # tgroup
self.assertEqual(5, len(doctree[1][0]))
self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
@@ -413,13 +407,14 @@ class TestRstDirectives(unittest2.TestCase):
self.assertEqual(2, len(tbody))
self.assertEqual('1', tbody[0][0][0][0])
self.assertEqual('B', tbody[0][1][0][0])
- self.assertEqual(0, len(tbody[0][2]))
+ self.assertEqual(1, len(tbody[0][2]))
+ self.assertEqual('bar', tbody[0][2][0][0])
self.assertEqual('2', tbody[1][0][0][0])
self.assertEqual('A', tbody[1][1][0][0])
- self.assertEqual(0, len(tbody[1][2]))
+ self.assertEqual('foo', tbody[1][2][0][0])
@use_tmpdir
- def test_rst_directives_with_block_desctable_for_edges(self, path):
+ def test_desctable_for_edges(self, path):
directives.setup(format='SVG', outputdir=path)
text = ".. blockdiag::\n :desctable:\n\n" + \
" { A -> B [description = \"foo\"]; " + \
@@ -427,6 +422,48 @@ class TestRstDirectives(unittest2.TestCase):
" C [label = \"label_C\"]; " + \
" D [label = \"label_D\"]; }"
doctree = publish_doctree(text)
+ self.assertEqual(2, len(doctree))
+ self.assertEqual(nodes.image, type(doctree[0]))
+ self.assertEqual(nodes.table, type(doctree[1]))
+
+ # tgroup
+ self.assertEqual(4, len(doctree[1][0]))
+ self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
+ self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
+ self.assertEqual(nodes.thead, type(doctree[1][0][2]))
+ self.assertEqual(nodes.tbody, type(doctree[1][0][3]))
+
+ # colspec
+ self.assertEqual(25, doctree[1][0][0]['colwidth'])
+ self.assertEqual(50, doctree[1][0][1]['colwidth'])
+
+ # thead
+ thead = doctree[1][0][2]
+ self.assertEqual(2, len(thead[0]))
+ self.assertEqual('Name', thead[0][0][0][0])
+ self.assertEqual('Description', thead[0][1][0][0])
+
+ # tbody
+ tbody = doctree[1][0][3]
+ self.assertEqual(2, len(tbody))
+ self.assertEqual('A -> B', tbody[0][0][0][0])
+ self.assertEqual(1, len(tbody[0][1][0]))
+ self.assertEqual(nodes.Text, type(tbody[0][1][0][0]))
+ self.assertEqual('foo', str(tbody[0][1][0][0]))
+ self.assertEqual('label_C -> label_D', tbody[1][0][0][0])
+ self.assertEqual(1, len(tbody[1][1][0]))
+ self.assertEqual(nodes.Text, type(tbody[1][1][0][0]))
+ self.assertEqual('bar', str(tbody[1][1][0][0]))
+
+ @use_tmpdir
+ def test_desctable_for_nodes_and_edges(self, path):
+ directives.setup(format='SVG', outputdir=path)
+ text = ".. blockdiag::\n :desctable:\n\n" + \
+ " { A -> B [description = \"foo\"]; " + \
+ " C -> D [description = \"bar\"]; " + \
+ " C [label = \"label_C\", description = foo]; " + \
+ " D [label = \"label_D\"]; }"
+ doctree = publish_doctree(text)
self.assertEqual(3, len(doctree))
self.assertEqual(nodes.image, type(doctree[0]))
self.assertEqual(nodes.table, type(doctree[1]))
diff --git a/src/blockdiag/utils/bootstrap.py b/src/blockdiag/utils/bootstrap.py
index 0a0a2fc..bac0cdb 100644
--- a/src/blockdiag/utils/bootstrap.py
+++ b/src/blockdiag/utils/bootstrap.py
@@ -49,14 +49,14 @@ class Application(object):
self.fontmap = create_fontmap(self.options)
def parse_diagram(self):
+ import codecs
if self.options.input == '-':
- import codecs
stream = codecs.getreader('utf-8')(sys.stdin)
- tree = self.module.parser.parse_string(stream.read())
+ self.code = stream.read()
else:
- tree = self.module.parser.parse_file(self.options.input)
+ self.code = codecs.open(self.options.input, 'r', 'utf-8').read()
- return tree
+ return self.module.parser.parse_string(self.code)
def build_diagram(self, tree):
DiagramDraw = self.module.drawer.DiagramDraw
@@ -65,7 +65,7 @@ class Application(object):
drawer = DiagramDraw(self.options.type, diagram,
self.options.output, fontmap=self.fontmap,
- antialias=self.options.antialias,
+ code=self.code, antialias=self.options.antialias,
nodoctype=self.options.nodoctype,
transparency=self.options.transparency)
drawer.draw()
@@ -122,8 +122,9 @@ class Options(object):
elif self.options.output == '-':
self.options.output = 'output.' + self.options.type.lower()
else:
+ basename = os.path.splitext(self.options.input)[0]
ext = '.%s' % self.options.type.lower()
- self.options.output = re.sub('\..*?$', ext, self.options.input)
+ self.options.output = basename + ext
self.options.type = self.options.type.upper()
if not self.options.type in ('SVG', 'PNG', 'PDF'):
@@ -181,13 +182,23 @@ class Options(object):
def detectfont(options):
- fonts = ['c:/windows/fonts/VL-Gothic-Regular.ttf', # for Windows
- 'c:/windows/fonts/msgothic.ttf', # for Windows
- 'c:/windows/fonts/msgoth04.ttc', # for Windows
- '/usr/share/fonts/truetype/ipafont/ipagp.ttf', # for Debian
- '/usr/local/share/font-ipa/ipagp.otf', # for FreeBSD
- '/Library/Fonts/Hiragino Sans GB W3.otf', # for MacOS
- '/System/Library/Fonts/AppleGothic.ttf'] # for MacOS
+ fonts = [
+ # for Windows
+ 'c:/windows/fonts/VL-Gothic-Regular.ttf',
+ 'c:/windows/fonts/msgothic.ttf',
+ 'c:/windows/fonts/msgoth04.ttc',
+ # for Debian (squeeze)
+ '/usr/share/fonts/truetype/ipafont/ipagp.ttf',
+ '/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf',
+ # for Debian (wheezy)
+ '/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf',
+ '/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf',
+ # for MacOS
+ '/Library/Fonts/Hiragino Sans GB W3.otf', # for MacOS
+ '/System/Library/Fonts/AppleGothic.ttf', # for MacOS
+ # for FreeBSD
+ '/usr/local/share/font-ipa/ipagp.otf', # for FreeBSD
+ ]
fontpath = None
if options.font:
diff --git a/src/blockdiag/utils/rst/directives.py b/src/blockdiag/utils/rst/directives.py
index 07d4440..946a804 100644
--- a/src/blockdiag/utils/rst/directives.py
+++ b/src/blockdiag/utils/rst/directives.py
@@ -223,8 +223,8 @@ class BlockdiagDirective(BlockdiagDirectiveBase):
descriptions = [n.to_desctable() for n in nodes if n.drawable]
descriptions.sort(cmp_node_number)
- for i in range(len(headers) - 2, -1, -1):
- if [desc[i] for desc in descriptions if desc[i]]:
+ for i in reversed(range(len(headers))):
+ if any(desc[i] for desc in descriptions):
pass
else:
widths.pop(i)
@@ -232,7 +232,10 @@ class BlockdiagDirective(BlockdiagDirectiveBase):
for desc in descriptions:
desc.pop(i)
- return self._description_table(descriptions, widths, headers)
+ if len(headers) == 1:
+ return None
+ else:
+ return self._description_table(descriptions, widths, headers)
def edge_description_table(self, diagram):
edges = diagram.traverse_edges()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/blockdiag.git
More information about the debian-science-commits
mailing list