diff --git a/build.py b/build.py index 09cba33..62087a1 100755 --- a/build.py +++ b/build.py @@ -11,16 +11,12 @@ CWD = pathlib.Path(os.getcwd()) BASE_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_FILE = BASE_DIR / 'main.tex' OUTPUT_FILE = CWD / 'output.pdf' -CONTEXT_FILE = CWD / 'context.yaml' WORDCOUNT_TEMPLATE = BASE_DIR / 'wordcount.yaml' def build(input_file, additional_args=None): build_args = ['pandoc', str(input_file)] - if CONTEXT_FILE.exists(): - build_args.append(str(CONTEXT_FILE)) - if additional_args is not None: build_args.extend(additional_args) @@ -60,8 +56,13 @@ def parse_args(): if __name__ == '__main__': args = parse_args() input_file = args.input.resolve() + operating_dir = input_file.parents[0] + context_file = operating_dir.joinpath('context.yaml') if not input_file.is_file(): raise ValueError("Failed to find {}".format(input_file)) - build(input_file) - wordcount_metadata_file = write_wordcount() - build(input_file, [str(wordcount_metadata_file)]) + additional_args = [] + if context_file.exists(): + additional_args.append(str(context_file)) + build(input_file, additional_args) + additional_args.append(write_wordcount()) + build(input_file,additional_args)