implement option to prune old files in build directory

This commit is contained in:
Maximilian Keßler 2022-01-13 20:56:09 +01:00
parent bfd0f6e01b
commit f5a5ad6328
1 changed files with 12 additions and 0 deletions

View File

@ -130,6 +130,18 @@ def build(
for info in infos:
built_files = [info['name'] for info in info_dict['tex_sources']]
if last_build_info:
lastly_built_files = [info['name'] for info in last_build_info['tex_sources']]
lastly_built_files = []
if clean_old_files:
for file in output_dir.rglob('*'):
if str(file.relative_to(output_dir)) in lastly_built_files:
if str(file.relative_to(output_dir)) not in built_files:
print(f'[PyTeX] Removing old built file {str(file.relative_to(output_dir))}')
if write_build_information:
with open(output_dir / 'build_info.json', 'w') as f:
json.dump(info_dict, f, indent=4)