Skip to content

Commit 35ff112

Browse files
new wkthmltopdf, also uprev python in server (#22)
* new wkthmltopdf, also uprev python in server * uprev version * New wkhtmltopdf * Switch to GH Actions (#27) * Switch to GH Actions * Update test reqs * Install black * Remove travis * Add versioning script to publish to pypi Co-authored-by: tomhamiltonstubber <[email protected]>
1 parent 4af5aff commit 35ff112

File tree

14 files changed

+150
-113
lines changed

14 files changed

+150
-113
lines changed

.github/workflows/ci.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- '**'
9+
pull_request: {}
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: set up python
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: '3.9'
22+
23+
- name: install dependencies
24+
run: |
25+
sudo apt install libjpeg62 libc6
26+
make install
27+
pip freeze
28+
29+
- name: test
30+
run: |
31+
chmod +x /home/runner/work/pydf/pydf/pydf/bin/wkhtmltopdf
32+
make lint
33+
make test
34+
make benchmark
35+
python -c "import pydf; print(pydf.get_version())"
36+
37+
- name: codecov
38+
run: bash <(curl -s https://codecov.io/bash)
39+
40+
deploy:
41+
needs:
42+
- test
43+
if: "success() && startsWith(github.ref, 'refs/tags/')"
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- uses: actions/checkout@v2
48+
49+
- name: set up python
50+
uses: actions/setup-python@v1
51+
with:
52+
python-version: '3.9'
53+
54+
- name: install
55+
run: |
56+
pip install -U pip setuptools wheel twine
57+
pip install .
58+
- name: set version
59+
run: VERSION_PATH='pydf/version.py' python <(curl -Ls https://git.io/JT3rm)
60+
61+
- run: python setup.py sdist bdist_wheel
62+
63+
- run: twine check dist/*
64+
65+
- name: upload to pypi
66+
run: twine upload dist/*
67+
env:
68+
TWINE_USERNAME: __token__
69+
TWINE_PASSWORD: ${{ secrets.pypi_token }}

.travis.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM python:3.6
1+
FROM python:3.8
22

3-
RUN pip install aiohttp==2.1.0
3+
LABEL maintainer='[email protected]'
4+
5+
RUN pip install aiohttp==3.7.3
46
ADD ./pydf /pydf
57
ADD setup.py /
68
RUN pip install -e .
79

8-
LABEL maintainer '[email protected]'
9-
1010
ADD ./docker-entrypoint.py /
1111
ENTRYPOINT ["/docker-entrypoint.py"]

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
black = black -S -l 120 --target-version py38
2+
isort = isort -w 120
3+
14
.PHONY: install
25
install:
36
pip install -U setuptools pip
47
pip install -U .
58
pip install -r tests/requirements.txt
69

7-
.PHONY: isort
8-
isort:
9-
isort -rc -w 120 pydf
10-
isort -rc -w 120 tests
10+
.PHONY: format
11+
format:
12+
$(isort) pydf tests
13+
$(black) pydf tests
1114

1215
.PHONY: lint
1316
lint:
1417
python setup.py check -rms
15-
flake8 pydf/ tests/
16-
pytest pydf -p no:sugar -q
18+
flake8 pydf tests
19+
$(isort) --check-only pydf tests
20+
$(black) --check pydf tests
1721

1822
.PHONY: test
1923
test:

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,17 @@ wkhtmltopdf binary and passed to subprocess with not processing.
162162
:target: https://github.com/tutorcruncher/pydf
163163
.. |docker| image:: https://img.shields.io/docker/automated/samuelcolvin/pydf.svg
164164
:target: https://hub.docker.com/r/samuelcolvin/pydf/
165+
166+
167+
Heroku
168+
-------
169+
170+
If you are deploying onto Heroku, then you will need to install a couple of dependencies before WKHTMLTOPDF will work.
171+
172+
Add the Heroku buildpack `https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/apt.tgz`
173+
174+
Then create an `Aptfile` in your root directory with the dependencies:
175+
176+
.. code::shell
177+
libjpeg62
178+
libc6

docker-entrypoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.6
1+
#!/usr/bin/env python3.8
22
"""
33
pydf
44
@@ -55,7 +55,7 @@ async def generate(request):
5555
app = web.Application()
5656
app.router.add_get('/', index)
5757
app.router.add_route('*', '/generate.pdf', generate)
58-
app['apydf'] = AsyncPydf(loop=app.loop)
58+
app['apydf'] = AsyncPydf()
5959

6060
port = int(os.getenv('PORT', '80'))
6161
logger.info('starting pydf server on port %s', port)

pydf/bin/wkhtmltopdf

100755100644
8 Bytes
Binary file not shown.

pydf/version.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from distutils.version import StrictVersion
2-
3-
VERSION = StrictVersion('0.38.0')
1+
VERSION = '0.39.0'

pydf/wkhtmltopdf.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,39 @@ async def generate_pdf(self, html, **cmd_args):
6262
stdin=asyncio.subprocess.PIPE,
6363
stdout=asyncio.subprocess.PIPE,
6464
stderr=asyncio.subprocess.PIPE,
65-
loop=self.loop
65+
loop=self.loop,
6666
)
6767
p.stdin.write(html.encode())
6868
p.stdin.close()
6969
await p.wait()
7070
pdf_content = await p.stdout.read()
7171
if p.returncode != 0 and pdf_content[:4] != b'%PDF':
7272
stderr = await p.stderr.read()
73-
raise RuntimeError('error running wkhtmltopdf, command: {!r}\n'
74-
'response: "{}"'.format(cmd_args, stderr.decode().strip()))
73+
raise RuntimeError(
74+
'error running wkhtmltopdf, command: {!r}\n'
75+
'response: "{}"'.format(cmd_args, stderr.decode().strip())
76+
)
7577
return pdf_content
7678

7779

78-
def generate_pdf(html, *,
79-
cache_dir: Path=DFT_CACHE_DIR,
80-
grayscale: bool=False,
81-
lowquality: bool=False,
82-
margin_bottom: str=None,
83-
margin_left: str=None,
84-
margin_right: str=None,
85-
margin_top: str=None,
86-
orientation: str=None,
87-
page_height: str=None,
88-
page_width: str=None,
89-
page_size: str=None,
90-
image_dpi: str=None,
91-
image_quality: str=None,
92-
**extra_kwargs):
80+
def generate_pdf(
81+
html,
82+
*,
83+
cache_dir: Path = DFT_CACHE_DIR,
84+
grayscale: bool = False,
85+
lowquality: bool = False,
86+
margin_bottom: str = None,
87+
margin_left: str = None,
88+
margin_right: str = None,
89+
margin_top: str = None,
90+
orientation: str = None,
91+
page_height: str = None,
92+
page_width: str = None,
93+
page_size: str = None,
94+
image_dpi: str = None,
95+
image_quality: str = None,
96+
**extra_kwargs,
97+
):
9398
"""
9499
Generate a pdf from either a url or a html string.
95100
@@ -148,8 +153,9 @@ def generate_pdf(html, *,
148153
# it seems wkhtmltopdf's error codes can be false, we'll ignore them if we
149154
# seem to have generated a pdf
150155
if p.returncode != 0 and pdf_content[:4] != b'%PDF':
151-
raise RuntimeError('error running wkhtmltopdf, command: {!r}\n'
152-
'response: "{}"'.format(cmd_args, p.stderr.decode().strip()))
156+
raise RuntimeError(
157+
'error running wkhtmltopdf, command: {!r}\n' 'response: "{}"'.format(cmd_args, p.stderr.decode().strip())
158+
)
153159
return pdf_content
154160

155161

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[tool:pytest]
22
testpaths = tests
3-
addopts = --isort
43
timeout = 10
54

65
[flake8]
7-
max-complexity = 10
86
max-line-length = 120
7+
max-complexity = 12
8+
# required to work with black
9+
ignore = E203, W503, W504
910

1011
[bdist_wheel]
1112
python-tag = py36

0 commit comments

Comments
 (0)