From 1a72ce8d2dea33679ca6156784f5366f0339034f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 28 Mar 2018 21:22:13 +0100 Subject: [PATCH] Get context file relative to main file rather than cwd --- build.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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)