Commit Graph

19 Commits

Author SHA1 Message Date
Bobby R. Bruce
3429da7787 python,tests,misc: Remove Gerrit-ID insertion from pre-commit
Change-Id: I4db06415c9d0bbba7a6db56d7e9febf6491003bf
2024-08-20 15:40:55 -07:00
Bobby R. Bruce
7d67109ca2 python,misc: Add isort to pre-commit
Change-Id: I391a8948f0817bd5c6a9fe8a4c3e4fed07a98c49
2023-11-29 22:06:05 -08:00
Bobby R. Bruce
be89758f0e misc: Add additional pre-commit hook checks (#420)
Adds the following hooks:

1. `check-ast`: Verifies all Python files have a AST indicating they are
valid Python.
2. `check-merge-conflict`: Checks to see if files have merge conflict
strings and blocks commits if so.
3. `check-symlinks`: Checks that symlinks in the repo still point to a
valid location.
4. `destroyed-symlinks`: Checks if symlink is replaced with a file and
if that file is identical to the file it was previously pointing too.

None of these commits change any code. They are all checks to ensure bad
code is not committed.
2023-10-18 12:21:22 -07:00
Bobby R. Bruce
83af4525ce misc,python: Add pyupgrade hook to pre-commit
This hook automatically upgrades the syntax to recommended standards for
new versions of the language.

These are numerous and are outlined here:
https://github.com/asottile/pyupgrade

Change-Id: I73fc58a08160ed9a21cfa3b3e023c259a84592ba
2023-10-10 21:43:39 -07:00
Bobby R. Bruce
3f5d7d647a misc: Run pre-commit autoupdate (#419)
1. Runs `pre-commit autoupdate`.
2. Runs `pre-commit run --all-files`.
3. Adds (2.) to ".git-blame-ignore-rev".
2023-10-10 21:41:33 -07:00
Bobby R. Bruce
592fbae2f5 python,misc: Add destroyed-symlinks hook to pre-commit
This hook detects which symlinks are changed to regular files with the
content of a path which that symlink was pointing to.

Change-Id: Ic925f02debc65c7c04e6d4cc3a25415b30858977
2023-10-10 21:40:28 -07:00
Bobby R. Bruce
768e488a6b python,misc: Add check-symlinks hook to pre-commit
This hook checks that symlinks in the repo still point to valid
location.

Change-Id: I350760800406d9c003e81236af8248c6fc0a7359
2023-10-10 21:39:32 -07:00
Bobby R. Bruce
5b5c5d09dd python,misc: Add check-merge-conflict hook to pre-commit
This hook will check to see if files have merge conflict strings and
blocks commit if so.

Change-Id: I8687e0a8367d3c43133890001023e0352954d90d
2023-10-10 21:38:48 -07:00
Bobby R. Bruce
132ec10818 python,misc: Add check-ast hook to pre-commit
This verifies all Python files have a AST indicating they valid Python.
No file in the repo fails this test, so it triggered no changes.

Change-Id: Ifd7998268df6be766d92c19cfc7f1cfdf8ed103e
2023-10-10 21:37:45 -07:00
Bobby R. Bruce
317d2fb5b8 misc: Run pre-commit autoupdate
This updates the pre-commit utility from v4.3.0 to v4.5.0 and updates
black from 22.6.0 to 23.9.1.

Change-Id: I7ebb551f30e617059ce49f89a30207f739b1cb14
2023-10-10 14:00:57 -07:00
Bobby R. Bruce
da212e04b5 Merge branch 'develop' into requirements-fixer-hook 2023-10-09 22:37:25 -07:00
Bobby R. Bruce
5b09777011 misc,python: Add pre-commit-hook-yamlfmt to pre-commit
This automatically formats .yaml files. By deault has the following
parameters:

* `mapping`: 4 spaces.
* `sequence`: 6 spaces.
* `offset`: 4 spaces.
* `colons`: do not align top-level colons.
* `width`: None.

Change-Id: Iee5194cd57b7b162fd7e33aa6852b64c5578a3d2
2023-10-09 13:16:52 -07:00
Bobby R. Bruce
c53529783b misc,python: Add requirements-txt-fixer to pre-commit
This sorts entries in requirements.txt files.

Change-Id: I7ee6e31f3cbe5078f24d13471a6aa9edc482cecd
2023-10-09 13:09:21 -07:00
Bobby R. Bruce
ff75e5b30e misc,ext: Update pre-commit hook to run on ext/testlib
Though in ext, we regularly modify these files to add features and
extend our testlib testing infrastructure. Ergo, the pre-commit checks
should be run.

Change-Id: I921a263f25f850b03e5535a8a1f509921c124763
2023-09-05 00:00:25 -07:00
Bobby R. Bruce
be33be87da misc: Update black to process src/python/m5/ext/pystats
The exclusion in .pre-commit-config.yaml covered all files in
src/python/m5/ext. This excludes src/python/m5/exit/pystats, which we
want covered by black. This commit updates .pre-commit-config.yaml to
only exclude src/python/m5/ext/pyfdt.

This change also runs black on these files.

Change-Id: Iecff45ea2a27a37fc0d00b867d41300aad911c7a
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63711
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
2022-11-03 22:32:36 +00:00
Bobby R. Bruce
c0df86fb3e misc: Add gerrit commit message hook to pre-commit
This pre-commit hook adds the Change-ID etc. to the commit message.

Change-Id: I43b239468ab60ce1a8aaabb53dd6905819a2ce05
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62575
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-08-24 21:47:07 +00:00
Bobby R. Bruce
64add0e04d misc: Exclude test ref directories from pre-commit
The files in "tests/*./ref" directories are used in tests to check the
output of a test is valid. As such these should not be automatically
formatted by the pre-commit.

Change-Id: I82be1a91132a0b6c66c8bbb8f6d7dcc6e72abe77
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62631
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
2022-08-24 21:47:07 +00:00
Bobby R. Bruce
ab04acc26e misc: Add the legacy gem5 .git/hooks to the pre-commit
The gem5 commit msg checker must be run during the 'commit-msg'
stage ergo this is explicitly set. The other hooks are only applicable
to the "commit" stage, the `default_stage` for the hooks.

To install all the hooks, you need to run the following:

```
pre-commit install -t pre-commit -t commit-msg
```

This ensures both the 'commit-msg' and 'pre-commit' hooks are installed.
If you run just `pre-commit install`, only the pre-commit hooks are
installed.

Change-Id: I4a0dcc7159ed5048baa120adf80bbf65f63c11dd
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62552
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
2022-08-24 21:47:07 +00:00
Andreas Sandberg
616391e48a misc: Add pre-commit configuration
Add a pre-precommit configuration that can be used to run a series of
automated tests in CI. This configuration currently enforces Black
style on Python files and checks for other common errors (incorrect
json, mixed line endings etc.).

The CI system runs pre-commit using the following command:

  pre-commit run --from-ref HEAD~ --to-ref HEAD

Users can install pre-commit hooks in their git repositories using the
following command:

  pre-commit install

Note that our scons scripts automatically install a simple style
checker as a pre-commit hooks already. If the pre-commit tool is
installed after the existing hook, the existing hook will be kept and
called automatically.

The current pre-commit configuration doesn't currently doesn't run the
C++ style checker automatically. This feature could easily be added in
the future by adding the following to the pre-commit file:

  - repo: local
    hooks:
    - id: style-checker
      name: Check C++ coding style
      language: python
      entry: util/style.py -f

The main reason this isn't already in the configuration is that it is
expected that the style checker will have some false positives since
style checks will be enforced on the entire file rather than the lines
changed in a commit.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Change-Id: Ibbb1dc641e2979509f3259cd951c7272094d69f5
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/61111
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
2022-07-12 09:28:47 +00:00