-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
87 lines (66 loc) · 2.73 KB
/
wscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! python
import os
from collections import OrderedDict
# The project root directory and the build directory.
top = "."
out = "bld"
def set_project_paths(ctx):
"""Return a dictionary with project paths represented by Waf nodes."""
pp = OrderedDict()
pp["PROJECT_ROOT"] = "."
pp["IN_DATA"] = "src/original_data/"
pp["IN_MODEL_CODE"] = "src/model_code"
pp["IN_MODEL_SPECS"] = "src/model_specs"
pp["LIBRARY"] = "src/library"
pp["BLD"] = ""
pp["OUT_DATA"] = f"{out}/out/data"
pp["OUT_ANALYSIS"] = f"{out}/out/analysis"
pp["OUT_FINAL"] = f"{out}/out/final"
pp["OUT_FIGURES"] = f"{out}/out/figures"
# OUT_MODEL_SPECS is only required for using Stata with JSON and
# can be safely deleted otherwise
pp["OUT_MODEL_SPECS"] = f"{out}/src/model_specs"
pp["OUT_TABLES"] = f"{out}/out/tables"
# Convert the directories into Waf nodes.
for key, val in pp.items():
if not key == "ADO":
pp[key] = ctx.path.make_node(val)
else:
for adokey, adoval in val.items():
pp[key][adokey] = ctx.path.make_node(adoval)
return pp
def path_to(ctx, pp_key, *args):
"""Return the relative path to os.path.join(*args*) in the directory
PROJECT_PATHS[pp_key] as seen from ctx.path (i.e. the directory of the
current wscript).
Use this to get the relative path---as needed by Waf---to a file in one
of the directory trees defined in the PROJECT_PATHS dictionary above.
We always pretend everything is in the source directory tree, Waf takes
care of the correct placing of targets and sources.
"""
# Implementation detail:
# We find the path to the directory where the file lives, so that
# we do not accidentally declare a node that does not exist.
dir_path_in_tree = os.path.join(".", *args[:-1])
# Find/declare the directory node. Use an alias to shorten the line.
pp_key_fod = ctx.env.PROJECT_PATHS[pp_key].find_or_declare
dir_node = pp_key_fod(dir_path_in_tree).get_src()
# Get the relative path to the directory.
path_to_dir = dir_node.path_from(ctx.path)
# Return the relative path to the file.
return os.path.join(path_to_dir, args[-1])
def configure(ctx):
ctx.env.PYTHONPATH = os.getcwd()
# Disable on a machine where security risks could arise
ctx.env.PDFLATEXFLAGS = "-shell-escape"
ctx.load("run_py_script")
ctx.load("write_project_headers")
# ctx.find_program("dot")
ctx.load("tex")
def build(ctx):
ctx.env.PROJECT_PATHS = set_project_paths(ctx)
ctx.path_to = path_to
# Generate header file(s) with project paths in "bld" directory
ctx(features="write_project_paths", target="project_paths.py")
ctx.add_group()
ctx.recurse("src")