From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 2BEC63858033; Wed, 20 Mar 2024 15:55:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BEC63858033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710950123; bh=IR/wtgiJTXfRM7XG/rrW/nN/wnDAt18su4FsD2dIkoQ=; h=From:To:Subject:Date:From; b=QBMV0kKFTY09C1r6J1KKaDSjPUJLSY9NEaDU8IPTWhHjBBBm+pHa7qI6QUxxnCK6Q V/HYPXY7ebGdtnVLe5dEQGz/mhLr8VcqhZD6UtcU8EAeBVyiSLXSoNjCaBVrc4GaqM aEai0XaBZbEJkQYzVuDcpRXc7PnSzp0mFFTDhBrQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] Add .pre-commit-config.yaml X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 105470cd79f6d8c62b9156ce45e992895b01b13b X-Git-Newrev: e8f6050cfb990452fcfc685bc9ccbae79113fa36 Message-Id: <20240320155523.2BEC63858033@sourceware.org> Date: Wed, 20 Mar 2024 15:55:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De8f6050cfb99= 0452fcfc685bc9ccbae79113fa36 commit e8f6050cfb990452fcfc685bc9ccbae79113fa36 Author: Simon Marchi Date: Mon Mar 11 11:09:43 2024 -0400 Add .pre-commit-config.yaml =20 Add a pre-commit [1] config file, with a single hook to run black on the gdb directory whenever a Python file is modified. We can always add more hooks if we find some that are useful. =20 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). =20 Follow these instructions to install the hooks in your local development git repository: =20 - 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`. =20 This installs a git hook at `.git/hooks/pre-commit`. =20 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`: =20 $ git commit black..............................................................= ......Failed - hook id: black - files were modified by this hook =20 reformatted gdb/python/lib/gdb/dap/breakpoint.py =20 All done! =E2=9C=A8 =F0=9F=8D=B0 =E2=9C=A8 1 file reformatted. =20 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. =20 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/`, so it won't use the version of black you have installed already. This may help ensure that contributors use the right black version. =20 The procedure when there is a new version of black (or a new version of any hook we might be using in the future) is: =20 - Modify .pre-commit-config.yaml to change the version number, push to the upstream repo. - Have contributors run `pre-commit autoupdate` to make their local pre-commit installation update the hooks. =20 It is possible to have pre-commit skip some hooks if needed [2]. =20 I will add these instructions to the wiki if this patch gets merged, so they are easy to find. We could perhaps think of having a gdb/CONTRIBUTING document of some sort checked in the repo with that kind of information. =20 I have not used pre-commit in a real project before, but have heard good things from it. If we want to give it a try before pushing it to the repo, some volunteers can copy the .pre-commit-config.yaml file locally and try it for some time. However, pushing the file upstream is not going to impact anybody who doesn't care about it, so I'd say it's relatively low-risk to push it right now. =20 [1] https://pre-commit.com [2] https://pre-commit.com/#temporarily-disabling-hooks =20 Change-Id: Id00cda882f5140914a670c87e574fa7f2f972099 Acked-By: Tom Tromey Acked-By: Guinevere Larsen Acked-By: Andrew Burgess Diff: --- .pre-commit-config.yaml | 8 ++++++++ ChangeLog | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..b8d1ef7dc74 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.2.0 + hooks: + - id: black + files: 'gdb/.*' diff --git a/ChangeLog b/ChangeLog index 91b9f774ada..e1b17767d47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-03-20 Simon Marchi + + * .pre-commit-config.yaml: New. + 2024-03-14 Simon Marchi =20 * Makefile.def: Add configure-gdbserver and all-gdbserver