Skip to content

Commit 9d81e6d

Browse files
committed
fix: template path when using copy-spotter package
1 parent e3cd11e commit 9d81e6d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

scripts/html_writing.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
from os import fsync, path
1111
from random import randint
12-
from shutil import copy
12+
from shutil import copyfile, copy
1313
from typing import Any, List
1414

1515
from bs4 import BeautifulSoup as Bs
16+
import importlib.resources
1617
from tabulate import tabulate
1718

1819
from scripts.html_utils import (
@@ -114,11 +115,18 @@ def get_span_blocks(bs_obj: Bs, text1: list, text2: list, block_size: int) -> li
114115

115116
def papers_comparison(save_dir: str, ind: int, text1: list, text2: list, filenames: tuple, block_size: int) -> None:
116117
"""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")
119118

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)
122130

123131
with open(comp_path, encoding="utf-8") as html:
124132
soup = Bs(html, "html.parser")

0 commit comments

Comments
 (0)