From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 44AC53858CD1; Mon, 11 Mar 2024 15:09:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44AC53858CD1 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 44AC53858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710169791; cv=none; b=SNtX4E4855uH02uOgW7N8Xr3r74rUMFSCqEDd5oklUE2rk1Xy5xxSHcFU2NTNqFoAODs00JaXZElUQQnzykaluz7OpPXmKYruiTnhX8QsWutKuMWUqwyUXHrlAO8jr1hHBjZu4tqwOGQBrik/kyWqUaRDXdooBbdWRkqhSo//uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710169791; c=relaxed/simple; bh=Ec/d+ABsdTSpTbIQSSk+I29aH5ljaljHM8wHHHs+wKY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FNqk3RkRBBx6D9Ye5007x/Rgi3W6TxEY3qC26g0nEXvwkwmUlx2slTfj4Jdss2z9eZksEIEQ/Q9DOykZpZNNwJ0gyb4rGsButQzXJ2fmzfO5UK1dTBvlwLCHeHM9W8u7Qgg2nscMc+iF5feuGWTNRxZ1msrbunW4RcfQjhgcXpQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 3FFF21E0AC; Mon, 11 Mar 2024 11:09:48 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: binutils@sourceware.org, Simon Marchi Subject: [PATCH] gdb: add .pre-commit-config.yaml Date: Mon, 11 Mar 2024 11:09:43 -0400 Message-ID: <20240311150947.71762-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3496.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: [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/`, so it won't use the version of black you have installed already. This may help ensure that contributors use the right black version. 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: - 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. It is possible to have pre-commit skip some hooks if needed [2]. 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. 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. [1] https://pre-commit.com [2] https://pre-commit.com/#temporarily-disabling-hooks Change-Id: Id00cda882f5140914a670c87e574fa7f2f972099 --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000000..b8d1ef7dc74d --- /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/.*' base-commit: b792eb47f25f577ccef365fc9a5c20d55fad42d5 -- 2.44.0