Skip to content

Commit

Permalink
Build native images for seqdiag, nwdiag and actdiag
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Aug 13, 2023
1 parent 2902e14 commit 415eda9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,34 @@ jobs:
sudo apt-get install fonts-ipafont-gothic ghostscript libjpeg8-dev libfreetype6-dev ccache patchelf
pip install -U docutils tox nuitka
pip install .[pdf]
- name: Build native image
pip install seqdiag nwdiag actdiag
- name: Build single binary image
run: |
python3 -m nuitka --include-module=reportlab.pdfgen.canvas --include-module=blockdiag.imagedraw --include-module=blockdiag.plugins --include-module=blockdiag.utils --include-module=blockdiag.noderenderer --onefile `which blockdiag`
- name: Smoke test
run: |
echo 'blockdiag { A -> B; }' | ./blockdiag.bin -Tsvg -
echo 'blockdiag { A -> B; }' | ./blockdiag.bin -Tpng -
echo 'blockdiag { A -> B; }' | ./blockdiag.bin -Tpdf -
python3 -m nuitka --nofollow-import-to=*.tests \
--nofollow-import-to=reportlab.graphics.testshapes \
--include-module=actdiag \
--include-module=nwdiag \
--include-module=seqdiag \
--include-module=packetdiag \
--include-module=rackdiag \
--include-module=reportlab.pdfgen.canvas \
--include-module=blockdiag.imagedraw \
--include-module=blockdiag.plugins \
--include-module=blockdiag.utils \
--include-module=blockdiag.noderenderer \
--onefile src/blockdiag \
--output-filename=blockdiag-bundle.bin
- uses: actions/upload-artifact@v3
with:
name: blockdiag.bin
path: ./blockdiag.bin
name: native-images-amd64
path: ./*.bin
- name: Smoke test
run: |
echo 'blockdiag { A -> B; }' | ./blockdiag-bundle.bin -Tsvg -
echo 'blockdiag { A -> B; }' | ./blockdiag-bundle.bin -Tpng -
echo 'blockdiag { A -> B; }' | ./blockdiag-bundle.bin -Tpdf -
echo 'seqdiag { A -> B [label = "call"]; A <- B [label = "return"]; }' | ./blockdiag-bundle.bin -Tsvg --module=seqdiag -
echo 'actdiag { write -> convert -> image; lane user { label = "User"; write [label = "Writing reST"]; image [label = "Get diagram IMAGE"]; }; lane actdiag { convert [label = "Convert reST to Image"]; } }' | ./blockdiag-bundle.bin -Tsvg --module=actdiag -
echo 'packetdiag { colwidth = 32; node_height = 72; 0-15: Source Port; 16-31: Destination Port; }' | ./blockdiag-bundle.bin -Tsvg --module=packetdiag -
echo 'nwdiag { network dmz { web01; web02; }; network internal { web01; web02; db01; } }' | ./blockdiag-bundle.bin -Tsvg --module=nwdiag -
echo 'rackdiag { 8U; 1: UPS [2U]; 3: DB Server; 4: Web Server; 8: L3 Switch }' | ./blockdiag-bundle.bin -Tsvg --module=rackdiag -
7 changes: 6 additions & 1 deletion src/blockdiag/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BlockdiagApp(Application):

def parse_options(self, args):
self.options = BlockdiagOptions(self.module).parse(args)
if self.options.module:
self.module = self.options.module

def build_diagram(self, tree):
if not self.options.separate:
Expand All @@ -59,5 +61,8 @@ def build_diagram(self, tree):
return 0


def main(args=sys.argv[1:]):
def main(args=None):
if args is None:
args = sys.argv[1:]

return BlockdiagApp().run(args)
28 changes: 23 additions & 5 deletions src/blockdiag/utils/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import codecs
import importlib
import os
import re
import sys
Expand Down Expand Up @@ -103,7 +104,7 @@ def build_diagram(self, tree):
drawer.draw()

if self.options.size:
drawer.save(size=self.options.size)
output = drawer.save(size=self.options.size)
else:
output = drawer.save()

Expand All @@ -127,6 +128,9 @@ def cleanup(self):

class Options(object):
def __init__(self, module):
self.parser = None
self.args = None
self.options = None
self.module = module
self.build_parser()

Expand All @@ -147,6 +151,7 @@ def build_parser(self):
help='read configurations from FILE', metavar='FILE')
p.add_option('--debug', action='store_true',
help='Enable debug mode')
p.add_option('--module', dest='module', help='module name')
p.add_option('-o', dest='output',
help='write diagram to FILE', metavar='FILE')
p.add_option('-f', '--font', default=[], action='append',
Expand Down Expand Up @@ -177,11 +182,14 @@ def validate(self):
if self.options.output:
pass
elif self.options.output == '-':
self.options.output = 'output.' + self.options.type.lower()
self.options.output = None
else:
basename = os.path.splitext(self.options.input)[0]
ext = '.%s' % self.options.type.lower()
self.options.output = basename + ext
if self.options.input == '-':
self.options.output = None
else:
basename = os.path.splitext(self.options.input)[0]
ext = '.%s' % self.options.type.lower()
self.options.output = basename + ext

self.options.type = self.options.type.upper()
try:
Expand Down Expand Up @@ -225,6 +233,16 @@ def validate(self):
msg = "fontmap file is not found: %s" % self.options.fontmap
raise RuntimeError(msg)

if self.options.module:
try:
module = importlib.import_module(self.options.module)
importlib.import_module(f"{self.options.module}.builder")
importlib.import_module(f"{self.options.module}.parser")
importlib.import_module(f"{self.options.module}.drawer")
self.options.module = module
except ImportError:
raise RuntimeError(f"could not load module; Make sure {self.options.module} is available.")

def read_configfile(self):
if self.options.config:
configpath = self.options.config
Expand Down

0 comments on commit 415eda9

Please sign in to comment.