Skip to content

Commit 077ceb2

Browse files
committed
cleanup and move to python 3.5+
1 parent a74046d commit 077ceb2

File tree

14 files changed

+190
-140
lines changed

14 files changed

+190
-140
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ dist/
99
.idea
1010
build
1111
env
12+
.coverage
13+
.cache/

.travis.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ language: python
22
sudo: false
33

44
python:
5-
- '2.7'
6-
- '3.4'
75
- '3.5'
8-
- '3.6-dev'
6+
- '3.6'
97
- 'nightly'
108

119
matrix:
1210
allow_failures:
1311
- python: 'nightly'
1412

1513
install:
16-
- pip install coverage flake8 Pygments docutils
14+
- make install
15+
- pip freeze
1716

1817
script:
19-
- coverage run --source=pydf setup.py test
20-
- flake8 pydf/
21-
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then python setup.py check -rms; fi
22-
- python setup.py install
23-
- tests/check_file_permissions.py
18+
- make lint
19+
- make test
20+
- make benchmark
21+
- ./tests/check_tag.py
2422
- python -c "import pydf; print(pydf.get_version())"
2523

2624
after_success:
@@ -35,4 +33,4 @@ deploy:
3533
distributions: sdist bdist_wheel
3634
on:
3735
tags: true
38-
python: 3.5
36+
python: 3.6

HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. :changelog:
2+
3+
History
4+
-------
5+
6+
v0.31.0 (2017-05-23)
7+
....................
8+
* move to python 3.5 +

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.PHONY: install
2+
install:
3+
pip install -U setuptools pip
4+
pip install -U .
5+
pip install -r tests/requirements.txt
6+
7+
.PHONY: isort
8+
isort:
9+
isort -rc -w 120 pydf
10+
isort -rc -w 120 tests
11+
12+
.PHONY: lint
13+
lint:
14+
python setup.py check -rms
15+
flake8 pydf/ tests/
16+
pytest pydf -p no:sugar -q
17+
18+
.PHONY: test
19+
test:
20+
pytest --cov=pydf
21+
22+
.PHONY: testcov
23+
testcov:
24+
pytest --cov=pydf && (echo "building coverage html"; coverage html)
25+
26+
.PHONY: all
27+
all: testcov lint
28+
29+
.PHONY: clean
30+
clean:
31+
rm -rf `find . -name __pycache__`
32+
rm -f `find . -type f -name '*.py[co]' `
33+
rm -f `find . -type f -name '*~' `
34+
rm -f `find . -type f -name '.*~' `
35+
rm -rf .cache
36+
rm -rf htmlcov
37+
rm -rf *.egg-info
38+
rm -f .coverage
39+
rm -f .coverage.*
40+
rm -rf build
41+
python setup.py clean

pydf/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from distutils.version import StrictVersion
22

3-
VERSION = StrictVersion('0.30.0')
3+
VERSION = StrictVersion('0.31.0')

pydf/wkhtmltopdf.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import os
21
import subprocess
2+
from pathlib import Path
33
from tempfile import NamedTemporaryFile
4+
45
from .version import VERSION
56

7+
THIS_DIR = Path(__file__).parent.resolve()
8+
WK_PATH = THIS_DIR / 'bin' / 'wkhtmltopdf'
9+
610

711
def execute_wk(*args):
812
"""
@@ -11,14 +15,7 @@ def execute_wk(*args):
1115
:param args: args to pass straight to subprocess.Popen
1216
:return: stdout, stderr
1317
"""
14-
this_dir = os.path.dirname(__file__)
15-
wk_name = 'wkhtmltopdf'
16-
wkhtmltopdf_default = os.path.join(this_dir, 'bin', wk_name)
17-
# Reference command
18-
wkhtmltopdf_cmd = os.environ.get('WKHTMLTOPDF_CMD', wkhtmltopdf_default)
19-
if not os.path.isfile(wkhtmltopdf_cmd):
20-
raise IOError('wkhtmltopdf binary not found at %s' % wkhtmltopdf_cmd)
21-
wk_args = (wkhtmltopdf_cmd,) + args
18+
wk_args = (str(WK_PATH),) + args
2219
p = subprocess.Popen(wk_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2320
stdout, stderr = p.communicate()
2421
return stdout, stderr, p.returncode
@@ -100,22 +97,23 @@ def generate_pdf(source,
10097
cmd_args.extend([arg_name, str(value)])
10198

10299
def gen_pdf(src, cmd_args):
103-
with NamedTemporaryFile(suffix='.pdf', mode='rb+') as pdf_file:
100+
with NamedTemporaryFile(suffix='.pdf', mode='rb') as pdf_file:
104101
cmd_args += [src, pdf_file.name]
105102
_, stderr, returncode = execute_wk(*cmd_args)
106103
pdf_file.seek(0)
107104
pdf_string = pdf_file.read()
108105
# it seems wkhtmltopdf's error codes can be false, we'll ignore them if we
109106
# seem to have generated a pdf
110-
if returncode != 0 and pdf_string[:4] != '%PDF':
111-
raise IOError('error running wkhtmltopdf, command: %r\nresponse: "%s"' % (cmd_args, stderr.strip()))
107+
if returncode != 0 and pdf_string[:4] != b'%PDF':
108+
raise RuntimeError('error running wkhtmltopdf, command: {!r}\n'
109+
'response: "{}"'.format(cmd_args, stderr.strip()))
112110
return pdf_string
113111

114112
if is_url:
115113
return gen_pdf(source, cmd_args)
116114

117115
with NamedTemporaryFile(suffix='.html', mode='wb') as html_file:
118-
html_file.write(source.encode('utf8'))
116+
html_file.write(source.encode())
119117
html_file.flush()
120118
html_file.seek(0)
121119
return gen_pdf(html_file.name, cmd_args)

setup.cfg

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
[bdist_wheel]
2-
universal = 1
1+
[tool:pytest]
2+
testpaths = tests
3+
addopts = --isort
4+
timeout = 10
35

46
[flake8]
57
max-complexity = 10
68
max-line-length = 120
9+
10+
[bdist_wheel]
11+
python-tag = py36
12+
13+
[coverage:run]
14+
source = pdf
15+
branch = True
16+
17+
[coverage:report]
18+
precision = 2
19+
exclude_lines =
20+
pragma: no cover
21+
raise NotImplementedError

setup.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
2+
from pathlib import Path
3+
24
from setuptools import setup
35
from setuptools.command.install import install
46
from pydf.version import VERSION
57

68
description = 'PDF generation in python using wkhtmltopdf suitable for heroku'
7-
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
8-
with open(os.path.join(THIS_DIR, 'README.rst')) as f:
9-
long_description = f.read()
9+
THIS_DIR = Path(__file__).resolve().parent
10+
long_description = THIS_DIR.joinpath('README.rst').read_text()
1011

1112

1213
class OverrideInstall(install):
@@ -25,7 +26,7 @@ def run(self):
2526
long_description=long_description,
2627
author='Samuel Colvin',
2728
license='MIT',
28-
author_email='S@muelColvin.com',
29+
author_email='s@muelcolvin.com',
2930
url='https://github.com/tutorcruncher/pydf',
3031
packages=['pydf'],
3132
platforms='any',
@@ -36,13 +37,10 @@ def run(self):
3637
'Intended Audience :: Developers',
3738
'License :: OSI Approved :: MIT License',
3839
'Programming Language :: Python',
39-
'Programming Language :: Python :: 2',
40-
'Programming Language :: Python :: 2.7',
4140
'Programming Language :: Python :: 3',
42-
'Programming Language :: Python :: 3.4',
4341
'Programming Language :: Python :: 3.5',
42+
'Programming Language :: Python :: 3.6',
4443
'Topic :: Internet :: WWW/HTTP',
4544
],
46-
test_suite='tests',
4745
zip_safe=False
4846
)

tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from .runtests import *

tests/check_file_permissions.py

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

0 commit comments

Comments
 (0)