Skip to content
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
15 changes: 15 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: pre-commit

on:
pull_request:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- uses: pre-commit/action@v3.0.1
Copy link

@Quidge Quidge Sep 15, 2025

Choose a reason for hiding this comment

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

I've rolled without using the dedicated pre-commit action before, but something I've added in my own CI is the --show-diff-on-failure flag. It will show a git diff on a failure so you can see the issue in the CI readout. Unsure if the dedicated pre-commit CI action is already doing that under the hood (should be easy enough to check source for that action and confirm if they're using it or not; they likely also have a way to pass arbitrary flags).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fail_fast: false
minimum_pre_commit_version: 4.0.0
default_stages: [pre-commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.13.0"
hooks:
- id: ruff-check
args: [--exit-non-zero-on-fix]
- id: ruff-format
args: [--exit-non-zero-on-fix]
Comment on lines +22 to +25
Copy link

Choose a reason for hiding this comment

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

Isn't exit-non-zero the default? And/or, when pre-commit runs, if a delta is detected, doesn't the delta itself cause pre-commit to trip a failure anyways?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. But Ruff can also auto-magically fix some formatting and linting issues. In which case, it exits with a zero status code from what I've seen. We don't have the fix attribute set so it won't auto-fix any issues currently but I'd still suggest we leave this argument on, in case fix is enabled in the future.

18 changes: 16 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* [Docker](https://www.docker.com/get-started)
* [docker-compose](https://docs.docker.com/compose)
* Python 3.8 or 3.12
* Python 3.12.x
* [pipx](https://pypa.github.io/pipx/) - Install Python applications in isolated environments
* [uv](https://github.com/astral-sh/uv) - Fast Python package installer and resolver
* tox (install via `pipx install tox`)
Expand Down Expand Up @@ -49,7 +49,7 @@ If instead you'd prefer to set-up your project on the host machine, you are free

### 1. Python Version

If you have [`pyenv`](https://github.com/pyenv/pyenv) installed already, the [python version](.python-version) should be set automatically for you based on the `.python-version` file. However if you do not, you should make sure that Python 3.8 or 3.12 is available on your host.
If you have [`pyenv`](https://github.com/pyenv/pyenv) installed already, the [python version](.python-version) should be set automatically for you based on the `.python-version` file. However if you do not, you should make sure that 3.12.x is available on your host.

### 2. Install uv and Setup Environment

Expand Down Expand Up @@ -122,6 +122,20 @@ To run the tests with automatic setup and teardown of services simply run:
tox
```

### 8. Pre-commit

We use [pre-commit](https://pre-commit.com/) to automatically enforce formatting and linting. Pre-commit runs automatically on all pull requests, but it's highly recommended to install the hook locally. Installing the hook locally catches formatting and linting issues early, allowing for quick remediation before you commit.

To install the pre-commit hook locally:

1. Ensure your [environment is set up](#2-install-uv-and-setup-environment).
2. From the project root, run:
```bash
uv run pre-commit install
```

After installation, pre-commit will run automatically on all future commits.

## Windows Systems

TODO: see [#330](https://github.com/pyslackers/website/issues/330)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pyslackersweb"
version = "0.1.0"
description = "The website for the pythondev.slack.com community"
requires-python = ">=3.8"
requires-python = ">=3.12"
dependencies = [
# Web Framework
"aiohttp==3.10.11",
Expand Down Expand Up @@ -38,7 +38,8 @@ test = [
"pytest-asyncio>=0.23.5",
]
lint = [
"ruff>=0.12.11",
"pre-commit>=4.3.0",
"ruff>=0.13.0",
]
typing = [
"mypy>=1.8.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyslackersweb/website/static/images/pyslackers_small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyslackersweb/website/static/images/sponsor_sentry.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyslackersweb/website/static/vendor/bootstrap-4.3.1.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1812,4 +1812,3 @@
.ri-zoom-in-line:before { content: "\f0e7"; }
.ri-zoom-out-fill:before { content: "\f0e8"; }
.ri-zoom-out-line:before { content: "\f0e9"; }

Loading