diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 9c89fe9e0..738a95d9c 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -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 @@ -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 @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ae3040ef..4da54ab3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,11 +17,6 @@ repos: exclude: "docs/make.bat" - id: check-added-large-files args: ['--maxkb=1000'] -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - args: ["--ignore", "E,W,F"] # - repo: https://github.com/pre-commit/mirrors-mypy # rev: v0.942 # hooks: @@ -43,8 +38,18 @@ repos: - id: blacken-docs additional_dependencies: [black==22.1.0] exclude: "docs/user/robustness.md" +- repo: https://github.com/charliermarsh/ruff-pre-commit + # Ruff version. + rev: 'v0.0.237' + hooks: + - id: ruff - repo: https://github.com/asottile/pyupgrade rev: v3.3.1 hooks: - id: pyupgrade args: [--py36-plus] +- repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + args: ["--ignore", "E,W,F"] diff --git a/pypdf/_cmap.py b/pypdf/_cmap.py index 1b2bae373..f74faa19d 100644 --- a/pypdf/_cmap.py +++ b/pypdf/_cmap.py @@ -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 = "" diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 965db269c..adc70e257 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -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)) diff --git a/pypdf/constants.py b/pypdf/constants.py index 0ac40d08a..9ecdf0e82 100644 --- a/pypdf/constants.py +++ b/pypdf/constants.py @@ -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