Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple pre-commit hook #1065

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,30 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.8"

# Note: we could try and cache the pre-commit environment
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing it, but my first attempt didn't work. I still had the

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...

but the entire pre-commit step only takes 12 seconds at the moment. So it seems okay to leave it as is for now.

# See the pre-commit docs at https://pre-commit.com/#github-actions-example
- name: Run pre-commit hooks
run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit run --all-files
Copy link
Contributor Author

@SqAtx SqAtx Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does modify the files, but we don't commit them. The important thing is that the command's exit code is set to 1 if it made changes, which makes the workflow fail.


- name: Install dependencies
run: |
python -m pip install --upgrade pip
sudo apt-get update
sudo apt install -y meson gettext itstool libgirepository1.0-dev gir1.2-gtk-4.0 libgtksourceview-5-dev libportal-dev
pip install --user -e git+https://github.com/getting-things-gnome/liblarch.git#egg=liblarch
pip install --user pytest pycairo PyGObject caldav lxml

- name: Build and install GTG
run: |
meson setup --prefix=${PWD}/inst ./build
cd build
meson compile
sudo meson install

- name: Run unit tests with Pytest
run: |
export PYTHONPATH=${PWD}/inst/lib/python3.8/site-packages
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in #237, this trailing-whitespace is the one that I find important.

This file is just the output of pre-commit sample-config, and the default seemed reasonable. I'm okay removing the others if anyone insists.

- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ No data should be lost since it is just re-generateable build files.
[pudb]: https://pypi.org/project/pudb/
[gtk-interactive]: https://developer.gnome.org/gtk3/stable/gtk-running.html#interactive-debugging

## Setting up a development environment
Copy link
Contributor Author

@SqAtx SqAtx Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could eventually move into its own file within https://github.com/getting-things-gnome/gtg/tree/master/docs/contributors. I think it's OK to have it here for now.

I will create a task for modernizing https://github.com/getting-things-gnome/gtg/blob/master/docs/contributors/coding%20best%20practices.md, which still mentions Python 2 and tox. It's a good place to also mention the automated code quality checks that we're adding.


Now that you have installed all the dependencies and know how to run the tests,
it's possible that you would like to make code changes and submit them for
review.

We use [pre-commit](https://pre-commit.com) to run some checks that ensure that
our codebase is clean and consistent.

Install it with `pip install pre-commit`, and install the pre-commit hooks with
`pre-commit install`.

The checks will now run every time you make a commit, and fix files if
necessary. It's generally a good idea to always run them, but you can also
bypass them by running `git commit --no-verify`, if necessary.

The CI system runs the checks on each commit to master, and on each pull
request. If you want to make sure they pass before opening your PR, you can run
them locally with `pre-commit run --all-files`.

For more guidelines about contributing, see
[CONTRIBUTING.md](./CONTRIBUTING.md).

# "Where is my user data and config stored?"

It depends:
Expand Down
Loading