[PATCH] Add flake8 and isort to .pre-commit-config.yaml
Tom de Vries
tdevries@suse.de
Tue Apr 9 07:58:44 GMT 2024
On 4/3/24 21:57, Simon Marchi wrote:
> On 4/3/24 3:52 PM, Tom Tromey wrote:
>>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
>>
>> Simon> If we want to make pre-commit consider that file for our Python hooks,
>> Simon> the only solution I see currently would be to use something like this,
>> Simon> as described in the doc above:
>>
>> I did this in v2. Let me know what you think.
>>
>> Tom
>>
>> commit c3c3740f73b5f20697074c5a20a26d0805afbb98
>> Author: Tom Tromey <tromey@adacore.com>
>> Date: Tue Apr 2 12:04:21 2024 -0600
>>
>> Add flake8 and isort to .pre-commit-config.yaml
>>
>> 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.
>>
>> v2: Also update the various file-selection clauses to pick up
>> gdb-gdb.py.in; include the isort change made to this file; and finally
>> add a comment about the exclusions from flake8.
>>
>> diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
>> index 7afe60c20be..8721dac678b 100644
>> --- a/.pre-commit-config.yaml
>> +++ b/.pre-commit-config.yaml
>> @@ -5,4 +5,20 @@ repos:
>> rev: 24.3.0
>> hooks:
>> - id: black
>> - files: 'gdb/.*'
>> + types_or: [file]
>> + files: 'gdb/.*\.py(\.in)?$'
>> + - repo: https://github.com/pycqa/flake8
>> + rev: 7.0.0
>> + hooks:
>> + - id: flake8
>> + types_or: [file]
>> + # Note this one is only run on gdb/python, not (for now) the
>> + # test suite.
>> + files: 'gdb/python/.*\.py(\.in)?$'
>> + args: [--config, gdb/setup.cfg]
>> + - repo: https://github.com/pycqa/isort
>> + rev: 5.13.2
>> + hooks:
>> + - id: isort
>> + types_or: [file]
>> + files: 'gdb/.*\.py(\.in)?$'
>> diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
>> index 54db9b00cf3..b5a7fa4f390 100644
>> --- a/gdb/gdb-gdb.py.in
>> +++ b/gdb/gdb-gdb.py.in
>> @@ -15,9 +15,10 @@
>> # You should have received a copy of the GNU General Public License
>> # along with this program. If not, see <http://www.gnu.org/licenses/>.
>>
>> -import gdb
>> import os.path
>>
>> +import gdb
>> +
>>
>> class TypeFlag:
>> """A class that allows us to store a flag name, its short name,
>
> Thanks, LGTM.
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Hi,
just to report back on this with my current state.
I use openleap 15.4 with python 3.6, and the used version of flake8
requires python 3.7, so I ran into trouble after this commit.
Then I learned about "git commit -n", and started using that as
workaround, but eventually ran into trouble because that doesn't seem to
work while rebasing.
I then decided to install python 3.11 and use a virtual environment, and
use git commit from within that environment. AFAICT, the virtual
environment works as expected:
...
$ python --version
Python 3.11.5
$ python3 --version
Python 3.11.5
...
but for some reason I keep getting:
...
SyntaxError: future feature annotations is not defined
...
which is the same error I got with python 3.6.
I've tried removing ~/.cache/pre-commit a couple of times, but that
didn't help either.
So, atm I can no longer rebase. I'll try to workaround this by adding a
local commit that reverts this change, or something similar, but if
anybody has another idea I'd be happy to hear it.
Thanks,
- Tom
More information about the Gdb-patches
mailing list