|
9 | 9 |
|
10 | 10 | from os import fsync, path
|
11 | 11 | from random import randint
|
12 |
| -from shutil import copy |
| 12 | +from shutil import copyfile, copy |
13 | 13 | from typing import Any, List
|
14 | 14 |
|
15 | 15 | from bs4 import BeautifulSoup as Bs
|
| 16 | +import importlib.resources |
16 | 17 | from tabulate import tabulate
|
17 | 18 |
|
18 | 19 | from scripts.html_utils import (
|
@@ -114,11 +115,18 @@ def get_span_blocks(bs_obj: Bs, text1: list, text2: list, block_size: int) -> li
|
114 | 115 |
|
115 | 116 | def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenames: tuple, block_size: int) -> None:
|
116 | 117 | """Write to HTML file texts that have been compared with highlighted similar blocks"""
|
117 |
| - template_path = path.join("templates", "template.html") |
118 |
| - comp_path = path.join(save_dir, str(ind) + ".html") |
119 | 118 |
|
120 |
| - # Copy the template to the save directory under a new name |
121 |
| - copy(template_path, comp_path) |
| 119 | + try: |
| 120 | + with importlib.resources.path("copy_spotter.templates", "template.html") as template_path: |
| 121 | + comp_path = path.join(save_dir, f"{ind}.html") |
| 122 | + copyfile(template_path, comp_path) |
| 123 | + except ModuleNotFoundError: |
| 124 | + # Fallback for local development |
| 125 | + template_path_local = path.join("templates", "template.html") |
| 126 | + comp_path = path.join(save_dir, str(ind) + ".html") |
| 127 | + |
| 128 | + # Copy the template to the save directory under a new name |
| 129 | + copy(template_path_local, comp_path) |
122 | 130 |
|
123 | 131 | with open(comp_path, encoding="utf-8") as html:
|
124 | 132 | soup = Bs(html, "html.parser")
|
|
0 commit comments