Skip to content

Commit dd284d0

Browse files
committed
Reformated by black, removed waiting to CSS creation
1 parent 184157b commit dd284d0

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

main.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def __init__(self, include_private_data):
2424
autoescape=select_autoescape(["html", "xml"]),
2525
)
2626
repo = Repo(search_parent_directories=True)
27-
self.env.globals.update({
28-
'short_git_sha': repo.head.object.hexsha[:7]
29-
})
27+
self.env.globals.update({"short_git_sha": repo.head.object.hexsha[:7]})
3028
# Render output on startup
3129
print("Render on startup")
3230
self.create_output()
@@ -40,7 +38,6 @@ def create_output(self):
4038
self.tailwindcss_build()
4139
self.create_pdf(output_html_path, name)
4240

43-
4441
def on_closed(self, event):
4542
print(event)
4643
print(event.src_path)
@@ -56,20 +53,27 @@ def create_pdf(self, url, file_name):
5653
page = browser.new_page()
5754
page.goto(f"file:///{url}")
5855
page.emulate_media(media="print")
59-
# Waiting for the side to be loaded matters, else the fallback font is applied
56+
# Waiting for the custom fonts to be loaded matters, else the fallback font is applied
6057
page.wait_for_function("document.fonts.status === 'loaded'")
61-
# Wait for the CSS file to load
62-
page.wait_for_function("""
58+
# Wait for the CSS file to be loaded matters as well
59+
page.wait_for_function(
60+
"""
6361
() => {
6462
const link = [...document.querySelectorAll('link[rel="stylesheet"]')].find(
6563
l => l.href.includes('tailwind.css')
6664
);
6765
return link && link.sheet;
6866
}
69-
""")
67+
"""
68+
)
7069
print("CSS file has loaded!")
7170
page.wait_for_load_state("networkidle")
72-
page.pdf(path=f"./output/{file_name}.pdf", format="A4",landscape=False, margin={"top": "2cm"})
71+
page.pdf(
72+
path=f"./output/{file_name}.pdf",
73+
format="A4",
74+
landscape=False,
75+
margin={"top": "2cm"},
76+
)
7377
browser.close()
7478

7579
def merge_dicts(self, dict1, dict2):
@@ -110,9 +114,6 @@ def tailwindcss_build(self):
110114
result = subprocess.run(
111115
command, check=True, capture_output=True, text=True, shell=True
112116
)
113-
while not os.path.exists("static/css/tailwind.css"):
114-
print(f"Waiting for CSS file to be created...")
115-
time.sleep(0.01)
116117
print(result.stdout)
117118
print(result.stderr)
118119
print("Tailwind CSS compiled successfully:")

0 commit comments

Comments
 (0)