From bd8778394db6b5c3dadd2802ef78bef3469fab6b Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Wed, 5 Feb 2025 22:18:06 +0100 Subject: [PATCH] Include HTML2PDF.js to the Pip package --- .gitignore | 3 ++ html2print/html2print.py | 12 +++++++- pyproject.toml | 11 +++++--- tasks.py | 59 +++++++++++++++++++++++++++------------- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index ad82c22..9a07f38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# HTML2PDF JS file. +html2print/html2pdf_js/ + .idea/ **/.wdm/ build/ diff --git a/html2print/html2print.py b/html2print/html2print.py index 93edb66..fe93e42 100644 --- a/html2print/html2print.py +++ b/html2print/html2print.py @@ -23,7 +23,11 @@ from webdriver_manager.core.http import HttpClient from webdriver_manager.core.os_manager import OperationSystemManager -__version__ = "0.0.5" +__version__ = "0.0.7" + +PATH_TO_HTML2PDF_JS = os.path.join( + os.path.dirname(os.path.join(__file__)), "html2pdf_js", "html2pdf.min.js" +) DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".html2print", "chromedriver") @@ -239,6 +243,12 @@ def main(): # You can override this setting and save binaries to project.root/.wdm. os.environ["WDM_LOCAL"] = "1" + if not os.path.isfile(PATH_TO_HTML2PDF_JS): + raise RuntimeError( + f"Corrupted html2print package bundle. " + f"The HTML2PDF.js file is missing at path: {PATH_TO_HTML2PDF_JS}." + ) + parser = argparse.ArgumentParser(description="HTML2Print printer script.") parser.add_argument( diff --git a/pyproject.toml b/pyproject.toml index d18deaa..7ac79bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,11 +6,14 @@ build-backend = "hatchling.build" path = "html2print/html2print.py" [tool.hatch.build] +# We want HTML2PDF.js to be gitignored, but we want it to make into the dist/ +# folder, into both tar.gz and .whl when the Pip package is built. +# This option prevents Hatch from using .gitignore to exclude files. +ignore-vcs = true + include = [ - "/html2print/", - "LICENSE", - "README.md", - "pyproject.toml" + "html2print/html2print.py", + "html2print/html2pdf_js/html2pdf.min.js", ] exclude = [ diff --git a/tasks.py b/tasks.py index b883ab8..8fe996b 100644 --- a/tasks.py +++ b/tasks.py @@ -58,11 +58,24 @@ def bootstrap(context): run_invoke(context, "pip install -r requirements.development.txt") -@task +@task(aliases=["b"]) def build(context): run_invoke( context, "cd submodules/html2pdf && npm install && npm run build" ) + # Windows can't do slashes for this one. + run_invoke( + context, + """ + cd html2print && mkdir html2pdf_js + """, + ) + run_invoke( + context, + """ + cp submodules/html2pdf/dist/bundle.js html2print/html2pdf_js/html2pdf.min.js + """, + ) @task @@ -193,6 +206,30 @@ def clean_itest_artifacts(context): run_invoke(context, find_command, warn=True) +@task +def package(context): + build(context) + + run_invoke( + context, + """ + rm -rfv dist/ + """, + ) + run_invoke( + context, + """ + python3 -m build + """, + ) + run_invoke( + context, + """ + twine check dist/* + """, + ) + + @task def release(context, test_pypi=False, username=None, password=None): """ @@ -205,6 +242,8 @@ def release(context, test_pypi=False, username=None, password=None): # tokens set up on a local machine. assert username is None or password is not None + package(context) + repository_argument_or_none = ( "" if username @@ -216,24 +255,6 @@ def release(context, test_pypi=False, username=None, password=None): ) user_password = f"-u{username} -p{password}" if username is not None else "" - run_invoke( - context, - """ - rm -rfv dist/ - """, - ) - run_invoke( - context, - """ - python3 -m build - """, - ) - run_invoke( - context, - """ - twine check dist/* - """, - ) # The token is in a core developer's .pypirc file. # https://test.pypi.org/manage/account/token/ # https://packaging.python.org/en/latest/specifications/pypirc/#pypirc