Skip to content

Commit

Permalink
Check blackness in github actions (pdfminer#711)
Browse files Browse the repository at this point in the history
* Check blackness in github actions

* Blacken code

* Update github action names

* Add contributing guidelines on using black

* Add to checklist for PR
  • Loading branch information
pietermarsman authored Feb 11, 2022
1 parent 830acff commit b9a8920
Show file tree
Hide file tree
Showing 60 changed files with 12,844 additions and 7,443 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
17 changes: 6 additions & 11 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
**Pull request**

Thanks for improving pdfminer.six! Please include the following information to
help us discuss and merge this PR:

- A description of why this PR is needed. What does it fix? What does it
improve?
- A summary of the things that this PR changes.
- Reference the issues that this PR fixes (use the fixes #(issue nr) syntax).
If this PR does not fix any issue, create the issue first and mention that
you are willing to work on it.
Please remove this paragraph and replace it with a description of your PR.
Also include links to the issues that it fixes.

**How Has This Been Tested?**

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Include an example pdf if you have one.
Please repalce this paragraph with a description of how this PR has been
tested. Include the necessary instructions and files such that other can
reproduce it.

**Checklist**

- [ ] I have formatted my code with [black](https://github.com/psf/black).
- [ ] I have added tests that prove my fix is effective or that my feature
works
- [ ] I have added docstrings to newly created methods and classes
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ env:

jobs:

check-code-formatting:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check code formatting
uses: psf/black@stable

check-coding-style:
name: Check coding style
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Any contribution is appreciated! You might want to:
* 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 3.6+.
* Code should conform to PEP8 coding style.
* Code should be formatted with [black](https://github.com/psf/black).
* New features should be well documented using docstrings.
* Check spelling and grammar.
* Don't forget to update the [CHANGELOG.md](CHANGELOG.md#[Unreleased])
Expand Down Expand Up @@ -68,3 +68,9 @@ Any contribution is appreciated! You might want to:
```sh
nox -e py36
```

4. After changing the code, run the black formatter.

```sh
black .
```
23 changes: 11 additions & 12 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

import pdfminer

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 -----------------------------------------------------

project = 'pdfminer.six'
copyright = '2019, Yusuke Shinyama, Philippe Guglielmetti & Pieter Marsman'
author = 'Yusuke Shinyama, Philippe Guglielmetti & Pieter Marsman'
project = "pdfminer.six"
copyright = "2019, Yusuke Shinyama, Philippe Guglielmetti & Pieter Marsman"
author = "Yusuke Shinyama, Philippe Guglielmetti & Pieter Marsman"

# The full version, including alpha/beta/rc tags
release = pdfminer.__version__
Expand All @@ -35,16 +34,16 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinxarg.ext',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
"sphinxarg.ext",
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
]

# Root rst file
master_doc = 'index'
master_doc = "index"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -57,9 +56,9 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# 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"]
37 changes: 7 additions & 30 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,30 @@

@nox.session
def lint(session):
session.install('flake8')
session.run(
'flake8',
'pdfminer/',
'tools/',
'tests/',
'--count',
'--statistics'
)
session.install("flake8")
session.run("flake8", "pdfminer/", "tools/", "tests/", "--count", "--statistics")


@nox.session
def types(session):
session.install('mypy')
session.install("mypy")
session.run(
'mypy',
'--install-types',
'--non-interactive',
'--show-error-codes',
'.'
"mypy", "--install-types", "--non-interactive", "--show-error-codes", "."
)


@nox.session(python=PYTHON_ALL_VERSIONS)
def tests(session):
session.install("-e", ".[dev]")
session.run('pytest')
session.run("pytest")


@nox.session
def docs(session):
session.install("-e", ".[docs]")
session.run(
'python',
'-m',
'sphinx',
'-b',
'html',
'docs/source',
'docs/build/html'
"python", "-m", "sphinx", "-b", "html", "docs/source", "docs/build/html"
)
session.run(
'python',
'-m',
'sphinx',
'-b',
'doctest',
'docs/source',
'docs/build/doctest'
"python", "-m", "sphinx", "-b", "doctest", "docs/source", "docs/build/doctest"
)
4 changes: 2 additions & 2 deletions pdfminer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '20211012'
__version__ = "20211012"

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

"""An implementation of RFC4013 SASLprep."""

__all__ = ['saslprep']
__all__ = ["saslprep"]

import stringprep
from typing import Callable, Tuple
Expand All @@ -37,7 +37,8 @@
stringprep.in_table_c6,
stringprep.in_table_c7,
stringprep.in_table_c8,
stringprep.in_table_c9)
stringprep.in_table_c9,
)


def saslprep(data: str, prohibit_unassigned_code_points: bool = True) -> str:
Expand All @@ -63,12 +64,12 @@ def saslprep(data: str, prohibit_unassigned_code_points: bool = True) -> str:
in_table_c12 = stringprep.in_table_c12
in_table_b1 = stringprep.in_table_b1
data = "".join(
["\u0020" if in_table_c12(elt) else elt
for elt in data if not in_table_b1(elt)])
["\u0020" if in_table_c12(elt) else elt for elt in data if not in_table_b1(elt)]
)

# RFC3454 section 2, step 2 - Normalize
# RFC4013 section 2.2 normalization
data = unicodedata.ucd_3_2_0.normalize('NFKC', data)
data = unicodedata.ucd_3_2_0.normalize("NFKC", data)

in_table_d1 = stringprep.in_table_d1
if in_table_d1(data[0]):
Expand All @@ -89,7 +90,6 @@ def saslprep(data: str, prohibit_unassigned_code_points: bool = True) -> str:
# RFC3454 section 2, step 3 and 4 - Prohibit and check bidi
for char in data:
if any(in_table(char) for in_table in prohibited):
raise ValueError(
"SASLprep: failed prohibited character check")
raise ValueError("SASLprep: failed prohibited character check")

return data
9 changes: 4 additions & 5 deletions pdfminer/arcfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class Arcfour:

def __init__(self, key: Sequence[int]) -> None:
# because Py3 range is not indexable
s = [i for i in range(256)]
Expand All @@ -24,12 +23,12 @@ def __init__(self, key: Sequence[int]) -> None:
def process(self, data: bytes) -> bytes:
(i, j) = (self.i, self.j)
s = self.s
r = b''
r = b""
for c in iter(data):
i = (i+1) % 256
j = (j+s[i]) % 256
i = (i + 1) % 256
j = (j + s[i]) % 256
(s[i], s[j]) = (s[j], s[i])
k = s[(s[i]+s[j]) % 256]
k = s[(s[i] + s[j]) % 256]
r += bytes((c ^ k,))
(self.i, self.j) = (i, j)
return r
Expand Down
29 changes: 15 additions & 14 deletions pdfminer/ascii85.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ def ascii85decode(data: bytes) -> bytes:
"""
n = b = 0
out = b''
out = b""
for i in iter(data):
c = bytes((i,))
if b'!' <= c and c <= b'u':
if b"!" <= c and c <= b"u":
n += 1
b = b*85+(ord(c)-33)
b = b * 85 + (ord(c) - 33)
if n == 5:
out += struct.pack('>L', b)
out += struct.pack(">L", b)
n = b = 0
elif c == b'z':
elif c == b"z":
assert n == 0, str(n)
out += b'\0\0\0\0'
elif c == b'~':
out += b"\0\0\0\0"
elif c == b"~":
if n:
for _ in range(5-n):
b = b*85+84
out += struct.pack('>L', b)[:n-1]
for _ in range(5 - n):
b = b * 85 + 84
out += struct.pack(">L", b)[: n - 1]
break
return out


# asciihexdecode(data)
hex_re = re.compile(br'([a-f\d]{2})', re.IGNORECASE)
trail_re = re.compile(br'^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$', re.IGNORECASE)
hex_re = re.compile(rb"([a-f\d]{2})", re.IGNORECASE)
trail_re = re.compile(rb"^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$", re.IGNORECASE)


def asciihexdecode(data: bytes) -> bytes:
Expand All @@ -57,15 +57,16 @@ def asciihexdecode(data: bytes) -> bytes:
the EOD marker after reading an odd number of hexadecimal digits, it
will behave as if a 0 followed the last digit.
"""

def decode(x: bytes) -> bytes:
i = int(x, 16)
return bytes((i,))

out = b''
out = b""
for x in hex_re.findall(data):
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 b9a8920

Please sign in to comment.