Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update development tools: travis ci to github actions, tox to nox, nose to pytest #704

Merged
merged 19 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Continuous integration

on:
push:

env:
default-python: "3.10"

jobs:

check-coding-style:
name: Check coding style
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.default-python }}
- name: Upgrade pip, Install nox
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: Check coding style
run: |
nox --error-on-missing-interpreters --non-interactive --session lint

check-static-types:
name: Check static types
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.default-python }}
- name: Upgrade pip, Install nox
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: Check static types
run: |
nox --error-on-missing-interpreters --non-interactive --session types

tests:
name: Run tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Determine pip cache directory
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip${{ matrix.python-version }}
- name: Upgrade pip and install nox
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: Run tests
run: |
nox --non-interactive --session tests-${{ matrix.python-version }}

build-docs:
name: Test building docs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.default-python }}
- name: Upgrade pip and install nox
run: |
python -m pip install --upgrade pip
python -m pip install nox
- name: Build docs
run: |
nox --error-on-missing-interpreters --non-interactive --session docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tests/*.xml
tests/*.txt
.idea/
.tox/
.nox/

# python venv management tools
Pipfile
Expand Down
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
- Unnecessary return statements without argument at the end of functions ([#707](https://github.com/pdfminer/pdfminer.six/pull/707))

### Changed
- Switched from nose to pytest, from tox to nox and from Travis CI to GitHub Actions ([#704](https://github.com/pdfminer/pdfminer.six/pull/704))

## [20211012]

### Added
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ Any contribution is appreciated! You might want to:
On all Python versions:

```sh
tox
nox
```

Or on a single Python version:

```sh
tox -e py36
nox -e py36
```
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,3 @@ $(CMAPDST)/to-unicode-Adobe-Japan1.pickle.gz: $(CMAPDST)
$(CMAPDST)/to-unicode-Adobe-Korea1.pickle.gz: $(CMAPDST)
$(CONV_CMAP) -c KSC-EUC=euc-kr -c KSC-Johab=johab -c KSCms-UHC=cp949 -c UniKS-UTF8=utf-8 \
$(CMAPDST) Adobe-Korea1 $(CMAPSRC)/cid2code_Adobe_Korea1.txt

test: cmap
nosetests
5 changes: 4 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ disallow_untyped_defs = True
[mypy-cryptography.hazmat.*]
ignore_missing_imports = True

[mypy-nose.*]
[mypy-pytest.*]
ignore_missing_imports = True

[mypy-setuptools]
ignore_missing_imports = True

[mypy-nox]
ignore_missing_imports = True
58 changes: 58 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import nox


PYTHON_ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]


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


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


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


@nox.session
def docs(session):
session.install("-e", ".[docs]")
session.run(
'python',
'-m',
'sphinx',
'-b',
'html',
'docs/source',
'docs/build/html'
)
session.run(
'python',
'-m',
'sphinx',
'-b',
'doctest',
'docs/source',
'docs/build/doctest'
)
14 changes: 6 additions & 8 deletions pdfminer/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
from typing import Any, Dict, Iterable, List, Optional, Tuple
from typing import Any, Iterable, List, Optional, Tuple

from pdfminer import settings
from pdfminer.pdfparser import PDFSyntaxError
Expand All @@ -26,21 +25,20 @@ def __init__(self, obj: Any):
self.limits = list_value(self._obj['Limits'])

def _parse(self) -> List[Tuple[int, Any]]:
l = []
items = []
if self.nums: # Leaf node
for k, v in choplist(2, self.nums):
l.append((int_value(k), v))
items.append((int_value(k), v))

if self.kids: # Root or intermediate node
for child_ref in self.kids:
l += NumberTree(child_ref)._parse()
items += NumberTree(child_ref)._parse()

return l
return items

values: List[Tuple[int, Any]] # workaround decorators unsupported by mypy

@property # type: ignore [no-redef,misc]
@functools.lru_cache
@property # type: ignore[no-redef,misc]
def values(self) -> List[Tuple[int, Any]]:
values = self._parse()

Expand Down
5 changes: 3 additions & 2 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os.path
import struct
from io import BytesIO
from typing import BinaryIO, Tuple
from typing import BinaryIO, Tuple, List, Any

from .jbig2 import JBIG2StreamReader, JBIG2StreamWriter
from .layout import LTImage
Expand Down Expand Up @@ -104,6 +104,7 @@ def export_image(self, image: LTImage) -> str:
# seems to be easily opened by other programs
from PIL import Image
raw_data = image.stream.get_rawdata()
assert raw_data is not None
ifp = BytesIO(raw_data)
i = Image.open(ifp)
i.save(fp, 'JPEG2000')
Expand Down Expand Up @@ -162,7 +163,7 @@ def is_jbig2_image(image: LTImage) -> bool:
return is_jbig2

@staticmethod
def jbig2_global(image):
def jbig2_global(image: LTImage) -> List[Any]:
global_streams = []
filters = image.stream.get_filters()
for filter_name, params in filters:
Expand Down
10 changes: 7 additions & 3 deletions pdfminer/pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from .arcfour import Arcfour
from .data_structures import NumberTree
from .pdfparser import PDFSyntaxError, PDFParser, PDFStreamParser
from .pdftypes import DecipherCallable, PDFException, PDFTypeError, PDFStream, \
PDFObjectNotFound, decipher_all, int_value, str_value, list_value, \
uint_value, dict_value, stream_value
from .pdftypes import DecipherCallable, PDFException, PDFTypeError, \
PDFStream, PDFObjectNotFound, decipher_all, int_value, str_value, \
list_value, uint_value, dict_value, stream_value
from .psparser import PSEOF, literal_name, LIT, KWD
from .utils import choplist, decode_text, nunpack, format_int_roman, \
format_int_alpha
Expand Down Expand Up @@ -51,6 +51,10 @@ class PDFEncryptionError(PDFException):
pass


class PDFPasswordIncorrect(PDFEncryptionError):
pass


class PDFEncryptionWarning(UserWarning):
"""Legacy warning for failed decryption.

Expand Down
2 changes: 1 addition & 1 deletion pdfminer/pdftypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def stream_value(x: object) -> "PDFStream":
return x


def decompress_corrupted(data):
def decompress_corrupted(data: bytes) -> bytes:
"""Called on some data that can't be properly decoded because of CRC checksum
error. Attempt to decode it skipping the CRC.
"""
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys
from pathlib import Path

from setuptools import setup
from os import path

sys.path.append(str(Path(__file__).parent))
import pdfminer as package


Expand All @@ -17,7 +21,7 @@
'cryptography',
],
extras_require={
"dev": ["nose", "tox", "mypy == 0.910"],
"dev": ["pytest", "nox", "mypy == 0.931"],
"docs": ["sphinx", "sphinx-argparse"],
},
description='PDF parser and analyzer',
Expand Down
Loading