Skip to content

Commit

Permalink
ci/dev: upgrade to black version 24
Browse files Browse the repository at this point in the history
black version 19 does not work with python 3.13 due to a dependency on typed-ast.

Signed-off-by: Erik Larsson <[email protected]>
  • Loading branch information
whooo committed Oct 14, 2024
1 parent 66acdbd commit adfb931
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Install Dependencies
run: |
python3 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade black==19.10b0
python3 -m pip install --user --upgrade black~=24.0
- name: Check
env:
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributing

To contribute, please publish a PR and:

- Keep within the existing style of black. The known working version is: ``19.10b0``.
- Keep within the existing style of black. The known working version is: ``~24.0``.
- `Write a good commit message <https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/>`_.

- If possible prefix your commit with the affected subsystem and colon. For instance, if modifying docs do ``docs: my commit message``.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[tool.black]
required-version = 24
exclude = '''
(
/(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dev =
sphinx-rtd-theme
twine
setuptools_scm[toml]>=3.4.3
black==19.10b0
black~=24.0
pytest
pytest-xdist
pytest-cov
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,17 @@ def run(self):
for k, v in type_map.items():
(t, f) = k
mstr = mstr + f' ("{t}", "{f}"): "{v}",\n'
mstr = mstr.rstrip()
estr = ""
for k, v in element_type_map.items():
estr = estr + f' "{k}": "{v}",\n'
estr = estr.rstrip()

versions = self.get_versions()
vstr = ""
for k, v in versions.items():
vstr = vstr + f' "{k}": "{v}",\n'
vstr = vstr.rstrip()

p = os.path.join(self.build_lib, "tpm2_pytss/internal/type_mapping.py")
sp = os.path.join(
Expand All @@ -285,10 +288,10 @@ def run(self):
print(f"generated _versions with {len(versions)} versions")

stempl = dedent(self.map_template)
mout = stempl.format(mstr=mstr, estr=estr)
mout = stempl.format(mstr=mstr, estr=estr).lstrip()

vtempl = dedent(self.version_template)
vout = vtempl.format(vstr=vstr)
vout = vtempl.format(vstr=vstr).lstrip()

if not self.dry_run:
self.mkpath(os.path.dirname(p))
Expand Down
4 changes: 2 additions & 2 deletions src/tpm2_pytss/ESAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def tr_from_tpmpublic(
obj = ffi.new("ESYS_TR *")
_chkrc(
lib.Esys_TR_FromTPMPublic(
self._ctx, handle, session1, session2, session3, obj,
self._ctx, handle, session1, session2, session3, obj
)
)
return ESYS_TR(obj[0])
Expand Down Expand Up @@ -5390,7 +5390,7 @@ def hierarchy_change_auth(

_chkrc(
lib.Esys_HierarchyChangeAuth(
self._ctx, auth_handle, session1, session2, session3, new_auth_cdata,
self._ctx, auth_handle, session1, session2, session3, new_auth_cdata
)
)

Expand Down
6 changes: 3 additions & 3 deletions src/tpm2_pytss/FAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ def provision(
)
_chkrc(
ret,
acceptable=[lib.TSS2_FAPI_RC_ALREADY_PROVISIONED]
if is_provisioned_ok
else None,
acceptable=(
[lib.TSS2_FAPI_RC_ALREADY_PROVISIONED] if is_provisioned_ok else None
),
)
return ret == lib.TPM2_RC_SUCCESS

Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/TSS2_Exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def error(self):

@property
def fmt1(self):
"""bool: True if the error is related to a handle, parameter or session """
"""bool: True if the error is related to a handle, parameter or session."""
return bool(self._rc & lib.TPM2_RC_FMT1)
8 changes: 4 additions & 4 deletions src/tpm2_pytss/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse(cls, value: str) -> int:

@classmethod
def iterator(cls) -> filter:
""" Returns the constants in the class.
"""Returns the constants in the class.
Returns:
(int): The int values of the constants in the class.
Expand All @@ -47,7 +47,7 @@ def iterator(cls) -> filter:

@classmethod
def contains(cls, value: int) -> bool:
""" Indicates if a class contains a numeric constant.
"""Indicates if a class contains a numeric constant.
Args:
value (int): The raw numerical number to test for.
Expand All @@ -62,7 +62,7 @@ def contains(cls, value: int) -> bool:

@classmethod
def to_string(cls, value: int) -> str:
""" Converts an integer value into it's friendly string name for that class.
"""Converts an integer value into it's friendly string name for that class.
Args:
value (int): The raw numerical number to try and convert to a name.
Expand Down Expand Up @@ -289,7 +289,7 @@ class TPMA_FRIENDLY_INTLIST(TPM_FRIENDLY_INT):

@classmethod
def parse(cls, value: str) -> int:
""" Converts a string of | separated constant values into it's integer value.
"""Converts a string of | separated constant values into it's integer value.
Given a pipe "|" separated list of string constant values that represent the
bitwise values returns the value itself. The value "" (empty string) returns
Expand Down
10 changes: 5 additions & 5 deletions src/tpm2_pytss/internal/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@


def _get_curveid(curve):
for (algid, c) in _curvetable:
for algid, c in _curvetable:
if isinstance(curve, c):
return algid
return None


def _get_curve(curveid):
for (algid, c) in _curvetable:
for algid, c in _curvetable:
if algid == curveid:
return c
return None


def _get_digest(digestid):
for (algid, d) in _digesttable:
for algid, d in _digesttable:
if algid == digestid:
return d
return None


def _get_pyca_digest(digest_type):
for (algid, d) in _digesttable:
for algid, d in _digesttable:
if inspect.isclass(digest_type) and issubclass(digest_type, d):
return algid
elif isinstance(digest_type, d):
Expand All @@ -85,7 +85,7 @@ def _get_pyca_digest(digest_type):


def _get_alg(alg):
for (algid, a) in _algtable:
for algid, a in _algtable:
if algid == alg:
return a
return None
Expand Down
2 changes: 1 addition & 1 deletion src/tpm2_pytss/internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class TSS2Version:
""" Class for comparing git describe output
"""Class for comparing git describe output
Motivation:
python's packaging version class follows pep-440, however
Expand Down
1 change: 1 addition & 0 deletions src/tpm2_pytss/tsskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

_loadablekey_oid = ObjectIdentifier("2.23.133.10.1.3")


# _BooleanOne is used to encode True in the same way as tpm2-tss-engine
class _BooleanOne(Boolean):
def set(self, value):
Expand Down
14 changes: 7 additions & 7 deletions src/tpm2_pytss/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@


class ParserAttributeError(Exception):
""" Exception ocurred when when parsing."""
"""Exception ocurred when when parsing."""

pass


class TPM2_HANDLE(int):
""""A handle to a TPM address"""
"""A handle to a TPM address"""

pass


class TPM_OBJECT(object):
""" Abstract Base class for all TPM Objects. Not suitable for direct instantiation."""
"""Abstract Base class for all TPM Objects. Not suitable for direct instantiation."""

def __init__(self, _cdata=None, **kwargs):

Expand Down Expand Up @@ -244,7 +244,7 @@ def unmarshal(cls, buf):


class TPM2B_SIMPLE_OBJECT(TPM_OBJECT):
""" Abstract Base class for all TPM2B Simple Objects. A Simple object contains only
"""Abstract Base class for all TPM2B Simple Objects. A Simple object contains only
a size and byte buffer fields. This is not suitable for direct instantiation."""

def __init__(self, _cdata=None, **kwargs):
Expand Down Expand Up @@ -337,7 +337,7 @@ def __eq__(self, value):


class TPML_Iterator(object):
""" Iterator class for iterating over TPML data types.
"""Iterator class for iterating over TPML data types.
This class is used in enumerated for loops, such as:
.. code-block:: python
Expand All @@ -364,7 +364,7 @@ def __next__(self):


class TPML_OBJECT(TPM_OBJECT):
""" Abstract Base class for all TPML Objects. A TPML object is an object that
"""Abstract Base class for all TPML Objects. A TPML object is an object that
contains a list of objects. This is not suitable for direct instantiation."""

def __init__(self, _cdata=None, **kwargs):
Expand Down Expand Up @@ -2221,7 +2221,7 @@ def _serialize(
)

data = k.private_bytes(
encoding=encoding, format=format, encryption_algorithm=enc_alg,
encoding=encoding, format=format, encryption_algorithm=enc_alg
)

return data
Expand Down
12 changes: 6 additions & 6 deletions test/test_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ def test_cert_builder_rsa(self):

builder = x509.CertificateBuilder()
builder = builder.subject_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
builder = builder.issuer_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
builder = builder.serial_number(x509.random_serial_number())
one_day = datetime.timedelta(1, 0, 0)
Expand All @@ -459,7 +459,7 @@ def test_csr_builder_rsa(self):

builder = x509.CertificateSigningRequestBuilder()
builder = builder.subject_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
halg = privkey.get_digest_algorithm()
csr = builder.sign(privkey, algorithm=halg())
Expand All @@ -474,10 +474,10 @@ def test_cert_builder_ecc(self):

builder = x509.CertificateBuilder()
builder = builder.subject_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
builder = builder.issuer_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
builder = builder.serial_number(x509.random_serial_number())
one_day = datetime.timedelta(1, 0, 0)
Expand All @@ -497,7 +497,7 @@ def test_csr_builder_ecc(self):

builder = x509.CertificateSigningRequestBuilder()
builder = builder.subject_name(
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel"),])
x509.Name([x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "falafel")])
)
halg = privkey.get_digest_algorithm()
csr = builder.sign(privkey, algorithm=halg())
Expand Down
12 changes: 6 additions & 6 deletions test/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ def test_base_TPMS_CAPABILITY_DATA(self):
handles = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.HANDLES)
handles.data.handles = TPML_HANDLE((1,))
ev = enc.encode(handles)
self.assertEqual(ev, {"capability": 1, "data": [1,]})
self.assertEqual(ev, {"capability": 1, "data": [1]})

commands = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.COMMANDS)
cmd = TPM2_CC.NV_Write & TPMA_CC.NV & (2 << TPMA_CC.CHANDLES_SHIFT)
commands.data.command = TPML_CCA((cmd,))
ev = enc.encode(commands)
self.assertEqual(ev, {"capability": 2, "data": [cmd,]})
self.assertEqual(ev, {"capability": 2, "data": [cmd]})

ppcommands = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.PP_COMMANDS)
ppcommands.data.ppCommands = TPML_CC((3,))
ev = enc.encode(ppcommands)
self.assertEqual(ev, {"capability": 3, "data": [3,]})
self.assertEqual(ev, {"capability": 3, "data": [3]})

auditcommands = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.AUDIT_COMMANDS)
auditcommands.data.auditCommands = TPML_CC((4,))
ev = enc.encode(auditcommands)
self.assertEqual(ev, {"capability": 4, "data": [4,]})
self.assertEqual(ev, {"capability": 4, "data": [4]})

pcrs = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.PCRS)
pcrsel = TPMS_PCR_SELECTION(
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_base_TPMS_CAPABILITY_DATA(self):
curves = TPMS_CAPABILITY_DATA(capability=TPM2_CAP.ECC_CURVES)
curves.data.eccCurves = TPML_ECC_CURVE((TPM2_ECC.SM2_P256,))
ev = enc.encode(curves)
self.assertEqual(ev, {"capability": 8, "data": [0x20,]})
self.assertEqual(ev, {"capability": 8, "data": [0x20]})

def test_base_TPMS_ATTEST(self):
enc = base_encdec()
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_base_TPMS_ATTEST(self):
time=TPMS_TIME_INFO(
time=1234,
clockInfo=TPMS_CLOCK_INFO(
clock=1024, resetCount=2, restartCount=3, safe=False,
clock=1024, resetCount=2, restartCount=3, safe=False
),
),
firmwareVersion=1337,
Expand Down
Loading

0 comments on commit adfb931

Please sign in to comment.