Browse Source

Switch to Ruff

anonswap
Ofek Lev 2 years ago
parent
commit
0121668d05
  1. 2
      _cffi_build/build.py
  2. 3
      coincurve/context.py
  3. 6
      coincurve/ecdsa.py
  4. 4
      coincurve/keys.py
  5. 4
      coincurve/utils.py
  6. 43
      pyproject.toml
  7. 10
      tox.ini

2
_cffi_build/build.py

@ -13,7 +13,7 @@ def _mk_ffi(sources, name='_libsecp256k1', **kwargs):
code = []
for source in sources:
with open(os.path.join(here, source.h), 'rt') as h:
with open(os.path.join(here, source.h)) as h:
_ffi.cdef(h.read())
code.append(source.include)

3
coincurve/context.py

@ -24,7 +24,8 @@ class Context:
with self._lock:
seed = urandom(32) if not seed or len(seed) != 32 else seed
res = lib.secp256k1_context_randomize(self.ctx, ffi.new('unsigned char [32]', seed))
assert res == 1
if not res:
raise ValueError('secp256k1_context_randomize')
def __repr__(self):
return self.name or super().__repr__()

6
coincurve/ecdsa.py

@ -76,7 +76,8 @@ def serialize_compact(raw_sig, context: Context = GLOBAL_CONTEXT): # no cov
output = ffi.new('unsigned char[%d]' % CDATA_SIG_LENGTH)
res = lib.secp256k1_ecdsa_signature_serialize_compact(context.ctx, output, raw_sig)
assert res == 1
if not res:
raise ValueError('secp256k1_ecdsa_signature_serialize_compact')
return bytes(ffi.buffer(output, CDATA_SIG_LENGTH))
@ -87,7 +88,8 @@ def deserialize_compact(ser_sig: bytes, context: Context = GLOBAL_CONTEXT): # n
raw_sig = ffi.new('secp256k1_ecdsa_signature *')
res = lib.secp256k1_ecdsa_signature_parse_compact(context.ctx, raw_sig, ser_sig)
assert res == 1
if not res:
raise ValueError('secp256k1_ecdsa_signature_parse_compact')
return raw_sig

4
coincurve/keys.py

@ -407,7 +407,7 @@ class PublicKey:
return PublicKey(public_key, context)
def format(self, compressed: bool = True) -> bytes:
def format(self, compressed: bool = True) -> bytes: # noqa: A003
"""
Format the public key.
@ -579,7 +579,7 @@ class PublicKeyXOnly:
return cls(xonly_pubkey, parity=not not pk_parity[0], context=context)
def format(self) -> bytes:
def format(self) -> bytes: # noqa: A003
"""Serialize the public key.
:return: The public key serialized as 32 bytes.

4
coincurve/utils.py

@ -27,11 +27,11 @@ if environ.get('COINCURVE_BUILDING_DOCS') != 'true':
else: # no cov
class __Nonce(tuple):
class __Nonce(tuple): # noqa: N801
def __repr__(self):
return '(ffi.NULL, ffi.NULL)'
class __HasherSHA256:
class __HasherSHA256: # noqa: N801
def __call__(self, bytestr: bytes) -> bytes:
return _sha256(bytestr).digest()

43
pyproject.toml

@ -1,9 +1,7 @@
[tool.black]
target-version = ["py37"]
line-length = 120
py36 = true
skip-string-normalization = true
include = '\.pyi?$'
exclude = '''
/(
\.eggs
@ -24,12 +22,33 @@ exclude = '''
)
'''
[tool.isort]
default_section = 'THIRDPARTY'
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = 'coincurve'
line_length = 120
multi_line_output = 3
skip_glob = 'setup.py'
use_parentheses = true
[tool.ruff]
target-version = "py37"
line-length = 120
select = ["A", "B", "C", "E", "F", "I", "M", "N", "Q", "RUF", "S", "T", "U", "W", "YTT"]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
]
unfixable = [
# Don't touch unused imports
"F401",
]
[tool.ruff.isort]
known-first-party = ["coincurve"]
[tool.ruff.flake8-quotes]
inline-quotes = "single"
[tool.ruff.per-file-ignores]
"setup.py" = ["B", "C", "I", "N", "U"]
# Tests can use assertions
"tests/*" = ["S101"]
"tests/**/*" = ["S101"]

10
tox.ini

@ -36,23 +36,19 @@ commands =
envdir = {toxworkdir}/lint
skip_install = true
deps =
flake8>=3.9
flake8-bugbear>=20.1.4
flake8-quotes>=3.2.0
black>=21.12b0
isort[pyproject]>=5
ruff
commands =
flake8 .
ruff .
black --check --diff .
isort --check-only --diff .
[testenv:fmt]
envdir = {[testenv:lint]envdir}
skip_install = true
deps = {[testenv:lint]deps}
commands =
isort .
black .
ruff --fix .
{[testenv:lint]commands}
[testenv:typing]

Loading…
Cancel
Save