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
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux-ubuntu-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Install HPDF dependencies.
run: |
python developer/pip_install_hpdf_deps.py
python developer/pip_install_html2print_deps.py

- name: Run Lint tasks
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- name: Install HPDF dependencies.
run: |
python developer/pip_install_hpdf_deps.py
python developer/pip_install_html2print_deps.py

- name: Run Lint tasks
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

- name: Install HPDF dependencies.
run: |
python developer/pip_install_hpdf_deps.py
python developer/pip_install_html2print_deps.py

- name: Run Lint tasks
run: |
Expand All @@ -68,7 +68,7 @@ jobs:

- name: Download ChromeDriver
run: |
python hpdf/hpdf.py get_driver
python html2print/html2print.py get_driver

- name: Run tests (Bash)
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea/
**/.wdm/
build/
dist/
tests/integration/.lit_test_times.txt
tests/integration/**/Output/

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check_if_package_installed(package_name: str):


print( # noqa: T201
"pip_install_hpdf_deps.py: "
"pip_install_html2print_deps.py: "
"checking if the current Python environment has all packages installed"
".",
flush=True,
Expand All @@ -48,7 +48,7 @@ def check_if_package_installed(package_name: str):
check_if_package_installed(dependency)
except PackageNotFound:
print( # noqa: T201
f"pip_install_hpdf_deps.py: "
f"pip_install_html2print_deps.py: "
f"Package is not installed: '{dependency}'.",
flush=True,
)
Expand All @@ -57,8 +57,8 @@ def check_if_package_installed(package_name: str):
except PackageVersionConflict as exception_:
print( # noqa: T201
(
f"pip_install_hpdf_deps.py: version conflict between "
f"hpdf's requirement '{dependency}' "
f"pip_install_html2print_deps.py: version conflict between "
f"html2print's requirement '{dependency}' "
f"and the already installed package: "
f"{exception_.args[0]}."
),
Expand All @@ -69,13 +69,13 @@ def check_if_package_installed(package_name: str):

if not needs_installation:
print( # noqa: T201
"pip_install_hpdf_deps.py: all packages seem to be installed.",
"pip_install_html2print_deps.py: all packages seem to be installed.",
flush=True,
)
sys.exit(0)

print( # noqa: T201
"pip_install_hpdf_deps.py: will install packages.", flush=True
"pip_install_html2print_deps.py: will install packages.", flush=True
)

all_packages = "\n".join(dependencies) + "\n"
Expand Down
14 changes: 7 additions & 7 deletions hpdf/hpdf.py → html2print/html2print.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from webdriver_manager.core.http import HttpClient
from webdriver_manager.core.os_manager import OperationSystemManager

__version__ = "0.0.1"
__version__ = "0.0.2"

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

# HTML2PDF.js prints unicode symbols to console. The following makes it work on
# Windows which otherwise complains:
Expand All @@ -35,7 +35,7 @@
sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="utf8", closefd=False)


class HTML2PDF_HTTPClient(HttpClient):
class HTML2Print_HTTPClient(HttpClient):
def get(self, url, params=None, **kwargs) -> Response:
last_error: Optional[Exception] = None
for attempt in range(1, 3):
Expand All @@ -58,7 +58,7 @@ def get(self, url, params=None, **kwargs) -> Response:
)


class HTML2PDF_CacheManager(DriverCacheManager):
class HTML2Print_CacheManager(DriverCacheManager):
def __init__(self, file_manager: FileManager, path_to_cache_dir: str):
super().__init__(file_manager=file_manager)
self.path_to_cache_dir: str = path_to_cache_dir
Expand Down Expand Up @@ -187,12 +187,12 @@ class Done(Exception):


def get_chrome_driver(path_to_cache_dir: str) -> str:
cache_manager = HTML2PDF_CacheManager(
cache_manager = HTML2Print_CacheManager(
file_manager=FileManager(os_system_manager=OperationSystemManager()),
path_to_cache_dir=path_to_cache_dir,
)

http_client = HTML2PDF_HTTPClient()
http_client = HTML2Print_HTTPClient()
download_manager = WDMDownloadManager(http_client)
path_to_chrome = ChromeDriverManager(
download_manager=download_manager, cache_manager=cache_manager
Expand Down Expand Up @@ -239,7 +239,7 @@ def main():
# You can override this setting and save binaries to project.root/.wdm.
os.environ["WDM_LOCAL"] = "1"

parser = argparse.ArgumentParser(description="HTML2PDF printer script.")
parser = argparse.ArgumentParser(description="HTML2Print printer script.")

parser.add_argument(
"-v", "--version", action="version", version=__version__
Expand Down
15 changes: 9 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "hpdf/hpdf.py"
path = "html2print/html2print.py"

[tool.hatch.build]
include = [
"/hpdf/",
"/html2print/",
"LICENSE",
"README.md",
"pyproject.toml"
Expand All @@ -19,18 +19,21 @@ exclude = [
]

[project]
name = "hpdf"
name = "html2print"
dynamic = ["version"]
description = "Python client for HTML2PDF JavaScript library."
readme = "README.md"
license = "TBD"
# https://github.com/pypa/twine/issues/1216 license-files is broken as of 2025-02-03
# Using [] as a suggested workaround.
# license-files = [ "LICENSE" ]
license-files = []
requires-python = ">=3.8"
authors = [
{ name = "Stanislav Pankevich", email = "s.pankevich@gmail.com" },
{ name = "Maryna Balioura", email = "mettta@gmail.com" },
]
classifiers = [
"License :: OSI Approved :: BSD License",
# "License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
Expand Down Expand Up @@ -58,7 +61,7 @@ development = [
]

[project.scripts]
hpdf = "hpdf:main"
html2print = "html2print:main"

[project.urls]
Changelog = "https://github.com/mettta/html2pdf_python/releases/"
Expand Down
2 changes: 2 additions & 0 deletions requirements.development.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
invoke
toml
build
packaging
setuptools
twine

#
# Lint
Expand Down
66 changes: 60 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_chrome_driver(
run_invoke(
context,
"""
python hpdf/hpdf.py get_driver
python html2print/html2print.py get_driver
""",
)

Expand All @@ -97,7 +97,7 @@ def lint_ruff_format(context):
ruff
format
*.py
hpdf/
html2print/
tests/integration/
""",
)
Expand All @@ -113,7 +113,7 @@ def lint_ruff(context):
run_invoke(
context,
"""
ruff check *.py hpdf/ --fix --cache-dir build/ruff
ruff check *.py html2print/ --fix --cache-dir build/ruff
""",
)

Expand All @@ -126,7 +126,7 @@ def lint_mypy(context):
run_invoke(
context,
"""
mypy hpdf/
mypy html2print/
--show-error-codes
--disable-error-code=import
--disable-error-code=misc
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_integration(

cwd = os.getcwd()

html2pdf_exec = f'python3 \\"{cwd}/hpdf/hpdf.py\\"'
html2pdf_exec = f'python3 \\"{cwd}/html2print/html2print.py\\"'

focus_or_none = f"--filter {focus}" if focus else ""
debug_opts = "-vv --show-all" if debug else ""
Expand All @@ -167,7 +167,7 @@ def test_integration(
itest_command = f"""
lit
--threads 1
--param HTML2PDF_EXEC="{html2pdf_exec}"
--param HTML2PRINT_EXEC="{html2pdf_exec}"
-v
{debug_opts}
{focus_or_none}
Expand All @@ -191,3 +191,57 @@ def clean_itest_artifacts(context):
# The command sometimes exits with 1 even if the files are deleted.
# warn=True ensures that the execution continues.
run_invoke(context, find_command, warn=True)


@task
def release(context, test_pypi=False, username=None, password=None):
"""
A release can be made to PyPI or test package index (TestPyPI):
https://pypi.org/project/html2print/
https://test.pypi.org/project/html2print/
"""

# When a username is provided, we also need password, and then we don't use
# tokens set up on a local machine.
assert username is None or password is not None

repository_argument_or_none = (
""
if username
else (
"--repository html2print_test"
if test_pypi
else "--repository html2print_release"
)
)
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
run_invoke(
context,
f"""
twine upload dist/html2print-*.tar.gz
{repository_argument_or_none}
{user_password}
""",
)
4 changes: 2 additions & 2 deletions tests/integration/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import subprocess
import lit.formats


config.name = "HTML2PDF Python API integration tests"
config.name = "html2print Python API integration tests"
config.test_format = lit.formats.ShTest("0")

current_dir = os.getcwd()

html2pdf_exec = lit_config.params['HTML2PDF_EXEC']
html2pdf_exec = lit_config.params['HTML2PRINT_EXEC']
assert(html2pdf_exec)

config.substitutions.append(('%project_root', current_dir))
Expand Down