Skip to content

Commit

Permalink
[Docs] pre-commit setup and use (#1107)
Browse files Browse the repository at this point in the history
## Description

Added documentation on how to use `pre-commit` for GEF

Fixes #1063

---------

Co-authored-by: Grazfather <grazfather@gmail.com>
  • Loading branch information
hugsy and Grazfather committed May 21, 2024
1 parent c9bab34 commit 2c26e33
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v5.0.0
- uses: actions/setup-python@v5.1.0
with:
python-version: "3.8"
- uses: pre-commit/action@v3.0.0
- uses: pre-commit/action@v3.0.1

docs_link_check:
name: Check URLs in docs
Expand All @@ -23,9 +23,9 @@ jobs:
contents: read
steps:
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v4.1.6
- name: Check links
uses: lycheeverse/lychee-action@v1.9.1
uses: lycheeverse/lychee-action@v1.10.0
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
Expand Down
41 changes: 41 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,47 @@ compiled against. To obtain this version, you can execute the following command:
gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit
```

### Code quality

To ensure a consistent code quality and make it easy for both contributors and developers, GEF and
GEF-Extras both rely on [`pre-commit`](https://pre-commit.com). The `pre-commit` tool is a
framework used to manage and maintain multi-language pre-commit hooks. These hooks are scripts that
run automatically before each commit to identify issues in code, such as missing semicolons,
trailing whitespace, and debug statements. This helps in ensuring code quality and consistency
before submission to code review, and therefore is triggered automatically when submitting a Pull
Request to GEF. This check is treated equally with the unit tests and therefore failing to pass
will result in your PR not being merged.

`pre-commit` is part of the [dev package requirements](https://github.com/hugsy/gef/blob/main/tests/requirements.txt)

```console
cd /root/to/gef/repo
python -m pip install --user -r tests/requirements.txt
```

But if you need to install separately it can be done using

```console
python -m pip install pre-commit
```

And to enable it

```console
pre-commit install
```

By default, `pre-commit` will use git hook to run the validation checks after each commit but you
can modify this behavior as desired or even run it manually

```console
pre-commit run --all-files
```

By default, `pre-commit` will report and attempt to fix the code to match what the coding style
defined with GEF.


### Benchmarking GEF

Benchmarking relies on `pytest-benchmark` and is experimental for now.
Expand Down

0 comments on commit 2c26e33

Please sign in to comment.