From 2834392e6b75a308ac55dea8238db45e35acec0c Mon Sep 17 00:00:00 2001 From: Andreas Nordin Date: Wed, 24 Jun 2020 19:09:08 +0200 Subject: [PATCH] update build_examples script --- README.md | 8 ++++++++ src/wireviz/build_examples.py | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/wireviz/build_examples.py diff --git a/README.md b/README.md index 0ec6f6b..3f90415 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,14 @@ pip3 install -e . ## Examples +### (re)building the example projects + +If you would like to rebuild all of the included demos, examples and tutorials, use the ```build_examples.py``` script: + +```cd src/wireviz +./build_examples.py +``` + ### Demo 01 [WireViz input file](examples/demo01.yml): diff --git a/src/wireviz/build_examples.py b/src/wireviz/build_examples.py old mode 100644 new mode 100755 index a880340..114d904 --- a/src/wireviz/build_examples.py +++ b/src/wireviz/build_examples.py @@ -1,5 +1,11 @@ -import wireviz +#!/usr/bin/python3 + import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) + +from wireviz import wireviz demos = 2 # 2 examples = 6 # 6 @@ -7,15 +13,15 @@ tutorials = 7 # 7 if demos: for i in range(1,demos+1): - fn = '../examples/demo{:02d}.yml'.format(i) + fn = '../../examples/demo{:02d}.yml'.format(i) print(fn) wireviz.parse(fn, gen_bom=True) if examples: - with open(os.path.abspath('../examples/readme.md'), 'w') as file: + with open(os.path.abspath('../../examples/readme.md'), 'w') as file: file.write('# Example gallery\n') for i in range(1,examples+1): - fn = '../examples/ex{:02d}.yml'.format(i) + fn = '../../examples/ex{:02d}.yml'.format(i) print(fn) wireviz.parse(fn, gen_bom=True) @@ -24,19 +30,19 @@ if examples: file.write('[Source](ex{:02d}.yml) - [Bill of Materials](ex{:02d}.bom.tsv)\n\n\n'.format(i,i)) if tutorials: - with open(os.path.abspath('../tutorial/readme.md'), 'w') as file: + with open(os.path.abspath('../../tutorial/readme.md'), 'w') as file: file.write('# WireViz Tutorial\n') for i in range(1,tutorials+1): - fn = '../tutorial/tutorial{:02d}.yml'.format(i) + fn = '../../tutorial/tutorial{:02d}.yml'.format(i) print(fn) wireviz.parse(fn, gen_bom=True) - with open(os.path.abspath('../tutorial/tutorial{:02d}.md'.format(i)), 'r') as info: + with open(os.path.abspath('../../tutorial/tutorial{:02d}.md'.format(i)), 'r') as info: for line in info: file.write(line.replace('## ', '## {} - '.format(i))) file.write('\n[Source](tutorial{:02d}.yml):\n\n'.format(i)) - with open(os.path.abspath('../tutorial/tutorial{:02d}.yml'.format(i)), 'r') as src: + with open(os.path.abspath('../../tutorial/tutorial{:02d}.yml'.format(i)), 'r') as src: file.write('```yaml\n') for line in src: file.write(line)