From: Simon Marchi <simon.marchi@efficios.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: binutils@sourceware.org
Subject: Re: [PATCH] gdb: add .pre-commit-config.yaml
Date: Wed, 20 Mar 2024 11:56:57 -0400 [thread overview]
Message-ID: <1581895c-7160-4ab4-a6c9-f970d59f797e@efficios.com> (raw)
In-Reply-To: <87jzlxt3ve.fsf@redhat.com>
On 3/20/24 09:44, Andrew Burgess wrote:
> Simon Marchi <simon.marchi@efficios.com> writes:
>
>> [I'm CCing the binutils list because this patch adds a file at the
>> top-level, but it only concerns gdb for now. But if you are want to use
>> pre-commit for some things in binutils too, you are welcome to use that
>> file for your needs.]
>>
>> Add a pre-commit [1] config file, with a single hook to run black
>> whenever a Python file is modified. We can always add more hooks if we
>> find some that are useful.
>>
>> Using pre-commit to run hooks is opt-in, as in it's not mandatory at all
>> for development, but it can be useful to run some checks that are easy
>> to forget (like running black). The hooks run locally on the
>> developer's machine when doing `git commit` (although they can also be
>> configured to run at other stages of the git workflow).
>>
>> Follow these instructions to install the hooks in your local development
>> git repository:
>>
>> - Install pre-commit the way you prefer. It can be using your OS
>> package manager if it has a recent enough version, or using `pip
>> install pre-commit`.
>> - Go to the binutils-gdb repository and run `pre-commit install`.
>>
>> This installs a git hook at `.git/hooks/pre-commit`.
>>
>> Now, whenever you modify and try to commit a Python file, pre-commit
>> will run black on it. For instance, if I try to insert something
>> misformatted, I get this when doing `git commit`:
>>
>> $ git commit
>> black....................................................................Failed
>> - hook id: black
>> - files were modified by this hook
>>
>> reformatted gdb/python/lib/gdb/dap/breakpoint.py
>>
>> All done! ✨ 🍰 ✨
>> 1 file reformatted.
>>
>> At this point, black has already reformatted the files in place, so the
>> changes that fix the formatting are ready to add and commit. black is
>> only ran on files modified in the commit.
>>
>> The hook defines a black version, which is downloaded at `pre-commit
>> install` time. pre-commit manages its own env at
>> `$HOME/.cache/pre-commit/<some-hash>`, so it won't use the version of
>> black you have installed already. This may help ensure that
>> contributors use the right black version.
>
> This sounds great. I got a recent commit wrong because the version of
> black was rolled forward and I'd not updated locally, so this would
> really help.
>
> +1 from me for making this a thing.
Thanks! Given that I only got positive feedback and this file won't
hurt anybody who doesn't care about it, I went ahead and pushed the
patch. I added Acked-Bys for all those who provided feedback.
I'll now go ahead and updated the wiki.
Simon
prev parent reply other threads:[~2024-03-20 15:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 15:09 Simon Marchi
2024-03-11 20:26 ` Tom Tromey
2024-03-12 10:50 ` Guinevere Larsen
2024-03-20 13:44 ` Andrew Burgess
2024-03-20 15:56 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1581895c-7160-4ab4-a6c9-f970d59f797e@efficios.com \
--to=simon.marchi@efficios.com \
--cc=aburgess@redhat.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).