Skip to content

Commit 4bb2ab2

Browse files
authored
tasks: add release task for publishing Pip (#11)
1 parent 2a9906e commit 4bb2ab2

File tree

10 files changed

+92
-31
lines changed

10 files changed

+92
-31
lines changed

.github/workflows/ci-linux-ubuntu-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Install HPDF dependencies.
4040
run: |
41-
python developer/pip_install_hpdf_deps.py
41+
python developer/pip_install_html2print_deps.py
4242
4343
- name: Run Lint tasks
4444
run: |

.github/workflows/ci-mac.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
3737
- name: Install HPDF dependencies.
3838
run: |
39-
python developer/pip_install_hpdf_deps.py
39+
python developer/pip_install_html2print_deps.py
4040
4141
- name: Run Lint tasks
4242
run: |

.github/workflows/ci-windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
5757
- name: Install HPDF dependencies.
5858
run: |
59-
python developer/pip_install_hpdf_deps.py
59+
python developer/pip_install_html2print_deps.py
6060
6161
- name: Run Lint tasks
6262
run: |
@@ -68,7 +68,7 @@ jobs:
6868
6969
- name: Download ChromeDriver
7070
run: |
71-
python hpdf/hpdf.py get_driver
71+
python html2print/html2print.py get_driver
7272
7373
- name: Run tests (Bash)
7474
run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.idea/
22
**/.wdm/
3+
build/
4+
dist/
35
tests/integration/.lit_test_times.txt
46
tests/integration/**/Output/
57

developer/pip_install_hpdf_deps.py renamed to developer/pip_install_html2print_deps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def check_if_package_installed(package_name: str):
2929

3030

3131
print( # noqa: T201
32-
"pip_install_hpdf_deps.py: "
32+
"pip_install_html2print_deps.py: "
3333
"checking if the current Python environment has all packages installed"
3434
".",
3535
flush=True,
@@ -48,7 +48,7 @@ def check_if_package_installed(package_name: str):
4848
check_if_package_installed(dependency)
4949
except PackageNotFound:
5050
print( # noqa: T201
51-
f"pip_install_hpdf_deps.py: "
51+
f"pip_install_html2print_deps.py: "
5252
f"Package is not installed: '{dependency}'.",
5353
flush=True,
5454
)
@@ -57,8 +57,8 @@ def check_if_package_installed(package_name: str):
5757
except PackageVersionConflict as exception_:
5858
print( # noqa: T201
5959
(
60-
f"pip_install_hpdf_deps.py: version conflict between "
61-
f"hpdf's requirement '{dependency}' "
60+
f"pip_install_html2print_deps.py: version conflict between "
61+
f"html2print's requirement '{dependency}' "
6262
f"and the already installed package: "
6363
f"{exception_.args[0]}."
6464
),
@@ -69,13 +69,13 @@ def check_if_package_installed(package_name: str):
6969

7070
if not needs_installation:
7171
print( # noqa: T201
72-
"pip_install_hpdf_deps.py: all packages seem to be installed.",
72+
"pip_install_html2print_deps.py: all packages seem to be installed.",
7373
flush=True,
7474
)
7575
sys.exit(0)
7676

7777
print( # noqa: T201
78-
"pip_install_hpdf_deps.py: will install packages.", flush=True
78+
"pip_install_html2print_deps.py: will install packages.", flush=True
7979
)
8080

8181
all_packages = "\n".join(dependencies) + "\n"

hpdf/hpdf.py renamed to html2print/html2print.py

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

26-
__version__ = "0.0.1"
26+
__version__ = "0.0.2"
2727

28-
DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".hpdf", "chromedriver")
28+
DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".html2print", "chromedriver")
2929

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

3737

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

6060

61-
class HTML2PDF_CacheManager(DriverCacheManager):
61+
class HTML2Print_CacheManager(DriverCacheManager):
6262
def __init__(self, file_manager: FileManager, path_to_cache_dir: str):
6363
super().__init__(file_manager=file_manager)
6464
self.path_to_cache_dir: str = path_to_cache_dir
@@ -187,12 +187,12 @@ class Done(Exception):
187187

188188

189189
def get_chrome_driver(path_to_cache_dir: str) -> str:
190-
cache_manager = HTML2PDF_CacheManager(
190+
cache_manager = HTML2Print_CacheManager(
191191
file_manager=FileManager(os_system_manager=OperationSystemManager()),
192192
path_to_cache_dir=path_to_cache_dir,
193193
)
194194

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

242-
parser = argparse.ArgumentParser(description="HTML2PDF printer script.")
242+
parser = argparse.ArgumentParser(description="HTML2Print printer script.")
243243

244244
parser.add_argument(
245245
"-v", "--version", action="version", version=__version__

pyproject.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
[tool.hatch.version]
6-
path = "hpdf/hpdf.py"
6+
path = "html2print/html2print.py"
77

88
[tool.hatch.build]
99
include = [
10-
"/hpdf/",
10+
"/html2print/",
1111
"LICENSE",
1212
"README.md",
1313
"pyproject.toml"
@@ -19,18 +19,21 @@ exclude = [
1919
]
2020

2121
[project]
22-
name = "hpdf"
22+
name = "html2print"
2323
dynamic = ["version"]
2424
description = "Python client for HTML2PDF JavaScript library."
2525
readme = "README.md"
26-
license = "TBD"
26+
# https://github.com/pypa/twine/issues/1216 license-files is broken as of 2025-02-03
27+
# Using [] as a suggested workaround.
28+
# license-files = [ "LICENSE" ]
29+
license-files = []
2730
requires-python = ">=3.8"
2831
authors = [
2932
{ name = "Stanislav Pankevich", email = "s.pankevich@gmail.com" },
3033
{ name = "Maryna Balioura", email = "mettta@gmail.com" },
3134
]
3235
classifiers = [
33-
"License :: OSI Approved :: BSD License",
36+
# "License :: OSI Approved :: BSD License",
3437
"Operating System :: OS Independent",
3538
"Programming Language :: Python :: 3",
3639
"Programming Language :: Python :: 3.8",
@@ -58,7 +61,7 @@ development = [
5861
]
5962

6063
[project.scripts]
61-
hpdf = "hpdf:main"
64+
html2print = "html2print:main"
6265

6366
[project.urls]
6467
Changelog = "https://github.com/mettta/html2pdf_python/releases/"

requirements.development.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
invoke
22
toml
3+
build
34
packaging
45
setuptools
6+
twine
57

68
#
79
# Lint

tasks.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_chrome_driver(
8484
run_invoke(
8585
context,
8686
"""
87-
python hpdf/hpdf.py get_driver
87+
python html2print/html2print.py get_driver
8888
""",
8989
)
9090

@@ -97,7 +97,7 @@ def lint_ruff_format(context):
9797
ruff
9898
format
9999
*.py
100-
hpdf/
100+
html2print/
101101
tests/integration/
102102
""",
103103
)
@@ -113,7 +113,7 @@ def lint_ruff(context):
113113
run_invoke(
114114
context,
115115
"""
116-
ruff check *.py hpdf/ --fix --cache-dir build/ruff
116+
ruff check *.py html2print/ --fix --cache-dir build/ruff
117117
""",
118118
)
119119

@@ -126,7 +126,7 @@ def lint_mypy(context):
126126
run_invoke(
127127
context,
128128
"""
129-
mypy hpdf/
129+
mypy html2print/
130130
--show-error-codes
131131
--disable-error-code=import
132132
--disable-error-code=misc
@@ -156,7 +156,7 @@ def test_integration(
156156

157157
cwd = os.getcwd()
158158

159-
html2pdf_exec = f'python3 \\"{cwd}/hpdf/hpdf.py\\"'
159+
html2pdf_exec = f'python3 \\"{cwd}/html2print/html2print.py\\"'
160160

161161
focus_or_none = f"--filter {focus}" if focus else ""
162162
debug_opts = "-vv --show-all" if debug else ""
@@ -167,7 +167,7 @@ def test_integration(
167167
itest_command = f"""
168168
lit
169169
--threads 1
170-
--param HTML2PDF_EXEC="{html2pdf_exec}"
170+
--param HTML2PRINT_EXEC="{html2pdf_exec}"
171171
-v
172172
{debug_opts}
173173
{focus_or_none}
@@ -191,3 +191,57 @@ def clean_itest_artifacts(context):
191191
# The command sometimes exits with 1 even if the files are deleted.
192192
# warn=True ensures that the execution continues.
193193
run_invoke(context, find_command, warn=True)
194+
195+
196+
@task
197+
def release(context, test_pypi=False, username=None, password=None):
198+
"""
199+
A release can be made to PyPI or test package index (TestPyPI):
200+
https://pypi.org/project/html2print/
201+
https://test.pypi.org/project/html2print/
202+
"""
203+
204+
# When a username is provided, we also need password, and then we don't use
205+
# tokens set up on a local machine.
206+
assert username is None or password is not None
207+
208+
repository_argument_or_none = (
209+
""
210+
if username
211+
else (
212+
"--repository html2print_test"
213+
if test_pypi
214+
else "--repository html2print_release"
215+
)
216+
)
217+
user_password = f"-u{username} -p{password}" if username is not None else ""
218+
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+
)
237+
# The token is in a core developer's .pypirc file.
238+
# https://test.pypi.org/manage/account/token/
239+
# https://packaging.python.org/en/latest/specifications/pypirc/#pypirc
240+
run_invoke(
241+
context,
242+
f"""
243+
twine upload dist/html2print-*.tar.gz
244+
{repository_argument_or_none}
245+
{user_password}
246+
""",
247+
)

tests/integration/lit.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import subprocess
44
import lit.formats
55

66

7-
config.name = "HTML2PDF Python API integration tests"
7+
config.name = "html2print Python API integration tests"
88
config.test_format = lit.formats.ShTest("0")
99

1010
current_dir = os.getcwd()
1111

12-
html2pdf_exec = lit_config.params['HTML2PDF_EXEC']
12+
html2pdf_exec = lit_config.params['HTML2PRINT_EXEC']
1313
assert(html2pdf_exec)
1414

1515
config.substitutions.append(('%project_root', current_dir))

0 commit comments

Comments
 (0)