uv compatibility, typing improvements
cover uv compatibility, typing improvements
uv[0] is an extremely fast Python package and project manager; allowing b4 to be developed with it makes life more pleasant for all contributors.
This series makes the b4 project compatible with uv and fixes various typing problems. Please see also https://github.com/mricon/b4/issues/61
for the likely cause of many of these typing issues having previously gone unnoticed.
---
Tamir Duberstein (10):
Use PEP-735 dependency groups
Specify optional dependencies in pyproject.toml Specify dependencies in pyproject.toml Add ruff, remove all noqa comments Remove noinspection comments
Add mypy
Add missing LoreTrailer.lmsg annotation Check variables for None rather than exprs Make LoreSeries.indexes never None
Add missing type annotations
misc/requirements-completion.in | 1 - misc/send-receive.py | 9 ++- pyproject.toml | 30 ++++++--- requirements.in | 4 -- requirements.txt | 8 +-- src/b4/__init__.py | 133 ++++++++++++++++++++-------------------- src/b4/command.py | 34 +++++----- src/b4/ez.py | 50 +++++++-------- src/b4/kr.py | 3 +- src/b4/mbox.py | 6 +- src/b4/ty.py | 17 +++-- src/tests/conftest.py | 17 ++--- src/tests/test___init__.py | 25 ++++---- src/tests/test_ez.py | 9 +-- src/tests/test_mbox.py | 7 ++- 15 files changed, 181 insertions(+), 172 deletions(-)
---
base-commit: 6f78e874e96b0b3bac1767a1743b20af20cb0e2f
change-id: 20250128-uv-compat-4e107b99e7da
Best regards,
Signature · 1 line
Tamir Duberstein <[email protected]>
PATCH 1/10 Use PEP-735 dependency groups
--- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
pyproject.toml +3 -1
@@ -24,11 +24,13 @@ classifiers = [ ] dynamic = ["dependencies"] -[project.optional-dependencies] +[dependency-groups] dev = [ "pytest", "types-requests", ] + +[project.optional-dependencies] shtab = [ "shtab", ]
Signature · 1 line
2.49.0
PATCH 2/10 Specify optional dependencies in pyproject.toml
In reply to Tamir DubersteinThis allows uv tool install .[completion] to complete without warning; before this change the "completion" extra was not recognized by uv.
--- misc/requirements-completion.in | 1 - pyproject.toml | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-)
misc/requirements-completion.in deleted +0 -1
@@ -1 +0,0 @@ -shtab>=1.7
pyproject.toml +2 -5
@@ -31,16 +31,13 @@ dev = [ ] [project.optional-dependencies] -shtab = [ - "shtab", +completion = [ + "shtab>=1.7", ] [tool.setuptools.dynamic] dependencies = { file = ["requirements.in"] } -[tool.setuptools.dynamic.optional-dependencies] -completion = { file = ["misc/requirements-completion.in"] } - [tool.setuptools.packages.find] where = ['src'] exclude = ['tests*']
Signature · 1 line
2.49.0
PATCH 3/10 Specify dependencies in pyproject.toml
In reply to Tamir DubersteinThis reduces the setuptools-specific configuration slightly.
Add pip-tools to dev dependencies and use it to regenerate requirements.txt with uv run pip-compile > requirements.txt.
--- pyproject.toml | 11 +++++++---- requirements.in | 4 ---- requirements.txt | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-)
pyproject.toml +7 -4
@@ -22,10 +22,16 @@ classifiers = [ "Topic :: Software Development", "Topic :: Utilities", ] -dynamic = ["dependencies"] +dependencies = [ + "requests>=2.24,<3.0", + "git-filter-repo>=2.30,<3.0", + "dkimpy>=1.0,<2.0", + "patatt>=0.6,<2.0", +] [dependency-groups] dev = [ + "pip-tools", "pytest", "types-requests", ]
@@ -35,9 +41,6 @@ completion = [ "shtab>=1.7", ] -[tool.setuptools.dynamic] -dependencies = { file = ["requirements.in"] } - [tool.setuptools.packages.find] where = ['src'] exclude = ['tests*']
requirements.in deleted +0 -4
@@ -1,4 +0,0 @@ -requests>=2.24,<3.0 -git-filter-repo>=2.30,<3.0 -dkimpy>=1.0,<2.0 -patatt>=0.6,<2.0
requirements.txt +4 -4
@@ -156,7 +156,7 @@ charset-normalizer==3.3.2 \ # via requests dkimpy==1.1.6 \ --hash=sha256:0ce72d961f443e8f9f05694b354542dee534e08e2b8c5b60c62d5daca7c1da0f - # via -r requirements.in + # via b4 (pyproject.toml) dnspython==2.6.1 \ --hash=sha256:5ef3b9680161f6fa89daf8ad451b5f1a33b18ae8a1c6778cdf4b43f08c0a6e50 \ --hash=sha256:e8f0f9c23a7b7cb99ded64e6c3a6f3e701d78f50c55e002b839dea7225cff7cc
@@ -164,7 +164,7 @@ dnspython==2.6.1 \ git-filter-repo==2.38.0 \ --hash=sha256:c2646206dfdbf06ce27c06c5b77ea33209d8e32d1e33f6bd4c25b1ccc59f9864 \ --hash=sha256:fe1753e18f0bd6d3c9b57868c8011ae7d056a6ebab706706396a15ef5312725e - # via -r requirements.in + # via b4 (pyproject.toml) idna==3.7 \ --hash=sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc \ --hash=sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0
@@ -172,7 +172,7 @@ idna==3.7 \ patatt==0.6.3 \ --hash=sha256:980826f6529d2576c267ca1f564d5bef046cb47e54215bb598ed6c4b9b2d0a28 \ --hash=sha256:fd763660cb847aab623cbb9891240b6c10c39cc9bfca73cd3b03d40a5eb1c552 - # via -r requirements.in + # via b4 (pyproject.toml) pycparser==2.22 \ --hash=sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6 \ --hash=sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc
@@ -192,7 +192,7 @@ pynacl==1.5.0 \ requests==2.32.3 \ --hash=sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760 \ --hash=sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6 - # via -r requirements.in + # via b4 (pyproject.toml) urllib3==2.2.1 \ --hash=sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d \ --hash=sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19
Signature · 1 line
2.49.0
PATCH 4/10 Add ruff, remove all noqa comments
In reply to Tamir DubersteinAllows ruff check to pass.
--- misc/send-receive.py | 6 +++--- pyproject.toml | 7 +++++++ src/b4/__init__.py | 8 ++++---- src/b4/ez.py | 14 +++++++------- src/b4/mbox.py | 4 ++-- src/b4/ty.py | 4 ++-- src/tests/conftest.py | 2 +- src/tests/test___init__.py | 6 +++--- src/tests/test_ez.py | 3 +-- src/tests/test_mbox.py | 3 +-- 10 files changed, 31 insertions(+), 26 deletions(-)
misc/send-receive.py +3 -3
@@ -84,7 +84,7 @@ class SendReceiveListener(object): conn.execute(q) conn.close() - def on_get(self, req, resp): # noqa + def on_get(self, req, resp): resp.status = falcon.HTTP_200 resp.content_type = falcon.MEDIA_TEXT resp.text = "We don't serve GETs here\n"
@@ -417,7 +417,7 @@ class SendReceiveListener(object): bdata = umsg.encode() try: identity, selector, auth_id = self.validate_message(conn, t_auth, bdata) - except patatt.NoKeyError as ex: # noqa + except patatt.NoKeyError: self.send_error(resp, message='No matching key, please complete web auth first.') return except Exception as ex:
@@ -623,7 +623,7 @@ class SendReceiveListener(object): raw = req.bounded_stream.read() try: jdata = json.loads(raw) - except: + except Exception: resp.status = falcon.HTTP_500 resp.content_type = falcon.MEDIA_TEXT resp.text = 'Failed to parse the request\n'
pyproject.toml +7 -0
@@ -33,6 +33,7 @@ dependencies = [ dev = [ "pip-tools", "pytest", + "ruff", "types-requests", ]
@@ -71,3 +72,9 @@ files = [ {filename = "src/b4/man/b4.5.rst"}, {filename = "src/b4/man/b4.5"}, ] + +[tool.ruff.lint] +select = [ + "PGH004", # https://docs.astral.sh/ruff/rules/blanket-noqa/ +] +flake8-quotes.inline-quotes = "single"
src/b4/__init__.py +4 -4
@@ -1443,7 +1443,7 @@ class LoreMessage: try: res = dkim.verify(self.msg.as_bytes(policy=emlpolicy), logger=dkimlogger) logger.debug('DKIM verify results: %s=%s', identity, res) - except Exception as ex: # noqa + except Exception as ex: # Usually, this is due to some DNS resolver failure, which we can't # possibly cleanly try/catch. Just mark it as failed and move on. logger.debug('DKIM attestation failed: %s', ex)
@@ -2664,7 +2664,7 @@ class LoreAttestor: return None try: return datetime.datetime.fromtimestamp(int(ts), datetime.timezone.utc) - except: # noqa + except Exception: logger.debug('Failed parsing t=%s', ts) return None
@@ -2988,7 +2988,7 @@ def _setup_main_config(cmdargs: Optional[argparse.Namespace] = None) -> None: resolvers = [x.strip() for x in config['attestation-dns-resolvers'].split(',')] if resolvers: # Don't force this as an automatically discovered dependency - import dns.resolver # noqa + import dns.resolver dns.resolver.default_resolver = dns.resolver.Resolver(configure=False) dns.resolver.default_resolver.nameservers = resolvers except ImportError:
@@ -4123,7 +4123,7 @@ def send_mail(smtp: Union[smtplib.SMTP, smtplib.SMTP_SSL, None], msgs: Sequence[ rdata = res.json() if rdata.get('result') == 'success': return len(tosend) - except Exception as ex: # noqa + except Exception: logger.critical('Odd response from the endpoint: %s', res.text) return 0
src/b4/ez.py +7 -7
@@ -40,7 +40,7 @@ except ModuleNotFoundError: can_patatt = False try: - import git_filter_repo as fr # noqa + import git_filter_repo as fr can_gfr = True except ModuleNotFoundError:
@@ -199,7 +199,7 @@ def auth_new() -> None: logger.info('Once you receive it, run b4 send --web-auth-verify [challenge-string]') sys.exit(0) - except Exception as ex: # noqa + except Exception: logger.critical('Odd response from the endpoint: %s', res.text) sys.exit(1)
@@ -241,7 +241,7 @@ def auth_verify(cmdargs: argparse.Namespace) -> None: logger.info('You may now use this endpoint for submitting patches.') sys.exit(0) - except Exception as ex: # noqa + except Exception: logger.critical('Odd response from the endpoint: %s', res.text) sys.exit(1)
@@ -316,7 +316,7 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: break cover_sections.append(section) cover = '\n---\n'.join(cover_sections).strip() - except Exception as ex: # noqa + except Exception as ex: logger.critical('CRITICAL: unable to restore tracking information, ignoring') logger.critical(' %s', ex)
@@ -771,7 +771,7 @@ class FRCommitMessageEditor: def add(self, commit: str, message: str): self.edit_map[commit.encode()] = message.encode() - def callback(self, commit, metadata): # noqa + def callback(self, commit, metadata): if commit.original_id in self.edit_map: commit.message = self.edit_map[commit.original_id]
@@ -1224,7 +1224,7 @@ def get_addresses_from_cmd(cmdargs: List[str], msgbytes: bytes) -> List[Tuple[st return list() # Run this command from git toplevel topdir = b4.git_get_toplevel() - ecode, out, err = b4._run_command(cmdargs, stdin=msgbytes, rundir=topdir) # noqa + ecode, out, err = b4._run_command(cmdargs, stdin=msgbytes, rundir=topdir) if ecode > 0: logger.critical('CRITICAL: Running %s failed:', ' '.join(cmdargs)) logger.critical(err.decode(errors='ignore'))
@@ -2105,7 +2105,7 @@ def cmd_send(cmdargs: argparse.Namespace) -> None: else: try: smtp, fromaddr = b4.get_smtp(dryrun=cmdargs.dryrun) - except Exception as ex: # noqa + except Exception as ex: logger.critical('Failed to configure the smtp connection:') logger.critical(ex) sys.exit(1)
src/b4/mbox.py +2 -2
@@ -510,12 +510,12 @@ def thanks_record_am(lser: b4.LoreSeries, cherrypick: Optional[List[int]]) -> No try: allto = email.utils.getaddresses([str(x) for x in lmsg.msg.get_all('to', [])]) - except Exception as ex: # noqa + except Exception as ex: allto = [] logger.debug('Unable to parse the To: header in %s: %s', lmsg.msgid, str(ex)) try: allcc = email.utils.getaddresses([str(x) for x in lmsg.msg.get_all('cc', [])]) - except Exception as ex: # noqa + except Exception as ex: allcc = [] logger.debug('Unable to parse the Cc: header in %s: %s', lmsg.msgid, str(ex))
src/b4/ty.py +2 -2
@@ -261,7 +261,7 @@ def set_branch_details(gitdir: Optional[str], branch: str, jsondata: dict, confi # Try to grab the last two chunks of the path purl = Path(binfo['url']) jsondata['treename'] = os.path.join(purl.parts[-2], purl.parts[-1]) - except: + except Exception: # Something went wrong... just use the whole URL jsondata['treename'] = binfo['url'] else:
@@ -400,7 +400,7 @@ def send_messages(listing: List[Dict], branch: str, cmdargs: argparse.Namespace) send_email = True try: smtp, fromaddr = b4.get_smtp() - except Exception as ex: # noqa + except Exception as ex: logger.critical('Failed to configure the smtp connection:') logger.critical(ex) sys.exit(1)
src/tests/conftest.py +1 -1
@@ -1,4 +1,4 @@ -import pytest # noqa +import pytest import b4 import os import sys
src/tests/test___init__.py +3 -3
@@ -1,4 +1,4 @@ -import pytest # noqa +import pytest import b4 import os import email
@@ -183,8 +183,8 @@ def test_followup_trailers(sampledir, source, serargs, amargs, reference, b4cfg) # Test short message-id ('Message-ID: <[email protected]>', '<[email protected]>', 'encode'), # Test long message-id - ('Message-ID: <20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', # noqa - '<20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', # noqa + ('Message-ID: <20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', + '<20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', 'encode'), ]) def test_header_wrapping(sampledir, hval, verify, tr):
src/tests/test_ez.py +1 -2
@@ -1,4 +1,4 @@ -import pytest # noqa +import pytest import os import b4 import b4.ez
@@ -61,7 +61,6 @@ def test_trailers(sampledir, prepdir, mboxf, bundlef, rep, trargs, compareargs, cmdargs = parser.parse_args(b4args) with pytest.raises(SystemExit) as e: b4.mbox.main(cmdargs) - assert e.type == SystemExit assert e.value.code == 0 cfile = os.path.join(sampledir, f'{compareout}.verify')
src/tests/test_mbox.py +1 -2
@@ -1,4 +1,4 @@ -import pytest # noqa +import pytest import os import b4 import b4.mbox
@@ -24,7 +24,6 @@ def test_shazam(sampledir, gitdir, mboxf, shazamargs, compareargs, compareout, b cmdargs = parser.parse_args(shazamargs) with pytest.raises(SystemExit) as e: b4.mbox.main(cmdargs) - assert e.type == SystemExit assert e.value.code == 0 out, logstr = b4.git_run_command(None, compareargs) assert out == 0
Signature · 1 line
2.49.0
PATCH 5/10 Remove `noinspection` comments
In reply to Tamir DubersteinI don't see these warnings in PyCharm.
--- misc/send-receive.py | 3 +-- src/b4/__init__.py | 2 -- src/b4/command.py | 2 -- src/b4/ty.py | 1 - 4 files changed, 1 insertion(+), 7 deletions(-)
misc/send-receive.py +1 -2
@@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# noinspection PyUnresolvedReferences + import falcon import os import sys
@@ -35,7 +35,6 @@ logger = logging.getLogger('b4-send-receive') logger.setLevel(logging.DEBUG) -# noinspection PyBroadException, PyMethodMayBeStatic class SendReceiveListener(object): def __init__(self, _engine, _config) -> None:
src/b4/__init__.py +0 -2
@@ -28,7 +28,6 @@ import time import copy import shutil import mailbox -# noinspection PyCompatibility import pwd import io
@@ -1038,7 +1037,6 @@ class LoreSeries: return start_commit, end_commit def save_cover(self, outfile): - # noinspection PyUnresolvedReferences cover_msg = self.patches[0].get_am_message(add_trailers=False) with open(outfile, 'wb') as fh: fh.write(LoreMessage.get_msg_as_bytes(cover_msg, headers='decode'))
src/b4/command.py +0 -2
@@ -137,7 +137,6 @@ class ConfigOption(argparse.Action): def setup_parser() -> argparse.ArgumentParser: - # noinspection PyTypeChecker parser = argparse.ArgumentParser( prog='b4', description='A tool to work with patches in public-inbox archives',
@@ -431,7 +430,6 @@ if __name__ == '__main__': # We're running from a checkout, so reflect git commit in the version import os - # noinspection PyBroadException try: if b4.__VERSION__.find('-dev') > 0: base = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
src/b4/ty.py +0 -1
@@ -256,7 +256,6 @@ def set_branch_details(gitdir: Optional[str], branch: str, jsondata: dict, confi if 'thanks-treename' in config: jsondata['treename'] = config['thanks-treename'] elif 'url' in binfo: - # noinspection PyBroadException try: # Try to grab the last two chunks of the path purl = Path(binfo['url'])
Signature · 1 line
2.49.0
PATCH 6/10 Add mypy
In reply to Tamir Duberstein--- pyproject.toml | 1 + 1 file changed, 1 insertion(+)
pyproject.toml +1 -0
@@ -31,6 +31,7 @@ dependencies = [ [dependency-groups] dev = [ + "mypy", "pip-tools", "pytest", "ruff",
Signature · 1 line
2.49.0
PATCH 7/10 Add missing LoreTrailer.lmsg annotation
In reply to Tamir Duberstein--- src/b4/__init__.py | 1 + 1 file changed, 1 insertion(+)
src/b4/__init__.py +1 -0
@@ -172,6 +172,7 @@ class LoreMailbox: msgid_map: Dict[str, 'LoreMessage'] series: Dict[int, 'LoreSeries'] covers: Dict[int, 'LoreMessage'] + trailer_map: Dict[str, List['LoreMessage']] followups: List['LoreMessage'] unknowns: List['LoreMessage']
Signature · 1 line
2.49.0
PATCH 8/10 Check variables for None rather than exprs
In reply to Tamir DubersteinThis allows type checkers to better understand that these variables can't be None.
--- src/b4/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
src/b4/__init__.py +12 -9
@@ -207,10 +207,12 @@ class LoreMailbox: # To qualify for a partial reroll: # 1. Needs to be version > 1 # 2. Replies need to be to the exact X/N of the previous revision - if revision <= 1 or revision - 1 not in self.series: + if revision <= 1: return - # Are existing patches replies to previous revisions with the same counter? pser = self.get_series(revision - 1, sloppytrailers=sloppytrailers) + if pser is None: + return + # Are existing patches replies to previous revisions with the same counter? lser = self.series[revision] sane = True for patch in lser.patches:
@@ -245,11 +247,12 @@ class LoreMailbox: logger.debug('Reconstituting a partial reroll') at = 0 for patch in lser.patches: - if pser.patches[at] is None: + pserpatch = pser.patches[at] + if pserpatch is None: at += 1 continue if patch is None: - ppatch = copy.deepcopy(pser.patches[at]) + ppatch = copy.deepcopy(pserpatch) ppatch.revision = lser.revision ppatch.reroll_from_revision = pser.revision lser.patches[at] = ppatch
@@ -353,12 +356,12 @@ class LoreMailbox: if pmsg is None: # Can't find the message we're replying to here continue - elif fmsg.in_reply_to in self.msgid_map: - logger.debug('Found in-reply-to %s in msgid_map', fmsg.in_reply_to) - pmsg = self.msgid_map[fmsg.in_reply_to] else: - logger.debug(' missing message, skipping: %s', fmsg.in_reply_to) - continue + pmsg = self.msgid_map[fmsg.in_reply_to] + if pmsg is None: + logger.debug(' missing message, skipping: %s', fmsg.in_reply_to) + continue + logger.debug('Found in-reply-to %s in msgid_map', fmsg.in_reply_to) trailers, mismatches = fmsg.get_trailers(sloppy=sloppytrailers) for ltr in mismatches:
Signature · 1 line
2.49.0
PATCH 9/10 Make LoreSeries.indexes never None
In reply to Tamir Duberstein--- src/b4/__init__.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
src/b4/__init__.py +8 -11
@@ -502,7 +502,7 @@ class LoreSeries: has_cover: bool = False partial_reroll: bool = False subject: str - indexes: Optional[List[Tuple[str, str]]] = None + _indexes: Optional[List[Tuple[str, str]]] = None base_commit: Optional[str] = None change_id: Optional[str] = None prereq_patch_ids: Optional[List[str]] = None
@@ -795,8 +795,11 @@ class LoreSeries: return msgs - def populate_indexes(self): - self.indexes = list() + @property + def indexes(self) -> List[Tuple[str, str]]: + if self._indexes is not None: + return self._indexes + self._indexes = list() seenfiles = set() for lmsg in self.patches[1:]: if lmsg is None or not lmsg.blob_indexes:
@@ -812,17 +815,11 @@ class LoreSeries: if set(obh) == {'0'}: # New file, will for sure apply clean continue - self.indexes.append((ofn, obh)) + self._indexes.append((ofn, obh)) + return self._indexes def check_applies_clean(self, gitdir: Optional[str] = None, at: Optional[str] = None) -> Tuple[int, List[Tuple[str, str]]]: - if self.indexes is None: - self.populate_indexes() - - if self.indexes is None: - logger.debug('No indexes to check against') - return 0, list() - mismatches = list() if at is None: at = 'HEAD'
Signature · 1 line
2.49.0
PATCH 10/10 Add missing type annotations
In reply to Tamir DubersteinUnannotated functions are skipped by mypy, giving a false impression of the completeness of type annotations. Add missing generics.
--- src/b4/__init__.py | 82 ++++++++++++++++++++++------------------------ src/b4/command.py | 32 +++++++++--------- src/b4/ez.py | 38 ++++++++++----------- src/b4/kr.py | 3 +- src/b4/mbox.py | 2 +- src/b4/ty.py | 12 +++---- src/tests/conftest.py | 15 +++++---- src/tests/test___init__.py | 19 ++++++----- src/tests/test_ez.py | 6 ++-- src/tests/test_mbox.py | 4 ++- 10 files changed, 112 insertions(+), 101 deletions(-)
src/b4/__init__.py +40 -42
@@ -51,7 +51,7 @@ emlpolicy = email.policy.EmailPolicy(utf8=True, cte_type='8bit', max_line_length qspecials = re.compile(r'[()<>@,:;.\"\[\]]') try: - import dkim # type: ignore[import] + import dkim # type: ignore[import-not-found] can_dkim = True except ModuleNotFoundError:
@@ -71,7 +71,7 @@ __VERSION__ = '0.15-dev' PW_REST_API_VERSION = '1.2' -def _dkim_log_filter(record): +def _dkim_log_filter(record: logging.LogRecord) -> bool: # Hide all dkim logging output in normal operation by setting the level to # DEBUG. If debugging output has been enabled then prefix dkim logging # output to make its origin clear.
@@ -176,7 +176,7 @@ class LoreMailbox: followups: List['LoreMessage'] unknowns: List['LoreMessage'] - def __init__(self): + def __init__(self) -> None: self.msgid_map = dict() self.series = dict() self.covers = dict()
@@ -184,7 +184,7 @@ class LoreMailbox: self.followups = list() self.unknowns = list() - def __repr__(self): + def __repr__(self) -> str: out = list() for key, lser in self.series.items(): out.append(str(lser))
@@ -202,7 +202,7 @@ class LoreMailbox: return self.msgid_map[msgid] return None - def partial_reroll(self, revision, sloppytrailers): + def partial_reroll(self, revision: int, sloppytrailers: bool) -> None: # Is it a partial reroll? # To qualify for a partial reroll: # 1. Needs to be version > 1
@@ -516,7 +516,7 @@ class LoreSeries: self.trailer_mismatches = set() self.subject = '(untitled)' - def __repr__(self): + def __repr__(self) -> str: out = list() out.append('- Series: [v%s] %s' % (self.revision, self.subject)) out.append(' revision: %s' % self.revision)
@@ -839,7 +839,7 @@ class LoreSeries: return len(self.indexes), mismatches - def find_base(self, gitdir: Optional[str], branches: Optional[list] = None, maxdays: int = 30) -> Tuple[str, int, int]: + def find_base(self, gitdir: Optional[str], branches: Optional[List[str]] = None, maxdays: int = 30) -> Tuple[str, int, int]: if self.indexes is None: self.populate_indexes() if self.indexes is None or not len(self.indexes):
@@ -1037,7 +1037,7 @@ class LoreSeries: return start_commit, end_commit - def save_cover(self, outfile): + def save_cover(self, outfile: str) -> None: cover_msg = self.patches[0].get_am_message(add_trailers=False) with open(outfile, 'wb') as fh: fh.write(LoreMessage.get_msg_as_bytes(cover_msg, headers='decode'))
@@ -1197,7 +1197,7 @@ class LoreMessage: pw_ci_status: Optional[str] local_ci_status: Optional[List[Tuple[str, str]]] - def __init__(self, msg): + def __init__(self, msg: EmailMessage) -> None: self.msg = msg # set some defaults
@@ -1233,10 +1233,10 @@ class LoreMessage: self.counters_inferred = self.lsubject.counters_inferred # Loaded when properties are called - self._attestors = None - self._git_patch_id = None - self._pwhash = None - self._blob_indexes = None + self._attestors: Optional[List['LoreAttestor']] = None + self._git_patch_id: Optional[str] = None + self._pwhash: Optional[str] = None + self._blob_indexes: Optional[Set[Tuple[str, str, str, str]]] = None # Handle [PATCH 6/5] if self.counter > self.expected:
@@ -1605,7 +1605,7 @@ class LoreMessage: self.local_ci_status.extend(status) @staticmethod - def get_patchwork_data_by_msgid(msgid: str) -> dict: + def get_patchwork_data_by_msgid(msgid: str) -> Dict[str, str]: config = get_main_config() pwkey = str(config.get('pw-key', '')) pwurl = str(config.get('pw-url', ''))
@@ -1647,7 +1647,7 @@ class LoreMessage: save_cache(pwdata, pwurl + pwproj + msgid, suffix='lookup', is_json=True) return pwdata - def get_patchwork_info(self) -> Optional[dict]: + def get_patchwork_info(self) -> Optional[Dict[str,str]]: if not self.pwhash: return None try:
@@ -1721,7 +1721,7 @@ class LoreMessage: return checkmark, trailers, critical - def __repr__(self): + def __repr__(self) -> str: out = list() out.append('msgid: %s' % self.msgid) out.append(str(self.lsubject))
@@ -1837,7 +1837,7 @@ class LoreMessage: return new_hdrval.strip() @staticmethod - def wrap_header(hdr, width: int = 75, nl: str = '\n', + def wrap_header(hdr: Tuple[str, str], width: int = 75, nl: str = '\n', transform: Literal['encode', 'decode', 'preserve'] = 'preserve') -> bytes: hname, hval = hdr if hname.lower() in ('to', 'cc', 'from', 'x-original-from'):
@@ -1911,7 +1911,7 @@ class LoreMessage: return bdata @staticmethod - def get_parts_from_header(hstr: str) -> dict: + def get_parts_from_header(hstr: str) -> Dict[str, str]: hstr = re.sub(r'\s*', '', hstr) hdata = dict() for chunk in hstr.split(';'):
@@ -1997,7 +1997,7 @@ class LoreMessage: line = filename_match.group(1) + ' ' + filename elif hunk_match: # remove line numbers, but leave line counts - def fn(x): + def fn(x: Optional[str]) -> int: if not x: return 1 return int(x)
@@ -2462,7 +2462,7 @@ class LoreSubject: counters_inferred: bool prefixes: List[str] - def __init__(self, subject): + def __init__(self, subject: str) -> None: # Subject-based info self.reply = False self.resend = False
@@ -2560,7 +2560,7 @@ class LoreSubject: else: return f'[PATCH] {self.subject}' - def get_slug(self, sep='_', with_counter: bool = True) -> str: + def get_slug(self, sep: str = '_', with_counter: bool = True) -> str: unsafe = self.subject if with_counter: unsafe = '%04d%s%s' % (self.counter, sep, unsafe)
@@ -2618,7 +2618,7 @@ class LoreAttestor: return ATT_FAIL_SIMPLE @property - def trailer(self): + def trailer(self) -> str: if self.keyalgo: mode = self.keyalgo else:
@@ -2626,7 +2626,7 @@ class LoreAttestor: return '%s/%s' % (mode, self.identity.lower()) - def check_time_drift(self, emldate, maxdays: int = 30) -> bool: + def check_time_drift(self, emldate: datetime.datetime, maxdays: int = 30) -> bool: if not self.passing or self.signtime is None: return False
@@ -2667,7 +2667,7 @@ class LoreAttestor: logger.debug('Failed parsing t=%s', ts) return None - def __repr__(self): + def __repr__(self) -> str: out = list() out.append(' mode: %s' % self.mode) out.append(' level: %s' % self.level)
@@ -2682,7 +2682,7 @@ class LoreAttestor: class LoreAttestorDKIM(LoreAttestor): - def __init__(self, passing: bool, identity: str, signtime: Optional[datetime.datetime], errors: list) -> None: + def __init__(self, passing: bool, identity: str, signtime: Optional[datetime.datetime], errors: List[str]) -> None: super().__init__() self.mode = 'DKIM' self.level = 'domain'
@@ -2698,7 +2698,7 @@ class LoreAttestorDKIM(LoreAttestor): class LoreAttestorPatatt(LoreAttestor): def __init__(self, result: bool, identity: str, signtime: Optional[datetime.datetime], keysrc: str, keyalgo: str, - errors: list) -> None: + errors: List[str]) -> None: super().__init__() self.mode = 'patatt' self.level = 'person'
@@ -2804,7 +2804,7 @@ def git_credential_fill(gitdir: Optional[str], protocol: str, host: str, usernam return None -def git_get_command_lines(gitdir: Optional[str], args: list) -> List[str]: +def git_get_command_lines(gitdir: Optional[str], args: List[str]) -> List[str]: ecode, out = git_run_command(gitdir, args) lines = list() if out:
@@ -2871,7 +2871,7 @@ def in_directory(dirname: str) -> Generator[bool, None, None]: os.chdir(cdir) -def setup_config(cmdargs: argparse.Namespace): +def setup_config(cmdargs: argparse.Namespace) -> None: """Setup configuration options. Needs to be called before accessing any of the config options.""" _setup_main_config(cmdargs)
@@ -2881,7 +2881,7 @@ def setup_config(cmdargs: argparse.Namespace): _setup_sendemail_config(cmdargs) -def _cmdline_config_override(cmdargs: argparse.Namespace, config: dict, section: str): +def _cmdline_config_override(cmdargs: argparse.Namespace, config: Dict[str, Any], section: str) -> None: """Use cmdline.config to set and override config values for section.""" if not cmdargs.config: return
@@ -2897,14 +2897,14 @@ def _cmdline_config_override(cmdargs: argparse.Namespace, config: dict, section: config.update(config_override) -def git_set_config(fullpath: Optional[str], param: str, value: str, operation: str = '--replace-all'): +def git_set_config(fullpath: Optional[str], param: str, value: str, operation: str = '--replace-all') -> int: args = ['config', operation, param, value] ecode, out = git_run_command(fullpath, args) return ecode -def get_config_from_git(regexp: str, defaults: Optional[dict] = None, - multivals: Optional[list] = None, source: Optional[str] = None) -> dict: +def get_config_from_git(regexp: str, defaults: Optional[Dict[str, Any]] = None, + multivals: Optional[List[str]] = None, source: Optional[str] = None) -> Dict[str, Any]: if multivals is None: multivals = list() args = ['config']
@@ -3101,7 +3101,7 @@ def save_cache(contents: Any, identifier: str, suffix: Optional[str] = None, is_ logger.debug('Could not write cache %s for %s', fullpath, identifier) -def _setup_user_config(cmdargs: argparse.Namespace): +def _setup_user_config(cmdargs: argparse.Namespace) -> None: global USER_CONFIG USER_CONFIG = get_config_from_git(r'user\..*')
@@ -3470,7 +3470,7 @@ def get_pi_thread_by_url(t_mbx_url: str, nocache: bool = False) -> Optional[List def get_pi_thread_by_msgid(msgid: str, nocache: bool = False, - onlymsgids: Optional[set] = None, + onlymsgids: Optional[Set[str]] = None, with_thread: bool = True) -> Optional[List[EmailMessage]]: qmsgid = urllib.parse.quote_plus(msgid, safe='@') config = get_main_config()
@@ -3810,7 +3810,7 @@ def save_mboxrd_mbox(msgs: List[EmailMessage], dest: BinaryIO, mangle_from: bool gen.flatten(msg) -def save_maildir(msgs: list, dest) -> None: +def save_maildir(msgs: List[EmailMessage], dest: str) -> None: d_new = os.path.join(dest, 'new') pathlib.Path(d_new).mkdir(parents=True) d_cur = os.path.join(dest, 'cur')
@@ -3826,7 +3826,7 @@ def save_maildir(msgs: list, dest) -> None: os.rename(os.path.join(d_tmp, f'{slug}.eml'), os.path.join(d_new, f'{slug}.eml')) -def get_mailinfo(bmsg: bytes, scissors: bool = False) -> Tuple[dict, bytes, bytes]: +def get_mailinfo(bmsg: bytes, scissors: bool = False) -> Tuple[Dict[str, str], bytes, bytes]: with tempfile.TemporaryDirectory() as tfd: m_out = os.path.join(tfd, 'm') p_out = os.path.join(tfd, 'p')
@@ -3899,7 +3899,7 @@ def get_sendemail_config() -> Dict[str, Optional[Union[str, List[str]]]]: return SENDEMAIL_CONFIG -def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL, list, None], str]: +def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL, List[str], None], str]: sconfig = get_sendemail_config() # Limited support for smtp settings to begin with, but should cover the vast majority of cases fromaddr = str(sconfig.get('from'))
@@ -3994,7 +3994,7 @@ def get_patchwork_session(pwkey: str, pwurl: str) -> Tuple[requests.Session, str return session, url -def patchwork_set_state(msgids: List[str], state: str) -> bool: +def patchwork_set_state(msgids: List[str], state: str) -> None: # Do we have a pw-key defined in config? config = get_main_config() pwkey = str(config.get('pw-key', ''))
@@ -4002,7 +4002,7 @@ def patchwork_set_state(msgids: List[str], state: str) -> bool: pwproj = str(config.get('pw-project', '')) if not (pwkey and pwurl and pwproj): logger.debug('Patchwork support requires pw-key, pw-url and pw-project settings') - return False + return pses, url = get_patchwork_session(pwkey, pwurl) patches_url = '/'.join((url, 'patches')) tochange = list()
@@ -4042,8 +4042,6 @@ def patchwork_set_state(msgids: List[str], state: str) -> bool: except requests.exceptions.RequestException as ex: logger.debug('Patchwork REST error: %s', ex) - return True - def send_mail(smtp: Union[smtplib.SMTP, smtplib.SMTP_SSL, None], msgs: Sequence[EmailMessage], fromaddr: Optional[str], destaddrs: Optional[Union[Set[str], List[str]]] = None,
@@ -4250,7 +4248,7 @@ def get_email_signature() -> str: return signature -def retrieve_messages(cmdargs: argparse.Namespace) -> Tuple[Optional[str], Optional[list]]: +def retrieve_messages(cmdargs: argparse.Namespace) -> Tuple[Optional[str], Optional[List[EmailMessage]]]: msgid = None with_thread = True pickings = set()
src/b4/command.py +17 -15
@@ -10,10 +10,12 @@ import logging import b4 import sys +from typing import Any, Optional, Sequence, Union + logger = b4.logger -def cmd_retrieval_common_opts(sp): +def cmd_retrieval_common_opts(sp: argparse.ArgumentParser) -> None: sp.add_argument('msgid', nargs='?', help='Message ID to process, or pipe a raw message') sp.add_argument('-m', '--use-local-mbox', dest='localmbox', default=None,
@@ -26,7 +28,7 @@ def cmd_retrieval_common_opts(sp): help='Only retrieve the message matching the msgid and ignore the rest of the thread') -def cmd_mbox_common_opts(sp): +def cmd_mbox_common_opts(sp: argparse.ArgumentParser) -> None: cmd_retrieval_common_opts(sp) sp.add_argument('-o', '--outdir', default='.', help='Output into this directory (or use - to output mailbox contents to stdout)')
@@ -38,7 +40,7 @@ def cmd_mbox_common_opts(sp): help='Save as maildir (avoids mbox format ambiguities)') -def cmd_am_common_opts(sp): +def cmd_am_common_opts(sp: argparse.ArgumentParser) -> None: sp.add_argument('-v', '--use-version', dest='wantver', type=int, default=None, help='Get a specific version of the patch/series') sp.add_argument('-t', '--apply-cover-trailers', dest='covertrailers', action='store_true', default=False,
@@ -68,59 +70,59 @@ def cmd_am_common_opts(sp): help='Add a Message-ID: trailer to every patch') -def cmd_mbox(cmdargs): +def cmd_mbox(cmdargs: argparse.Namespace) -> None: import b4.mbox b4.mbox.main(cmdargs) -def cmd_kr(cmdargs): +def cmd_kr(cmdargs: argparse.Namespace) -> None: import b4.kr b4.kr.main(cmdargs) -def cmd_prep(cmdargs): +def cmd_prep(cmdargs: argparse.Namespace) -> None: import b4.ez b4.ez.cmd_prep(cmdargs) -def cmd_trailers(cmdargs): +def cmd_trailers(cmdargs: argparse.Namespace) -> None: import b4.ez b4.ez.cmd_trailers(cmdargs) -def cmd_send(cmdargs): +def cmd_send(cmdargs: argparse.Namespace) -> None: import b4.ez b4.ez.cmd_send(cmdargs) -def cmd_am(cmdargs): +def cmd_am(cmdargs: argparse.Namespace) -> None: import b4.mbox b4.mbox.main(cmdargs) -def cmd_shazam(cmdargs): +def cmd_shazam(cmdargs: argparse.Namespace) -> None: import b4.mbox b4.mbox.main(cmdargs) -def cmd_pr(cmdargs): +def cmd_pr(cmdargs: argparse.Namespace) -> None: import b4.pr b4.pr.main(cmdargs) -def cmd_ty(cmdargs): +def cmd_ty(cmdargs: argparse.Namespace) -> None: import b4.ty b4.ty.main(cmdargs) -def cmd_diff(cmdargs): +def cmd_diff(cmdargs: argparse.Namespace) -> None: import b4.diff b4.diff.main(cmdargs) class ConfigOption(argparse.Action): """Action class for storing key=value arguments in a dict.""" - def __call__(self, parser, namespace, keyval, option_string=None): + def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace, keyval: Union[str, Sequence[Any], None], option_string: Optional[str] = None) -> None: config = getattr(namespace, self.dest, None) if config is None:
@@ -395,7 +397,7 @@ def setup_parser() -> argparse.ArgumentParser: return parser -def cmd(): +def cmd() -> None: parser = setup_parser() cmdargs = parser.parse_args() logger.setLevel(logging.DEBUG)
src/b4/ez.py +19 -19
@@ -28,7 +28,7 @@ import tarfile import hashlib import urllib.parse -from typing import Optional, Tuple, List, Union, Dict, Set +from typing import Any, Optional, Tuple, List, Union, Dict, Set from email import utils from string import Template
@@ -589,13 +589,13 @@ def start_new_series(cmdargs: argparse.Namespace) -> None: logger.info('NOTE: any follow-up trailers were ignored; apply them with b4 trailers -u') -def make_magic_json(data: dict) -> str: +def make_magic_json(data: Dict[str, Any]) -> str: mj = (f'{MAGIC_MARKER}\n' '# This section is used internally by b4 prep for tracking purposes.\n') return mj + json.dumps(data, indent=2) -def load_cover(strip_comments: bool = False, usebranch: Optional[str] = None) -> Tuple[str, dict]: +def load_cover(strip_comments: bool = False, usebranch: Optional[str] = None) -> Tuple[str, Dict[str, Any]]: strategy = get_cover_strategy(usebranch) if strategy in {'commit', 'tip-commit'}: cover_commit = find_cover_commit(usebranch=usebranch)
@@ -636,7 +636,7 @@ def load_cover(strip_comments: bool = False, usebranch: Optional[str] = None) -> return cover.strip(), tracking -def store_cover(content: str, tracking: dict, new: bool = False) -> None: +def store_cover(content: str, tracking: Dict[str, Any], new: bool = False) -> None: strategy = get_cover_strategy() if strategy in {'commit', 'tip-commit'}: cover_message = content + '\n\n' + make_magic_json(tracking)
@@ -654,9 +654,9 @@ def store_cover(content: str, tracking: dict, new: bool = False) -> None: raise RuntimeError('Error saving cover letter (commit not found)') fred = FRCommitMessageEditor() fred.add(commit, cover_message) - args = fr.FilteringOptions.parse_args(['--force', '--quiet', '--refs', f'{commit}~1..HEAD']) - args.refs = [f'{commit}~1..HEAD'] - frf = fr.RepoFilter(args, commit_callback=fred.callback) + frargs = fr.FilteringOptions.parse_args(['--force', '--quiet', '--refs', f'{commit}~1..HEAD']) + frargs.refs = [f'{commit}~1..HEAD'] + frf = fr.RepoFilter(frargs, commit_callback=fred.callback) logger.info('Invoking git-filter-repo to update the cover letter.') frf.run()
@@ -760,18 +760,18 @@ def find_cover_commit(usebranch: Optional[str] = None) -> Optional[str]: class FRCommitMessageEditor: - edit_map: dict + edit_map: Dict[bytes, bytes] - def __init__(self, edit_map: Optional[dict] = None): + def __init__(self, edit_map: Optional[Dict[bytes, bytes]] = None): if edit_map: self.edit_map = edit_map else: self.edit_map = dict() - def add(self, commit: str, message: str): + def add(self, commit: str, message: str) -> None: self.edit_map[commit.encode()] = message.encode() - def callback(self, commit, metadata): + def callback(self, commit: fr.Commit, metadata: Dict[str, str]) -> None: if commit.original_id in self.edit_map: commit.message = self.edit_map[commit.original_id]
@@ -1271,7 +1271,7 @@ def get_series_details(start_commit: Optional[str] = None, usebranch: Optional[s return base_commit, start_commit, end_commit, oneline, shortlog.rstrip(), diffstat.rstrip() -def print_pretty_addrs(addrs: list, hdrname: str) -> None: +def print_pretty_addrs(addrs: List[str], hdrname: str) -> None: if len(addrs) < 1: return logger.info('%s: %s', hdrname, b4.format_addrs([addrs[0]]))
@@ -1339,7 +1339,7 @@ def get_cover_dests(cbody: str) -> Tuple[List, List, str]: def add_cover(csubject: b4.LoreSubject, msgid_tpt: str, patches: List[Tuple[str, email.message.EmailMessage]], - cbody: str, datets: int, thread: bool = True): + cbody: str, datets: int, thread: bool = True) -> None: fp = patches[0][1] cmsg = email.message.EmailMessage() cmsg.add_header('From', fp['From'])
@@ -1420,7 +1420,7 @@ def get_cover_subject_body(cover: str) -> Tuple[b4.LoreSubject, str]: return lsubject, cbody -def rethread(patches: List[Tuple[str, email.message.EmailMessage]]): +def rethread(patches: List[Tuple[str, email.message.EmailMessage]]) -> None: refto = patches[0][1].get('message-id') for commit, msg in patches[1:]: msg.add_header('References', refto)
@@ -2162,7 +2162,7 @@ def get_sent_tagname(tagbase: str, tagprefix: str, revstr: Union[str, int]) -> T return f'{tagprefix}{tagbase}-v{revision}', revision -def reroll(mybranch: str, tag_msg: str, msgid: str, tagprefix: str = SENT_TAG_PREFIX): +def reroll(mybranch: str, tag_msg: str, msgid: str, tagprefix: str = SENT_TAG_PREFIX) -> None: # Remove signature chunks = tag_msg.rsplit('\n-- \n') if len(chunks) > 1:
@@ -2299,7 +2299,7 @@ def show_revision() -> None: logger.info(' %s: %s', rn, config['linkmask'] % link) -def write_to_tar(bio_tar: tarfile.TarFile, name, mtime, bio_file: io.BytesIO): +def write_to_tar(bio_tar: tarfile.TarFile, name: str, mtime: int, bio_file: io.BytesIO) -> None: tifo = tarfile.TarInfo(name) tuser = os.environ.get('USERNAME', 'user') tuid = os.getuid()
@@ -2316,7 +2316,7 @@ def write_to_tar(bio_tar: tarfile.TarFile, name, mtime, bio_file: io.BytesIO): def get_prep_managed_branches(gitdir: Optional[str] = None) -> List[str]: lines = b4.git_get_command_lines(gitdir, ['show-ref', '--heads']) - mybranches = list() + mybranches: List[str] = list() if not lines: logger.debug('Git show-ref returned no heads') return mybranches
@@ -2555,7 +2555,7 @@ def force_revision(forceto: int) -> None: store_cover(cover, tracking) -def compare(compareto: str, execvp: bool = True, range_diff_opts: str = None) -> Union[str, None]: +def compare(compareto: str, execvp: bool = True, range_diff_opts: Optional[str] = None) -> Union[str, None]: cover, tracking = load_cover() # Try the new format first tagname, revision = get_sent_tagname(tracking['series']['change-id'], SENT_TAG_PREFIX, compareto)
@@ -2736,7 +2736,7 @@ def store_preflight_check(identity: str) -> None: b4.save_cache(pf_checks, cacheid, suffix='checks', is_json=True) -def set_prefixes(prefixes: list, additive: bool = False) -> None: +def set_prefixes(prefixes: List[str], additive: bool = False) -> None: cover, tracking = load_cover() old_prefixes = tracking['series'].get('prefixes', list()) if len(prefixes) == 1 and not prefixes[0].strip():
src/b4/kr.py +2 -1
@@ -5,6 +5,7 @@ # __author__ = 'Konstantin Ryabitsev <[email protected]>' +import argparse import os import sys import pathlib
@@ -15,7 +16,7 @@ import b4 logger = b4.logger -def main(cmdargs): +def main(cmdargs: argparse.Namespace) -> None: if cmdargs.showkeys: msgid, msgs = b4.retrieve_messages(cmdargs) logger.info('---')
src/b4/mbox.py +1 -1
@@ -574,7 +574,7 @@ def save_as_quilt(am_msgs: List[EmailMessage], q_dirname: str) -> None: sfh.write('%s\n' % patch_filename) -def get_extra_series(msgs: list, direction: int = 1, wantvers: Optional[List[int]] = None, +def get_extra_series(msgs: List[EmailMessage], direction: int = 1, wantvers: Optional[List[int]] = None, nocache: bool = False) -> List[EmailMessage]: base_msg: Optional[EmailMessage] = None latest_revision: Optional[int] = None
src/b4/ty.py +6 -6
@@ -78,7 +78,7 @@ def git_get_commit_message(gitdir: Optional[str], rev: str) -> Tuple[int, Union[ return b4.git_run_command(gitdir, args) -def make_reply(reply_template: str, jsondata: dict, gitdir: Optional[str]) -> email.message.EmailMessage: +def make_reply(reply_template: str, jsondata: Dict[str, str], gitdir: Optional[str]) -> email.message.EmailMessage: msg = email.message.EmailMessage() msg['From'] = '%s <%s>' % (jsondata['myname'], jsondata['myemail']) excludes = b4.get_excluded_addrs()
@@ -118,7 +118,7 @@ def make_reply(reply_template: str, jsondata: dict, gitdir: Optional[str]) -> em return msg -def auto_locate_pr(gitdir: Optional[str], jsondata: dict, branch: str) -> Optional[str]: +def auto_locate_pr(gitdir: Optional[str], jsondata: Dict[str, str], branch: str) -> Optional[str]: pr_commit_id = jsondata['pr_commit_id'] logger.debug('Checking %s', jsondata['pr_commit_id']) if not b4.git_commit_exists(gitdir, pr_commit_id):
@@ -192,7 +192,7 @@ def get_all_commits(gitdir: Optional[str], branch: str, since: str = '1.week', return MY_COMMITS -def auto_locate_series(gitdir: Optional[str], jsondata: dict, branch: str, +def auto_locate_series(gitdir: Optional[str], jsondata: Dict[str, str], branch: str, since: str = '1.week') -> List[Tuple[int, Optional[str]]]: commits = get_all_commits(gitdir, branch, since)
@@ -238,7 +238,7 @@ def auto_locate_series(gitdir: Optional[str], jsondata: dict, branch: str, return found -def set_branch_details(gitdir: Optional[str], branch: str, jsondata: dict, config: dict) -> Tuple[dict, dict]: +def set_branch_details(gitdir: Optional[str], branch: str, jsondata: Dict[str, str], config: Dict[str, str]) -> Tuple[dict, dict]: binfo = get_branch_info(gitdir, branch) jsondata['branch'] = branch for key, val in binfo.items():
@@ -269,7 +269,7 @@ def set_branch_details(gitdir: Optional[str], branch: str, jsondata: dict, confi return jsondata, config -def generate_pr_thanks(gitdir: Optional[str], jsondata: dict, branch: str) -> email.message.EmailMessage: +def generate_pr_thanks(gitdir: Optional[str], jsondata: Dict[str, str], branch: str) -> email.message.EmailMessage: config = b4.get_main_config() jsondata, config = set_branch_details(gitdir, branch, jsondata, config) thanks_template = DEFAULT_PR_TEMPLATE
@@ -298,7 +298,7 @@ def generate_pr_thanks(gitdir: Optional[str], jsondata: dict, branch: str) -> em return msg -def generate_am_thanks(gitdir: Optional[str], jsondata: dict, branch: str, since: str) -> email.message.EmailMessage: +def generate_am_thanks(gitdir: Optional[str], jsondata: Dict[str, str], branch: str, since: str) -> email.message.EmailMessage: config = b4.get_main_config() jsondata, config = set_branch_details(gitdir, branch, jsondata, config) thanks_template = DEFAULT_AM_TEMPLATE
src/tests/conftest.py +9 -6
@@ -1,11 +1,14 @@ import pytest import b4 import os +import pathlib import sys +from typing import Generator + @pytest.fixture(scope="function", autouse=True) -def settestdefaults(tmp_path): +def settestdefaults(tmp_path: pathlib.Path) -> None: topdir = b4.git_get_toplevel() if topdir and topdir != os.getcwd(): os.chdir(topdir)
@@ -23,15 +26,15 @@ def settestdefaults(tmp_path): @pytest.fixture(scope="function") -def sampledir(request): - return os.path.join(request.fspath.dirname, 'samples') +def sampledir(request: pytest.FixtureRequest) -> str: + return os.path.join(request.path.parent, 'samples') @pytest.fixture(scope="function") -def gitdir(request, tmp_path): - sampledir = os.path.join(request.fspath.dirname, 'samples') +def gitdir(request: pytest.FixtureRequest, tmp_path: pathlib.Path) -> Generator[str, None, None]: + sampledir = os.path.join(request.path.parent, 'samples') # look for bundle file specific to the calling fspath - bname = request.fspath.basename[5:-3] + bname = request.path.name[5:-3] bfile = os.path.join(sampledir, f'{bname}-gitdir.bundle') if not os.path.exists(bfile): # Fall back to the default
src/tests/test___init__.py +11 -8
@@ -5,6 +5,9 @@ import email import email.parser import mailbox import io +import pathlib + +from typing import Any, Dict, List, Literal, Optional, Tuple @pytest.mark.parametrize('source,expected', [
@@ -14,7 +17,7 @@ import io ('badsig', (False, False, False, 'B6C41CE35664996C', None)), ('no-pubkey', (False, False, False, None, None)), ]) -def test_check_gpg_status(sampledir, source, expected): +def test_check_gpg_status(sampledir: str, source: str, expected: Tuple[bool, bool, bool, Optional[str], Optional[str]]) -> None: with open(f'{sampledir}/gpg-{source}.txt', 'r') as fh: status = fh.read() assert b4.check_gpg_status(status) == expected
@@ -27,7 +30,7 @@ def test_check_gpg_status(sampledir, source, expected): # mailbox.mbox does not properly handle 8bit-clean headers ('save-8bit-clean', r'From: Unicôdé', 0, False), ]) -def test_save_git_am_mbox(sampledir, tmp_path, source, regex, flags, ismbox): +def test_save_git_am_mbox(sampledir: Optional[str], tmp_path: pathlib.Path, source: Optional[str], regex: str, flags: int, ismbox: bool) -> None: import re if source is not None: if ismbox:
@@ -72,7 +75,7 @@ def test_save_git_am_mbox(sampledir, tmp_path, source, regex, flags, ismbox): ('person', 'Signed-off-by', 'Wrapped Persontrailer <[email protected]>', None), ]), ]) -def test_parse_trailers(sampledir, source, expected): +def test_parse_trailers(sampledir: str, source: str, expected: List[Tuple[str, str, str, Optional[str]]]) -> None: with open(f'{sampledir}/{source}.txt', 'r') as fh: msg = email.message_from_file(fh) lmsg = b4.LoreMessage(msg)
@@ -116,7 +119,7 @@ def test_parse_trailers(sampledir, source, expected): ('bare-address', {}, {}, 'defaults', {}), ('stripped-lines', {}, {}, 'defaults', {}), ]) -def test_followup_trailers(sampledir, source, serargs, amargs, reference, b4cfg): +def test_followup_trailers(sampledir: str, source: str, serargs: Dict[str, Any], amargs: Dict[str, Any], reference: str, b4cfg: Dict[str, Any]) -> None: b4.MAIN_CONFIG.update(b4cfg) lmbx = b4.LoreMailbox() for msg in mailbox.mbox(f'{sampledir}/trailers-followup-{source}.mbox'):
@@ -187,7 +190,7 @@ def test_followup_trailers(sampledir, source, serargs, amargs, reference, b4cfg) '<20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', 'encode'), ]) -def test_header_wrapping(sampledir, hval, verify, tr): +def test_header_wrapping(sampledir: str, hval: str, verify: str, tr: Literal['encode', 'decode', 'preserve']) -> None: if ':' in hval: chunks = hval.split(':', maxsplit=1) hname = chunks[0].strip()
@@ -216,7 +219,7 @@ def test_header_wrapping(sampledir, hval, verify, tr): ([('', '[email protected]'), ('=?utf-8?q?Qu=C3=BBx=2C_Foo?=', '[email protected]')], '[email protected], =?utf-8?q?Qu=C3=BBx=2C_Foo?= <[email protected]>', False), ]) -def test_format_addrs(pairs, verify, clean): +def test_format_addrs(pairs: List[Tuple[str, str]], verify: str, clean: bool) -> None: formatted = b4.format_addrs(pairs, clean) assert formatted == verify
@@ -233,7 +236,7 @@ def test_format_addrs(pairs, verify, clean): ('-7', 5, []), ('1-8', 3, [1, 2, 3]), ]) -def test_parse_int_range(intrange, upper, expected): +def test_parse_int_range(intrange: str, upper: int, expected: List[int]) -> None: assert list(b4.parse_int_range(intrange, upper)) == expected
@@ -248,6 +251,6 @@ def test_parse_int_range(intrange, upper, expected): ('[PATCH RFC v3] This is a [patch]', ['RFC'], '[PATCH RFC v3] This is a [patch]'), ('[PATCH RFC v3 2/3] This is a patch', ['netdev', 'bpf'], '[PATCH RFC netdev bpf v3 2/3] This is a patch'), ]) -def test_lore_subject_prefixes(subject, extras, expected): +def test_lore_subject_prefixes(subject: str, extras: Optional[List[str]], expected: str) -> None: lsubj = b4.LoreSubject(subject) assert lsubj.get_rebuilt_subject(eprefixes=extras) == expected
src/tests/test_ez.py +4 -2
@@ -5,9 +5,11 @@ import b4.ez import b4.mbox import b4.command +from typing import Any, Dict, Generator, List, Optional, Tuple + @pytest.fixture(scope="function") -def prepdir(gitdir): +def prepdir(gitdir: str) -> Generator[str, None, None]: b4.MAIN_CONFIG.update({'prep-cover-strategy': 'branch-description'}) parser = b4.command.setup_parser() b4args = ['--no-stdin', '--no-interactive', '--offline-mode', 'prep', '-n', 'pytest']
@@ -32,7 +34,7 @@ def prepdir(gitdir): ['log', '--format=%ae%n%s%n%b---', 'HEAD~4..'], 'trailers-thread-with-followups-and-tripledash', None), ]) -def test_trailers(sampledir, prepdir, mboxf, bundlef, rep, trargs, compareargs, compareout, b4cfg): +def test_trailers(sampledir: str, prepdir: str, mboxf: str, bundlef: Optional[str], rep: Optional[Tuple[bytes, bytes]], trargs: List[str], compareargs: List[str], compareout: str, b4cfg: Dict[str, Any]) -> None: if b4cfg: b4.MAIN_CONFIG.update(b4cfg) config = b4.get_main_config()
src/tests/test_mbox.py +3 -1
@@ -4,6 +4,8 @@ import b4 import b4.mbox import b4.command +from typing import Any, Dict, List + @pytest.mark.parametrize('mboxf, shazamargs, compareargs, compareout, b4cfg', [ ('shazam-git1-just-series', [],
@@ -13,7 +15,7 @@ import b4.command ('shazam-git1-just-series', ['-M'], ['log', '--format=%ae%n%ce%n%s%n%b---', 'HEAD^..'], 'shazam-git1-just-series-merged', {}), ]) -def test_shazam(sampledir, gitdir, mboxf, shazamargs, compareargs, compareout, b4cfg): +def test_shazam(sampledir: str, gitdir: str, mboxf: str, shazamargs: List[str], compareargs: List[str], compareout: str, b4cfg: Dict[str, Any]) -> None: b4.MAIN_CONFIG.update(b4cfg) mfile = os.path.join(sampledir, f'{mboxf}.mbox') cfile = os.path.join(sampledir, f'{compareout}.verify')
Signature · 1 line
2.49.0
Konstantin Ryabitsev
AppliedQuoted 10 lines · Tamir Duberstein
uv[0] is an extremely fast Python package and project manager; allowing b4 to be developed with it makes life more pleasant for all contributors.
This series makes the b4 project compatible with
uvand fixes various typing problems. Please see also https://github.com/mricon/b4/issues/61
for the likely cause of many of these typing issues having previously gone unnoticed.[...]
Applied, thanks!
[01/10] Use PEP-735 dependency groups
commit: 9a3a30061bb4a2027442d0f1567c157dbbcf63d8
[02/10] Specify optional dependencies in pyproject.toml
commit: e63bd80b7f866f1da136581f79cfd81c11302575
[03/10] Specify dependencies in pyproject.toml
commit: f4185d6bc8ea0ac6b8a9ae8df7aaf334b8a983d1
[04/10] Add ruff, remove all noqa comments
commit: e8ead16ba4ad5f04de4d4b17420bb425f4d38ef9
[05/10] Remove `noinspection` comments
commit: 0be2cb4e31b36d531287a0e0fd6d81bfd4304d6d
[06/10] Add mypy
commit: ec65df28096a90b0a3057052b59229d87b4db1b5
[07/10] Add missing LoreTrailer.lmsg annotation
commit: e4b094a3bfbd040aad4a4018e264916b341406e1
[08/10] Check variables for None rather than exprs
commit: 8633c7e830a5a75b6e34593cda98d0b6c0b1bb05
[09/10] Make LoreSeries.indexes never None
commit: ca13d4787e403627f7ca7c70e7339ce399402166
[10/10] Add missing type annotations
commit: 7027afc6e0f0f2cc67a5e71df65f4025d9a89e3cBest regards,
Signature · 1 line
Konstantin Ryabitsev <[email protected]>