Skip to content

Commit e574b5c

Browse files
committed
Include HTML2PDF.js to the Pip package
1 parent e6cda57 commit e574b5c

5 files changed

Lines changed: 57 additions & 24 deletions

File tree

.github/workflows/ci-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
- name: Build HTML2PDF.js
6666
run: |
6767
invoke build
68+
shell: bash
6869

6970
- name: Download ChromeDriver
7071
run: |

.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: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ 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+
run_invoke(
67+
context,
68+
"""
69+
mkdir -p html2print/html2pdf_js
70+
&&
71+
cp submodules/html2pdf/dist/bundle.js html2print/html2pdf_js/html2pdf.min.js
72+
""",
73+
)
6674

6775

6876
@task
@@ -193,6 +201,30 @@ def clean_itest_artifacts(context):
193201
run_invoke(context, find_command, warn=True)
194202

195203

204+
@task
205+
def package(context):
206+
build(context)
207+
208+
run_invoke(
209+
context,
210+
"""
211+
rm -rfv dist/
212+
""",
213+
)
214+
run_invoke(
215+
context,
216+
"""
217+
python3 -m build
218+
""",
219+
)
220+
run_invoke(
221+
context,
222+
"""
223+
twine check dist/*
224+
""",
225+
)
226+
227+
196228
@task
197229
def release(context, test_pypi=False, username=None, password=None):
198230
"""
@@ -205,6 +237,8 @@ def release(context, test_pypi=False, username=None, password=None):
205237
# tokens set up on a local machine.
206238
assert username is None or password is not None
207239

240+
package(context)
241+
208242
repository_argument_or_none = (
209243
""
210244
if username
@@ -216,24 +250,6 @@ def release(context, test_pypi=False, username=None, password=None):
216250
)
217251
user_password = f"-u{username} -p{password}" if username is not None else ""
218252

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-
)
237253
# The token is in a core developer's .pypirc file.
238254
# https://test.pypi.org/manage/account/token/
239255
# https://packaging.python.org/en/latest/specifications/pypirc/#pypirc

0 commit comments

Comments
 (0)