Skip to content

Commit

Permalink
DEV: Introduce ruff (#1586)
Browse files Browse the repository at this point in the history
Move code style to extra execution path. This way we can see more easily what the style issues are and what the pytest issues are (+ it might execute faster)
  • Loading branch information
MartinThoma authored Feb 5, 2023
1 parent 9bef0d3 commit 90476ef
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ jobs:
- name: Install pypdf
run: |
pip install .
- name: Test with flake8
run: |
flake8 .
- name: Test with pytest
run: |
python -m coverage run --parallel-mode -m pytest tests -vv
Expand All @@ -85,6 +82,39 @@ jobs:
path: .coverage.*
if-no-files-found: ignore

codestyle:
name: Check code style issues
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Cache Downloaded Files
id: cache-downloaded-files
uses: actions/cache@v3
with:
path: '**/tests/pdf_cache/*'
key: cache-downloaded-files
- name: Setup Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: 'pip'
cache-dependency-path: '**/requirements/ci-3.11.txt'
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
- name: Install requirements
run: |
pip install -r requirements/ci-3.11.txt
- name: Install pypdf
run: |
pip install .
- name: Test with flake8
run: |
flake8 .
package:
name: Build & verify package
runs-on: ubuntu-latest
Expand Down Expand Up @@ -140,7 +170,7 @@ jobs:
python -m coverage combine
python -m coverage xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ repos:
exclude: "docs/make.bat"
- id: check-added-large-files
args: ['--maxkb=1000']
- repo: https:/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--ignore", "E,W,F"]
# - repo: https:/pre-commit/mirrors-mypy
# rev: v0.942
# hooks:
Expand All @@ -43,8 +38,18 @@ repos:
- id: blacken-docs
additional_dependencies: [black==22.1.0]
exclude: "docs/user/robustness.md"
- repo: https:/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.237'
hooks:
- id: ruff
- repo: https:/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https:/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--ignore", "E,W,F"]
4 changes: 2 additions & 2 deletions pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def parse_bfrange(
return None if closure_found else (a, b)


def parse_bfchar(l: bytes, map_dict: Dict[Any, Any], int_entry: List[int]) -> None:
lst = [x for x in l.split(b" ") if x]
def parse_bfchar(line: bytes, map_dict: Dict[Any, Any], int_entry: List[int]) -> None:
lst = [x for x in line.split(b" ") if x]
map_dict[-1] = len(lst[0]) // 2
while len(lst) > 1:
map_to = ""
Expand Down
2 changes: 1 addition & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ def encrypt(
rev = 2
keylen = int(40 / 8)
P = permissions_flag
O = ByteStringObject(_alg33(owner_password, user_password, rev, keylen)) # type: ignore[arg-type]
O = ByteStringObject(_alg33(owner_password, user_password, rev, keylen)) # type: ignore[arg-type] # noqa
ID_1 = ByteStringObject(md5((repr(time.time())).encode("utf8")).digest())
ID_2 = ByteStringObject(md5((repr(random.random())).encode("utf8")).digest())
self._ID = ArrayObject((ID_1, ID_2))
Expand Down
2 changes: 1 addition & 1 deletion pypdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EncryptionDictAttributes:
"""

R = "/R" # number, required; revision of the standard security handler
O = "/O" # 32-byte string, required
O = "/O" # 32-byte string, required # noqa
U = "/U" # 32-byte string, required
P = "/P" # integer flag, required; permitted operations
ENCRYPT_METADATA = "/EncryptMetadata" # boolean flag, optional
Expand Down

0 comments on commit 90476ef

Please sign in to comment.