Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# HTML2PDF JS file.
html2print/html2pdf_js/

.idea/
**/.wdm/
build/
Expand Down
12 changes: 11 additions & 1 deletion html2print/html2print.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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(
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
59 changes: 40 additions & 19 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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
Expand All @@ -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
Expand Down