Skip to content

Commit 57f4637

Browse files
author
Sam Kleinman
committed
build: table builder makefile automated.
1 parent 8441701 commit 57f4637

File tree

5 files changed

+69
-67
lines changed

5 files changed

+69
-67
lines changed

bin/makefile.tables

Lines changed: 0 additions & 59 deletions
This file was deleted.

bin/makefile_builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ def section_break(self, name, block='_all'):
4848
def comment(self, comment, block='_all'):
4949
self.add_to_builder('\n# ' + comment + '\n', block)
5050

51-
def newline(self, block='_all'):
52-
self.add_to_builder('\n', block)
51+
def newline(self, n=1, block='_all'):
52+
for i in range(n):
53+
self.add_to_builder('\n', block)
5354

5455
def target(self, target, dependency='', block='_all'):
5556
self.add_to_builder(target + ':' + dependency + '\n', block)
@@ -79,7 +80,7 @@ def print_content(self, block_order=['_all']):
7980
o.append(self.builder[block])
8081
o = [item for sublist in o for item in sublist]
8182
for line in o:
82-
print(line.rstrip('\n'))
83+
print(line.rstrip())
8384

8485
def write(self, filename, block_order=['_all']):
8586
o = []

bin/pdf_makefile_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ def build_all_pdfs(pdfs):
4242
pdf_makefile(pdf[0], pdf[1])
4343

4444
m.newline()
45+
m.target(target='.PHONY',
46+
dependency='manual-pdfs')
4547
m.target(target='manual-pdfs',
4648
dependency='$(PDF_OUTPUT)')
4749

4850
def main():
4951
build_all_pdfs(pdfs_to_build)
5052
m.write(sys.argv[1])
51-
m.print_content()
5253
print('[meta-build]: built "' + sys.argv[1] + '" to specify pdf builders.')
5354

5455
if __name__ == '__main__':

bin/table_makefile_builder.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
from makefile_builder import MakefileBuilder
5+
6+
# to add a table to the build process, add a tuple to the ``tables_to_build`` list.
7+
8+
tables_to_build = [
9+
# (input_file, output_file, makefile_block)
10+
('$(rst-include)/table-sql-to-agg-terms.yaml', '$(rst-include)/table-sql-to-agg-terms.rst', 'agg'),
11+
('$(rst-include)/table-sql-to-agg-examples.yaml','$(rst-include)/table-sql-to-agg-examples.rst', 'agg'),
12+
('$(rst-include)/table-sql-to-mongo-executables.yaml', '$(rst-include)/table-sql-to-mongo-executables.rst', 'sql'),
13+
('$(rst-include)/table-sql-to-mongo-terms.yaml', '$(rst-include)/table-sql-to-mongo-terms.rst', 'sql'),
14+
('$(rst-include)/table-sql-to-mongo-schema-examples.yaml', '$(rst-include)/table-sql-to-mongo-schema-examples.rst', 'sql'),
15+
('$(rst-include)/table-sql-to-mongo-insert-examples.yaml', '$(rst-include)/table-sql-to-mongo-insert-examples.rst', 'sql'),
16+
('$(rst-include)/table-sql-to-mongo-select-examples.yaml', '$(rst-include)/table-sql-to-mongo-select-examples.rst', 'sql'),
17+
('$(rst-include)/table-sql-to-mongo-update-examples.yaml', '$(rst-include)/table-sql-to-mongo-update-examples.rst', 'sql'),
18+
('$(rst-include)/table-sql-to-mongo-delete-examples.yaml', '$(rst-include)/table-sql-to-mongo-delete-examples.rst', 'sql'),
19+
]
20+
21+
m = MakefileBuilder()
22+
23+
def build_all_tables(tables):
24+
m.comment('each table is compiled into rst from a yaml file using the table_builder.py file.', block='header')
25+
m.newline(block='header')
26+
27+
for table in tables:
28+
makefile_table(table[0], table[1], table[2])
29+
30+
m.comment('meta-targets for testing/integration with rest of the build. must apear at the end', block='footer')
31+
m.newline(block='footer')
32+
33+
m.target('.PHONY', 'tables clean-tables', block='footer')
34+
m.target('tables', '$(output-tables)', block='footer')
35+
m.job('git update-index --assume-unchanged', block='footer')
36+
m.msg('[build]: clensing git index of compiled tables', block='footer')
37+
m.newline(block='footer')
38+
m.target('clean-tables', block='footer')
39+
m.job('rm -rf $(output-tables)', True)
40+
41+
def makefile_table(input, output, block):
42+
m.append_var('output-tables', output, block)
43+
m.target(output, input, block)
44+
m.job('$(PYTHONBIN) bin/table_builder.py $< $@', block)
45+
m.msg('[table-builder]: \(re\)generate $@ table for inclusion in build', block)
46+
m.newline(block=block)
47+
48+
def main():
49+
build_all_tables(tables_to_build)
50+
51+
m.write(sys.argv[1])
52+
53+
print('[meta-build]: built "' + sys.argv[1] + '" to specify table builders.')
54+
55+
if __name__ == '__main__':
56+
main()

makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ MAKEFLAGS += --no-print-directory
55

66
# includes
77
include bin/makefile.compatibility
8-
include bin/makefile.tables
98

109
# Build directory tweaking.
1110
output = build
11+
rst-include = source/includes
1212
build-tools = bin
1313
public-output = $(output)/public
1414
branch-output = $(output)/$(current-branch)
@@ -190,11 +190,14 @@ $(branch-output)/singlehtml/contents.html:$(branch-output)/singlehtml
190190

191191
# Building and Linking the LaTeX/PDF Output
192192
#
193-
.PHONY: manual-pdfs
194193

195-
-include build/makefile.pdfs
196-
$(output)/makefile.pdfs:bin/pdf_makefile_builder.py
194+
-include $(output)/makefile.pdfs
195+
-include $(output)/makefile.tables
196+
197+
$(output)/makefile.pdfs:bin/pdf_makefile_builder.py bin/makefile_builder.py
197198
@bin/pdf_makefile_builder.py $@
199+
$(output)/makefile.tables:bin/table_makefile_builder.py bin/makefile_builder.py
200+
@bin/table_makefile_builder.py $@
198201

199202
#
200203
# Building and Linking ePub Output

0 commit comments

Comments
 (0)