Skip to content

Commit

Permalink
Enforce pep8 coding-style (#345)
Browse files Browse the repository at this point in the history
* Code Refractor: Use code-style enforcement #312

* Add flake8 to travis-ci

* Remove python 2 3 comment on six library. 891 errors > 870 errors.

* Remove class and functions comments that consist of just the name. 870 errors > 855 errors.

* Fix flake8 errors in pdftypes.py. 855 errors > 833 errors.

* Moving flake8 testing from .travis.yml to tox.ini to ensure local testing before commiting

* Cleanup pdfinterp.py and add documentation from PDF Reference

* Cleanup pdfpage.py

* Cleanup pdffont.py

* Clean psparser.py

* Cleanup high_level.py

* Cleanup layout.py

* Cleanup pdfparser.py

* Cleanup pdfcolor.py

* Cleanup rijndael.py

* Cleanup converter.py

* Rename klass to cls if it is the class variable, to be more consistent with standard practice

* Cleanup cmap.py

* Cleanup pdfdevice.py

* flake8 ignore fontmetrics.py

* Cleanup test_pdfminer_psparser.py

* Fix flake8 in pdfdocument.py; 339 errors to go

* Fix flake8 utils.py; 326 errors togo

* pep8 correction for few files in /tools/ 328 > 160 to go (#342)

* pep8 correction for few files in /tools/ 328 > 160 to go

* pep8 correction: 160 > 5 to go

* Fix ascii85.py errors

* Fix error in getting index from target that does not exists

* Remove commented print lines

* Fix flake8 error in pdfinterp.py

* Fix python2 specific error by removing argument from print statement

* Ignore invalid python2 syntax

* Update contributing.md

* Added changelog

* Remove unused import

Co-authored-by: Fakabbir Amin <[email protected]>
  • Loading branch information
pietermarsman and fakabbir authored Dec 29, 2019
1 parent 78f0622 commit f3ab1bc
Show file tree
Hide file tree
Showing 49 changed files with 1,396 additions and 1,053 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ python:
- "3.7"
- "3.8"
install:
- pip install tox-travis
- pip install tox-travis flake8
script:
- tox -r
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Changed
- Enforce pep8 coding style by adding flake8 to CI ([#345](https://github.com/pdfminer/pdfminer.six/pull/345))

## [20191110] - 2019-11-10

### Fixed
Expand Down
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Any contribution is appreciated! You might want to:
- If you report a bug in the results for a particular pdf, include that pdf. This allows others to replicate the
issue.
* Fix issues by [creating pull requests](https://help.github.com/en/articles/creating-a-pull-request).
* Help others by giving your thoughts on open issues and pull requests.
* Help others by sharing your thoughs in comments on issues and pull requests.

## Guidelines for creating issues

Expand All @@ -29,11 +29,15 @@ Any contribution is appreciated! You might want to:
* Pull requests should be merged to develop, not master. This ensures that master always equals the released version.
* Include unit tests when possible. In case of bugs, this will help to prevent the same mistake in the future. In case
of features, this will show that your code works correctly.
* Code should work for Python 2.7 and Python 3.x (for now), conform to PEP8 code style (with a line-width of 120)
and properly documented with docstrings.
* Code should work for Python 2.7 and Python 3.x (for now), conform to PEP8 code style (enforced by
[flake8](http://flake8.pycqa.org/en/latest/)) and properly documented with docstrings.
* Check spelling and grammar.
* Don't forget to update the [CHANGELOG.md](CHANGELOG.md#[Unreleased])

## Guidelines for posting comments

* [Be cordial and positive](https://www.kennethreitz.org/essays/be-cordial-or-be-on-your-way)

## Getting started

1. Clone the repository
Expand Down
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import os
import sys
sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)), '../../'))
sys.path.insert(0, os.path.join(
os.path.abspath(os.path.dirname(__file__)), '../../'))


# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -58,4 +59,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
7 changes: 5 additions & 2 deletions pdfminer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@


if sys.version_info < (3, 0):
warnings.warn('On January 1st, 2020, pdfminer.six will stop supporting Python 2. Please upgrade to Python 3. For '
'more information see https://github.com/pdfminer/pdfminer.six/issues/194')
warnings.warn('On January 1st, 2020, '
'pdfminer.six will stop supporting Python 2. '
'Please upgrade to Python 3. '
'For more information see '
'https://github.com/pdfminer/pdfminer.six/issues/194')

if __name__ == '__main__':
print(__version__)
14 changes: 8 additions & 6 deletions pdfminer/arcfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
"""

import six # Python 2+3 compatibility
## Arcfour
##
import six # Python 2+3 compatibility


class Arcfour(object):

def __init__(self, key):
s = [i for i in range(256)] #because Py3 range is not indexable
# because Py3 range is not indexable
s = [i for i in range(256)]
j = 0
klen = len(key)
for i in range(256):
j = (j + s[i] + six.indexbytes(key,i % klen)) % 256
j = (j + s[i] + six.indexbytes(key, i % klen)) % 256
(s[i], s[j]) = (s[j], s[i])
self.s = s
(self.i, self.j) = (0, 0)
Expand All @@ -34,7 +35,8 @@ def process(self, data):
r += six.int2byte(c ^ k)
(self.i, self.j) = (i, j)
return r

encrypt = decrypt = process


new = Arcfour
18 changes: 10 additions & 8 deletions pdfminer/ascii85.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
import struct

import six #Python 2+3 compatibility
import six # Python 2+3 compatibility


# ascii85decode(data)
Expand All @@ -27,7 +27,7 @@ def ascii85decode(data):
n = b = 0
out = b''
for i in six.iterbytes(data):
c=six.int2byte(i)
c = six.int2byte(i)
if b'!' <= c and c <= b'u':
n += 1
b = b*85+(ord(c)-33)
Expand All @@ -45,9 +45,11 @@ def ascii85decode(data):
break
return out


# asciihexdecode(data)
hex_re = re.compile(b'([a-f\d]{2})', re.IGNORECASE)
trail_re = re.compile(b'^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$', re.IGNORECASE)
hex_re = re.compile(b'([a-f0-9]{2})', re.IGNORECASE)
trail_re = re.compile(b'^(?:[a-f0-9]{2}|[ \t\n\r\f\v])*'
b'([a-f0-9])[ \t\n\r\f\v>]*$', re.IGNORECASE)


def asciihexdecode(data):
Expand All @@ -61,14 +63,14 @@ def asciihexdecode(data):
will behave as if a 0 followed the last digit.
"""
def decode(x):
i=int(x,16)
i = int(x, 16)
return six.int2byte(i)

out=b''
out = b''
for x in hex_re.findall(data):
out+=decode(x)
out += decode(x)

m = trail_re.search(data)
if m:
out+=decode(m.group(1)+b'0')
out += decode(m.group(1)+b'0')
return out
Loading

0 comments on commit f3ab1bc

Please sign in to comment.