Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
code format cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Apr 12, 2021
1 parent a621da8 commit df10bb7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ jobs:
- run: python -V
- run: pip -V

- run: pip install -e .
- run: pip install -r requirements_dev.txt

- name: Lint
continue-on-error: true
# run: flake8 pdfx tests setup.py --exclude="pdfx/libs,pdfx/extractor.py"
run: flake8 pdfx tests setup.py
run: make lint

- name: Run the test suite
run: py.test --strict --capture=no tests
- name: Test
run: make test

- name: Checks
continue-on-error: true
run: make ceck
26 changes: 14 additions & 12 deletions pdfx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,26 @@
License: GPLv3
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from pdfminer.pdfparser import PDFSyntaxError
from .exceptions import FileNotFoundError, DownloadError, PDFInvalidError
from .downloader import download_urls
from .backends import PDFMinerBackend, TextBackend
from .extractor import extract_urls

__title__ = "pdfx"
__version__ = "1.3.1"
__author__ = "Chris Hager"
__license__ = "Apache 2.0"
__copyright__ = "Copyright 2015 Chris Hager"

import os
import sys
import json
import shutil
import logging

__title__ = "pdfx"
__version__ = "1.3.1"
__author__ = "Chris Hager"
__license__ = "Apache 2.0"
__copyright__ = "Copyright 2015 Chris Hager"

from .extractor import extract_urls
from .backends import PDFMinerBackend, TextBackend
from .downloader import download_urls
from .exceptions import FileNotFoundError, DownloadError, PDFInvalidError
from pdfminer.pdfparser import PDFSyntaxError


IS_PY2 = sys.version_info < (3, 0)

Expand All @@ -62,7 +65,6 @@

unicode = str


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -92,7 +94,7 @@ class PDFx(object):
reader = None # ReaderBackend
summary = {}

def __init__(self, uri): # noqa: C901
def __init__(self, uri):
"""
Open PDF handle and parse PDF metadata
- `uri` can bei either a filename or an url
Expand Down
22 changes: 11 additions & 11 deletions pdfx/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"""

from __future__ import absolute_import, division, print_function, unicode_literals
from pdfminer.layout import LAParams
from pdfminer.converter import TextConverter
from pdfminer.pdftypes import resolve1, PDFObjRef
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer import psparser

import sys
import logging
Expand All @@ -30,6 +22,14 @@
from pdfminer import settings as pdfminer_settings

pdfminer_settings.STRICT = False
from pdfminer import psparser # noqa: E402
from pdfminer.pdfdocument import PDFDocument # noqa: E402
from pdfminer.pdfparser import PDFParser # noqa: E402
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter # noqa: E402
from pdfminer.pdfpage import PDFPage # noqa: E402
from pdfminer.pdftypes import resolve1, PDFObjRef # noqa: E402
from pdfminer.converter import TextConverter # noqa: E402
from pdfminer.layout import LAParams # noqa: E402


logger = logging.getLogger(__name__)
Expand All @@ -41,7 +41,7 @@
unicode = str


def make_compat_str(in_str): # noqa: C901
def make_compat_str(in_str):
"""
Tries to guess encoding of [str/bytes] and
return a standard unicode string
Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self):
def get_metadata(self):
return self.metadata

def metadata_key_cleanup(self, d, k): # noqa: C901
def metadata_key_cleanup(self, d, k):
""" Recursively clean metadata dictionaries """
if isinstance(d[k], (str, unicode)):
d[k] = d[k].strip()
Expand Down Expand Up @@ -264,7 +264,7 @@ def __init__(self, pdf_stream, password="", pagenos=[], maxpages=0): # noqa: C9
for ref in extractor.extract_doi(self.text):
self.references.add(Reference(ref, self.curpage))

def resolve_PDFObjRef(self, obj_ref): # noqa: C901
def resolve_PDFObjRef(self, obj_ref):
"""
Resolves PDFObjRef objects. Returns either None, a Reference object or
a list of Reference objects.
Expand Down
4 changes: 2 additions & 2 deletions pdfx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def create_parser():
return parser


def get_text_output(pdf, args): # noqa: C901
def get_text_output(pdf, args):
""" Normal output of infos of PDFx instance """
# Metadata
ret = ""
Expand Down Expand Up @@ -145,7 +145,7 @@ def print_to_console(text):
sys.stdout.write("\n")


def main(): # noqa: C901
def main():
parser = create_parser()
args = parser.parse_args()

Expand Down
4 changes: 2 additions & 2 deletions pdfx/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_status_code(url):
return None


def check_refs(refs, verbose=True, max_threads=MAX_THREADS_DEFAULT): # noqa: C901
def check_refs(refs, verbose=True, max_threads=MAX_THREADS_DEFAULT):
""" Check if urls exist """
codes = defaultdict(list)

Expand Down Expand Up @@ -97,7 +97,7 @@ def check_url(ref):
print(o)


def download_urls( # noqa: C901
def download_urls(
urls, output_directory, verbose=True, max_threads=MAX_THREADS_DEFAULT
):
""" Download urls to a target directory """
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ universal = 1

[flake8]
max-line-length = 100
max-complexity = 5
max-complexity = 15

0 comments on commit df10bb7

Please sign in to comment.