Skip to content

Commit e77cd91

Browse files
authored
Merge pull request #169 from jschlyter/ruff_reformat
Reformat with ruff
2 parents f18448c + 69fed0a commit e77cd91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+244
-401
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: poetry install
4848
- name: Run pytest
4949
run: |
50-
poetry run pytest -vvv -ra --cov=cryptojwt --cov-report=xml --isort --black
50+
poetry run pytest -vvv -ra --cov=cryptojwt --cov-report=xml
5151
- name: Upload coverage to Codecov
5252
uses: codecov/codecov-action@v4
5353
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: check-yaml
1010
- id: check-json
1111
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: v0.4.9
12+
rev: v0.6.8
1313
hooks:
1414
- id: ruff
1515
- id: ruff-format

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
all:
2+
3+
test:
4+
poetry run pytest --ruff --ruff-format --cov
5+
6+
reformat:
7+
poetry run ruff check --select I --fix src tests
8+
poetry run ruff format src tests

pyproject.toml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
# PEP 518: https://www.python.org/dev/peps/pep-0518/
22

3-
[tool.black]
4-
line-length = 100
5-
6-
[tool.isort]
7-
force_single_line = true
8-
known_first_party = "cryptojwt"
9-
include_trailing_comma = true
10-
force_grid_wrap = 0
11-
use_parentheses = true
12-
line_length = 100
13-
14-
[tool.coverage.run]
15-
branch = true
16-
17-
[tool.coverage.report]
18-
exclude_lines = [
19-
"pragma: no cover",
20-
"raise NotImplementedError",
21-
]
22-
233
[tool.poetry]
244
name = "cryptojwt"
255
version = "1.9.2"
@@ -44,23 +24,31 @@ requests = "^2.25.1"
4424

4525
[tool.poetry.group.dev.dependencies]
4626
alabaster = "^0.7.12"
47-
black = "^24.4.2"
48-
isort = "^5.13.2"
4927
pytest = "^8.2.1"
50-
pytest-black = "^0.3.12"
51-
pytest-isort = "^4.0.0"
5228
pytest-cov = "^4.0.0"
5329
responses = "^0.13.0"
5430
sphinx = "^3.5.2"
5531
sphinx-autobuild = "^2021.3.14"
5632
coverage = "^7"
57-
ruff = "^0.4.6"
33+
ruff = "^0.6.3"
5834
pytest-ruff = "^0.3.2"
5935

6036
[build-system]
6137
requires = ["poetry-core>=1.0.0"]
6238
build-backend = "poetry.core.masonry.api"
6339

40+
[tool.coverage.run]
41+
branch = true
42+
43+
[tool.coverage.report]
44+
exclude_lines = [
45+
"pragma: no cover",
46+
"raise NotImplementedError",
47+
]
48+
49+
[tool.ruff]
50+
line-length = 100
51+
6452
[tool.ruff.lint]
6553
select = [
6654
# pycodestyle
@@ -78,3 +66,9 @@ select = [
7866
]
7967
ignore = ["E501", "I001", "SIM102"]
8068
exclude = ["examples/*"]
69+
70+
[tool.ruff.lint.isort]
71+
force-sort-within-sections = false
72+
combine-as-imports = true
73+
split-on-trailing-comma = false
74+
known-first-party = ["cryptojwt"]

src/cryptojwt/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from cryptojwt.key_jar import KeyJar
1212

1313
from .exception import BadSyntax
14-
from .utils import as_unicode
15-
from .utils import b64d
16-
from .utils import b64encode_item
17-
from .utils import split_token
14+
from .utils import as_unicode, b64d, b64encode_item, split_token
1815

1916
__version__ = version("cryptojwt")
2017

src/cryptojwt/jwe/aes.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
from struct import pack
33

44
from cryptography.hazmat.primitives import hmac
5-
from cryptography.hazmat.primitives.ciphers import Cipher
6-
from cryptography.hazmat.primitives.ciphers import algorithms
7-
from cryptography.hazmat.primitives.ciphers import modes
5+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
86
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
97
from cryptography.hazmat.primitives.padding import PKCS7
108

11-
from ..exception import MissingKey
12-
from ..exception import Unsupported
13-
from ..exception import VerificationError
9+
from ..exception import MissingKey, Unsupported, VerificationError
1410
from . import Encrypter
1511
from .exception import UnsupportedBitLength
1612
from .utils import get_keys_seclen_dgst

src/cryptojwt/jwe/fernet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import base64
22
import os
3-
from typing import Optional
4-
from typing import Union
3+
from typing import Optional, Union
54

65
from cryptography.fernet import Fernet
76
from cryptography.hazmat.primitives import hashes

src/cryptojwt/jwe/jwe.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from ..jwk.hmac import SYMKey
77
from ..jwk.jwk import key_from_jwk_dict
88
from ..jwx import JWx
9-
from .exception import DecryptionFailed
10-
from .exception import NoSuitableDecryptionKey
11-
from .exception import NoSuitableEncryptionKey
12-
from .exception import NotSupportedAlgorithm
13-
from .exception import WrongEncryptionAlgorithm
9+
from .exception import (
10+
DecryptionFailed,
11+
NoSuitableDecryptionKey,
12+
NoSuitableEncryptionKey,
13+
NotSupportedAlgorithm,
14+
WrongEncryptionAlgorithm,
15+
)
1416
from .jwe_ec import JWE_EC
1517
from .jwe_hmac import JWE_SYM
1618
from .jwe_rsa import JWE_RSA
@@ -171,10 +173,7 @@ def decrypt(self, token=None, keys=None, alg=None, cek=None):
171173
elif _alg.startswith("ECDH-ES"):
172174
decrypter = JWE_EC(**self._dict)
173175

174-
if isinstance(keys[0], AsymmetricKey):
175-
_key = keys[0].private_key()
176-
else:
177-
_key = keys[0].key
176+
_key = keys[0].private_key() if isinstance(keys[0], AsymmetricKey) else keys[0].key
178177

179178
cek = decrypter.dec_setup(_jwe, key=_key)
180179
else:

src/cryptojwt/jwe/jwe_ec.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
import struct
33

44
from cryptography.hazmat.primitives.asymmetric import ec
5-
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap
6-
from cryptography.hazmat.primitives.keywrap import aes_key_wrap
7-
8-
from ..jwk.ec import NIST2SEC
9-
from ..jwk.ec import ECKey
10-
from ..utils import as_bytes
11-
from ..utils import as_unicode
12-
from ..utils import b64d
13-
from ..utils import b64e
5+
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap, aes_key_wrap
6+
7+
from ..jwk.ec import NIST2SEC, ECKey
8+
from ..utils import as_bytes, as_unicode, b64d, b64e
149
from . import KEY_LEN
1510
from .jwekey import JWEKey
1611
from .jwenc import JWEnc
17-
from .utils import concat_sha256
18-
from .utils import get_random_bytes
12+
from .utils import concat_sha256, get_random_bytes
1913

2014

2115
def ecdh_derive_key(key, epk, apu, apv, alg, dk_len):

src/cryptojwt/jwe/jwe_hmac.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import logging
33
import zlib
44

5-
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap
6-
from cryptography.hazmat.primitives.keywrap import aes_key_wrap
5+
from cryptography.hazmat.primitives.keywrap import aes_key_unwrap, aes_key_wrap
76

8-
from ..exception import MissingKey
9-
from ..exception import WrongNumberOfParts
7+
from ..exception import MissingKey, WrongNumberOfParts
108
from ..jwk.hmac import SYMKey
11-
from ..utils import as_bytes
12-
from ..utils import intarr2str
9+
from ..utils import as_bytes, intarr2str
1310
from .jwekey import JWEKey
1411
from .jwenc import JWEnc
1512

0 commit comments

Comments
 (0)