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 6DC14385E827 for ; Tue, 2 Apr 2024 20:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DC14385E827 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6DC14385E827 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=1712089578; cv=none; b=pm7mO3+Jfp5LtbckDIWu5Jht81q+9PYupDB5/iEQuQ0Gk2vjkMgtDL7UKE0dujC0g6B/61v5s8gWzlhvUdG3S4f5ks2T3YDbhizeFvWniIuqGryRhvOzEvxoGoKjPM0Da+jlWDfM1a3906s0bAxL8ypz4YBbOgj/ZBVbIbj4hI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712089578; c=relaxed/simple; bh=Foh+wMUNwMZIisojKYCcy2LXaAtpy+EcvP7irLsJvRY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=I4wwv6qmHs8AC3WOE5rQIAJfaZ+4AA7j47nwdIaXs1Wsa5uE+COJE9gceARFIQomwh3z7Um4FnlVWOPTo3lHOqUHkdR+uaWYL+j7URQfqW0zPpKuykkINWu2xtBdygHr5ZjS1t7AcN5RN1TTlbAkiM6Aji5ABDg+bB1rfRuOuEM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1712089575; bh=Foh+wMUNwMZIisojKYCcy2LXaAtpy+EcvP7irLsJvRY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Lsi7iKheDbe0+MPSfWodseFs/G9AN+lUlLsQLWRqa1m6APonc2WoxLokEJVs8MS1M fN2MOUGFc3Ql45EkxDgAS4jcLlYHJq3hxwSF7jcQKkOdmgWI8v7lLYtZNP3ASu1DpA WhyA/7fGw5kq263yX6Fr26v3VRjPxfrQf/ytCqr4= Received: from [10.0.0.11] (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D63C41E030; Tue, 2 Apr 2024 16:26:15 -0400 (EDT) Message-ID: Date: Tue, 2 Apr 2024 16:26:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Add flake8 and isort to .pre-commit-config.yaml To: Tom Tromey , gdb-patches@sourceware.org References: <20240402181121.1948535-1-tromey@adacore.com> Content-Language: en-US From: Simon Marchi In-Reply-To: <20240402181121.1948535-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP 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: On 2024-04-02 14:11, Tom Tromey wrote: > This adds flake8 and isort to .pre-commit-config.yaml. This way, they > will automatically be run on commit. > > I chose the most recent available versions after verifying that they > don't cause any reports or changes in the current tree. > > Internally at AdaCore, we also use a few flake8 plugins as well, so > perhaps that's another avenue for investigation. > --- > .pre-commit-config.yaml | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml > index 7afe60c20be..bca8acc5d02 100644 > --- a/.pre-commit-config.yaml > +++ b/.pre-commit-config.yaml > @@ -6,3 +6,14 @@ repos: > hooks: > - id: black > files: 'gdb/.*' > + - repo: https://github.com/pycqa/flake8 > + rev: 7.0.0 > + hooks: > + - id: flake8 > + files: gdb/python/.*\.py$ > + args: [--config, gdb/setup.cfg] > + - repo: https://github.com/pycqa/isort > + rev: 5.13.2 > + hooks: > + - id: isort > + files: gdb/.*\.py$ I only used `gdb/.*.py` for the black hook, because pre-commit does its own filtering already. The hooks specify the `python` type, so pre-commit only runs the hook on what it believes is a Python file. The only purpose of the regex was to limit the hooks to the gdb sub-directory. However, I realized we have at least one file that is python but isn't named *.py, gdb-gdb.py.in. I just tried, and the black hook doesn't run on gdb-gdb.py-in. If you run black manually, it considers gdb-gdb.py.in as a Python file (I don't know by which magic) and re-formats it: $ pwd /home/simark/src/binutils-gdb $ black gdb reformatted /home/simark/src/binutils-gdb/gdb/gdb-gdb.py.in But the filtering done by pre-commit doesn't consider gdb-gdb.py.in a Python file. The hooks specify `types: 'python'`, which doesn't match '*.py.in'. The doc for `types` is here: https://pre-commit.com/#filtering-files-with-types The mapping between extensions and types is here: https://github.com/pre-commit/identify/blob/main/identify/extensions.py If we want to make pre-commit consider that file for our Python hooks, the only solution I see currently would be to use something like this, as described in the doc above: hooks: - id: black types_or: [file] files: '^gdb/.*\.(py|py.in)$' It didn't seem to work for me using `types` (an error in gdb-gdb.py.in wouldn't be caught), but it works using `types_or`. So, I would consider something similar for other hooks as well. Simon