Re: [PATCH] [pre-commit] : add 'tomli' dependency for codespell pre-commit hook

Tom de Vries <[email protected]> Tue, 28 Jul 2026 10:01:44 +0200
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
On 7/13/26 12:35 PM, Tom de Vries wrote:
> On 7/13/26 11:42 AM, Tom de Vries wrote:
>> On 6/30/26 10:20 AM, Stephan Rohr wrote:
>>> From: "Rohr, Stephan" <[email protected]>
>>>
>>> The codespell pre-commit hook imports the 'tomllib' module to parse
>>> 'pyproject.toml'.  'tomllib' is not available for Python versions 3.10
>>> and older.  Add a dependency on 'tomli' so the hook also works on these
>>> Python versions.
>>>
>>
>> Hi,
>>
>> this LGTM.
>>
>> Approved-By: Tom de Vries <[email protected]>
>>

It's been two weeks since approval, so to prevent this from falling 
through the cracks I've pushed this, after rebasing and applying the 
anchor change I suggested below.

Thanks,
- Tom

> 
> Also, consider removing duplication using an anchor:
> ...
> diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
> index f96959d79fc..70c3033a9fe 100644
> --- a/.pre-commit-config.yaml
> +++ b/.pre-commit-config.yaml
> @@ -80,12 +80,12 @@ repos:
>         files: '^(gdb|gdbserver|gdbsupport)/'
>         args: [--toml, gdb/pyproject.toml]
>         # 'tomllib' library is not available on Python < 3.11.
> -      additional_dependencies: ['tomli']
> +      additional_dependencies: &codespell_deps ['tomli']
>       - id: codespell
>         name: codespell-log
>         entry: gdb/contrib/codespell-log.sh
>         args: [--toml, gdb/pyproject.toml]
> -      additional_dependencies: ['tomli']
> +      additional_dependencies: *codespell_deps
>         verbose: true
>         stages: [commit-msg]
> 
> ...
> 
> Thanks,
> - Tom
> 
>> FWIW, I had some trouble reproducing this.  I tried to reproduce this 
>> in a python virtual environment (3.10) on a system with system python 
>> 3.14.   As it turns out, pre-commit creates a python 3.14 environment, 
>> so tomli is found.
>>
>> After setting language_version to 3.10 in the yaml file, I managed to 
>> reproduce it, and indeed your patch fixes it.
>>
>> Thanks,
>> - Tom
>>
>>> ---
>>>   .pre-commit-config.yaml | 3 +++
>>>   1 file changed, 3 insertions(+)
>>>
>>> diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
>>> index 9910bbb82f2..1c6b018d7ac 100644
>>> --- a/.pre-commit-config.yaml
>>> +++ b/.pre-commit-config.yaml
>>> @@ -79,10 +79,13 @@ repos:
>>>       - id: codespell
>>>         files: '^(gdb|gdbserver|gdbsupport)/'
>>>         args: [--toml, gdb/pyproject.toml]
>>> +      # 'tomllib' library is not available on Python < 3.11.
>>> +      additional_dependencies: ['tomli']
>>>       - id: codespell
>>>         name: codespell-log
>>>         entry: gdb/contrib/codespell-log.sh
>>>         args: [--toml, gdb/pyproject.toml]
>>> +      additional_dependencies: ['tomli']
>>>         verbose: true
>>>         stages: [commit-msg]
>>
>