Get context file relative to main file rather than cwd
This commit is contained in:
parent
0a53d6c7ec
commit
1a72ce8d2d
1 changed files with 8 additions and 7 deletions
15
build.py
15
build.py
|
@ -11,16 +11,12 @@ CWD = pathlib.Path(os.getcwd())
|
||||||
BASE_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
TEMPLATE_FILE = BASE_DIR / 'main.tex'
|
TEMPLATE_FILE = BASE_DIR / 'main.tex'
|
||||||
OUTPUT_FILE = CWD / 'output.pdf'
|
OUTPUT_FILE = CWD / 'output.pdf'
|
||||||
CONTEXT_FILE = CWD / 'context.yaml'
|
|
||||||
WORDCOUNT_TEMPLATE = BASE_DIR / 'wordcount.yaml'
|
WORDCOUNT_TEMPLATE = BASE_DIR / 'wordcount.yaml'
|
||||||
|
|
||||||
|
|
||||||
def build(input_file, additional_args=None):
|
def build(input_file, additional_args=None):
|
||||||
build_args = ['pandoc', str(input_file)]
|
build_args = ['pandoc', str(input_file)]
|
||||||
|
|
||||||
if CONTEXT_FILE.exists():
|
|
||||||
build_args.append(str(CONTEXT_FILE))
|
|
||||||
|
|
||||||
if additional_args is not None:
|
if additional_args is not None:
|
||||||
build_args.extend(additional_args)
|
build_args.extend(additional_args)
|
||||||
|
|
||||||
|
@ -60,8 +56,13 @@ def parse_args():
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
input_file = args.input.resolve()
|
input_file = args.input.resolve()
|
||||||
|
operating_dir = input_file.parents[0]
|
||||||
|
context_file = operating_dir.joinpath('context.yaml')
|
||||||
if not input_file.is_file():
|
if not input_file.is_file():
|
||||||
raise ValueError("Failed to find {}".format(input_file))
|
raise ValueError("Failed to find {}".format(input_file))
|
||||||
build(input_file)
|
additional_args = []
|
||||||
wordcount_metadata_file = write_wordcount()
|
if context_file.exists():
|
||||||
build(input_file, [str(wordcount_metadata_file)])
|
additional_args.append(str(context_file))
|
||||||
|
build(input_file, additional_args)
|
||||||
|
additional_args.append(write_wordcount())
|
||||||
|
build(input_file,additional_args)
|
||||||
|
|
Reference in a new issue