Skip to content

Commit 65b6984

Browse files
authored
Include HTML2PDF.js to the Pip package (#14)
1 parent e6cda57 commit 65b6984

File tree

4 files changed

+61
-24
lines changed

4 files changed

+61
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# HTML2PDF JS file.
2+
html2print/html2pdf_js/
3+
14
.idea/
25
**/.wdm/
36
build/

html2print/html2print.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
from webdriver_manager.core.http import HttpClient
2424
from webdriver_manager.core.os_manager import OperationSystemManager
2525

26-
__version__ = "0.0.5"
26+
__version__ = "0.0.7"
27+
28+
PATH_TO_HTML2PDF_JS = os.path.join(
29+
os.path.dirname(os.path.join(__file__)), "html2pdf_js", "html2pdf.min.js"
30+
)
2731

2832
DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".html2print", "chromedriver")
2933

@@ -239,6 +243,12 @@ def main():
239243
# You can override this setting and save binaries to project.root/.wdm.
240244
os.environ["WDM_LOCAL"] = "1"
241245

246+
if not os.path.isfile(PATH_TO_HTML2PDF_JS):
247+
raise RuntimeError(
248+
f"Corrupted html2print package bundle. "
249+
f"The HTML2PDF.js file is missing at path: {PATH_TO_HTML2PDF_JS}."
250+
)
251+
242252
parser = argparse.ArgumentParser(description="HTML2Print printer script.")
243253

244254
parser.add_argument(

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ build-backend = "hatchling.build"
66
path = "html2print/html2print.py"
77

88
[tool.hatch.build]
9+
# We want HTML2PDF.js to be gitignored, but we want it to make into the dist/
10+
# folder, into both tar.gz and .whl when the Pip package is built.
11+
# This option prevents Hatch from using .gitignore to exclude files.
12+
ignore-vcs = true
13+
914
include = [
10-
"/html2print/",
11-
"LICENSE",
12-
"README.md",
13-
"pyproject.toml"
15+
"html2print/html2print.py",
16+
"html2print/html2pdf_js/html2pdf.min.js",
1417
]
1518

1619
exclude = [

tasks.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,24 @@ def bootstrap(context):
5858
run_invoke(context, "pip install -r requirements.development.txt")
5959

6060

61-
@task
61+
@task(aliases=["b"])
6262
def build(context):
6363
run_invoke(
6464
context, "cd submodules/html2pdf && npm install && npm run build"
6565
)
66+
# Windows can't do slashes for this one.
67+
run_invoke(
68+
context,
69+
"""
70+
cd html2print && mkdir html2pdf_js
71+
""",
72+
)
73+
run_invoke(
74+
context,
75+
"""
76+
cp submodules/html2pdf/dist/bundle.js html2print/html2pdf_js/html2pdf.min.js
77+
""",
78+
)
6679

6780

6881
@task
@@ -193,6 +206,30 @@ def clean_itest_artifacts(context):
193206
run_invoke(context, find_command, warn=True)
194207

195208

209+
@task
210+
def package(context):
211+
build(context)
212+
213+
run_invoke(
214+
context,
215+
"""
216+
rm -rfv dist/
217+
""",
218+
)
219+
run_invoke(
220+
context,
221+
"""
222+
python3 -m build
223+
""",
224+
)
225+
run_invoke(
226+
context,
227+
"""
228+
twine check dist/*
229+
""",
230+
)
231+
232+
196233
@task
197234
def release(context, test_pypi=False, username=None, password=None):
198235
"""
@@ -205,6 +242,8 @@ def release(context, test_pypi=False, username=None, password=None):
205242
# tokens set up on a local machine.
206243
assert username is None or password is not None
207244

245+
package(context)
246+
208247
repository_argument_or_none = (
209248
""
210249
if username
@@ -216,24 +255,6 @@ def release(context, test_pypi=False, username=None, password=None):
216255
)
217256
user_password = f"-u{username} -p{password}" if username is not None else ""
218257

219-
run_invoke(
220-
context,
221-
"""
222-
rm -rfv dist/
223-
""",
224-
)
225-
run_invoke(
226-
context,
227-
"""
228-
python3 -m build
229-
""",
230-
)
231-
run_invoke(
232-
context,
233-
"""
234-
twine check dist/*
235-
""",
236-
)
237258
# The token is in a core developer's .pypirc file.
238259
# https://test.pypi.org/manage/account/token/
239260
# https://packaging.python.org/en/latest/specifications/pypirc/#pypirc

0 commit comments

Comments
 (0)