Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def pushd(new_dir):
os.chdir(previous_dir)

def shexec(command):
returncode = subprocess.call(command, shell=True)
if returncode != 0:
print('Command {} failed'.format(command))
raise Exception(returncode)
returncode = subprocess.check_output(command, shell=True)
return returncode

def safe_rm(fname):
if os.path.exists(fname):
Expand Down Expand Up @@ -62,6 +60,66 @@ def make_docs(docspath, version, document, formats):
[safe_rm(f) for f in ("stan-manual.css", "_main.rds")]
shutil.rmtree("_book", ignore_errors=True)

def make_index_page(docset, formats):
# TODO: generate index.md based on current and new docs
# command = "Rscript -e \"bookdown::render_book(\'index.md\', output_format=\'bookdown::html_page\')\""
return

def make_stan_functions(sfpath):
path = os.getcwd()
rmdpath = os.path.join(path, "src", "functions-reference/")
command = "grep --no-filename 'hyperpage' " + rmdpath + "*.Rmd > " + sfpath
shexec(command)
f = open(sfpath, "r+")
text = f.read()
text = text.replace('\\index{{\\tt \\bfseries ', '')
text = text.replace('}!{\\tt ', '')
text = text.replace('}|hyperpage}', '')
text = text.replace('\\_', '_')
text = text.replace(':', ';')
text = text.replace(' (', ';(')
text = text.replace(' (', ';(')
text = text.replace('\\textbar\\', ',')
text = text.replace(' }!sampling statement|hyperpage}', ';~; real')
text = text.replace('~|~/|', '')
text = text.replace('operator_compound_add', 'operator+=')
text = text.replace('operator_compound_subtract', 'operator-=')
text = text.replace('operator_compound_multiply', 'operator*=')
text = text.replace('operator_compound_divide', 'operator/=')
text = text.replace('operator_compound_elt_multiply', 'operator.*=')
text = text.replace('operator_compound_elt_divide', 'operator./=')
text = text.replace('operator_subtract', 'operator-')
text = text.replace('operator_add', 'operator+')
text = text.replace('operator_multiply', 'operator*')
text = text.replace('operator_divide', 'operator\\')
text = text.replace('operator_elt_divide', 'operator.\\')
text = text.replace('operator_elt_multiply', 'operator.*')
text = text.replace('operator_left_div', 'operator\\')
text = text.replace('operator_logical_and', 'operator&&')
text = text.replace('operator_logical_or', 'operator||')
text = text.replace('operator_logical_greater_than_equal', 'operator>=')
text = text.replace('operator_logical_less_than_equal', 'operator<=')
text = text.replace('operator_logical_greater_than', 'operator>')
text = text.replace('operator_logical_less_than', 'operator<')
text = text.replace('operator_logical_not_equal', 'operator!=')
text = text.replace('operator_logical_equal', 'operator==')
text = text.replace('operator_mod', 'operator%')
text = text.replace('operator_negation', 'operator!')
text = text.replace('operator_pow', 'operator^')
text = text.replace('operator_transpose', "operator'")
f.write(text)
f.close()
command = "sort " + sfpath + " | uniq > " + sfpath + ".bak"
shexec(command)
command = "echo '# This file is semicolon delimited\nStanFunction;Arguments;ReturnType' > " + sfpath
shexec(command)
command = "grep --invert-match 'bfseries' " + sfpath + ".bak >> " + sfpath
shexec(command)
command = "rm " + sfpath + ".bak"
shexec(command)
return


def main():
global all_docs
global all_formats
Expand Down Expand Up @@ -108,6 +166,8 @@ def main():
for doc in docset:
make_docs(docspath, stan_version, doc, formats)

make_stan_functions(docspath + "/stan-functions.txt")


if __name__ == "__main__":
main()