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

Configure and run pre-commit #699

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage
# eg.: AWS_S3_CUSTOM_DOMAIN=cdn.mydomain.com
#AWS_S3_CUSTOM_DOMAIN=

# CSRF protection
# CSRF protection
# See https://docs.djangoproject.com/en/dev/ref/settings/#csrf-trusted-origins
CSRF_TRUSTED_ORIGINS="http://localhost:${NGINX_HOST_PORT}"
#CSRF_TRUSTED_ORIGINS="https://safe-config.staging.gnosisdev.com,http://safe-config.staging.gnosisdev.com"
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees: ''
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Provide references to the feature you are implementing that requires this change**
Provide at least one of the following:
Provide at least one of the following:
- Links to epics in your repository
- Images taken from mocks
- Gitbook or any form of written documentation links, etc. Any of these alternatives will help us contextualise your request.
Expand Down
108 changes: 26 additions & 82 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,25 @@ on:
push:
pull_request:
release:
types: [ released ]
types: [released]

jobs:
flake8:
name: flake8
linting:
hectorgomezv marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
- name: Install dependencies
run: |
pip install -U wheel setuptools
pip install -r requirements-dev.txt
- name: flake8
uses: liskin/gh-problem-matcher-wrap@v3
with:
linters: flake8
run: flake8
strategy:
matrix:
python-version: ["3.12.2"]
Copy link
Member Author

Choose a reason for hiding this comment

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

I would leave this as 3.12 so hotfixes are auto updated


isort:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U wheel setuptools
pip install -r requirements-dev.txt
- name: isort
uses: liskin/gh-problem-matcher-wrap@v3
with:
linters: isort
run: isort --check --profile black src/

black:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
- name: Install dependencies
run: |
pip install -U wheel setuptools
pip install -r requirements-dev.txt
- name: black
run: black --check src/
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files

django-check:
runs-on: ubuntu-latest
Expand All @@ -102,12 +46,12 @@ jobs:
ports:
- 5432:5432
env:
SECRET_KEY: 'insecure_key_for_dev'
SECRET_KEY: "insecure_key_for_dev"
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
AWS_ACCESS_KEY_ID: 'example-aws-access-key-id'
AWS_SECRET_ACCESS_KEY: 'example-aws-secret-access-key'
AWS_STORAGE_BUCKET_NAME: 'example-aws-storage-bucket-name'
AWS_ACCESS_KEY_ID: "example-aws-access-key-id"
AWS_SECRET_ACCESS_KEY: "example-aws-secret-access-key"
AWS_STORAGE_BUCKET_NAME: "example-aws-storage-bucket-name"
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand All @@ -120,7 +64,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
python-version: "3.12.2"
- name: Install dependencies
run: |
pip install -U wheel setuptools
Expand All @@ -140,7 +84,7 @@ jobs:

docker-publish-staging:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main')
needs: [ flake8, isort, black, django-check ]
needs: [linting, django-check]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -188,7 +132,7 @@ jobs:

docker-publish-release:
if: (github.event_name == 'release' && github.event.action == 'released')
needs: [ flake8, isort, black, django-check ]
needs: [linting, django-check]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -241,10 +185,10 @@ jobs:
needs: [docker-publish-staging]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Deploy Staging
run: bash scripts/autodeploy.sh
env:
AUTODEPLOY_URL: ${{ secrets.AUTODEPLOY_URL }}
AUTODEPLOY_TOKEN: ${{ secrets.AUTODEPLOY_TOKEN }}
TARGET_ENV: "staging"
- uses: actions/checkout@v4
- name: Deploy Staging
run: bash scripts/autodeploy.sh
env:
AUTODEPLOY_URL: ${{ secrets.AUTODEPLOY_URL }}
AUTODEPLOY_TOKEN: ${{ secrets.AUTODEPLOY_TOKEN }}
TARGET_ENV: "staging"
16 changes: 15 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +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/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [ "--profile", "black", "--filter-files" ]
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
Expand All @@ -13,3 +14,16 @@ repos:
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-docstring-first
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: requirements-txt-fixer
- id: trailing-whitespace
- id: end-of-file-fixer
types: [python]
- id: check-yaml
- id: check-added-large-files
hectorgomezv marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@ pytest src
being pushed. You can refer to the documentation
of these tools to check how to integrate them with your editor/IDE.

```shell
isort --profile black src # sorts imports according to the isort spec with a profile compatible with Black
black src # formats the files in the src folder using Black
flake8 src # runs flake8 Linter in the src folder
```

There's also a pre-commit hook that you can install locally via `pre-commit` so that it formats the files changed on each commit automatically:
You must configure `pre-commit` so the project format and linting are checked before every commit.

```shell
pre-commit install # installs commit hook under .git/hooks/pre-commit
git commit # Initially this can take a couple minutes to setup the environment (which will be reused in following commits)
pre-commit install -f # installs commit hook under .git/hooks/pre-commit
```
8 changes: 3 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
-r requirements.txt
black==24.8.0
coverage==7.6.1
django-stubs==5.0.4
djangorestframework-stubs==3.15.0
factory-boy==3.3.1
Faker==27.0.0
flake8==7.1.1
isort==5.13.2
mypy==1.11.1
pre-commit==3.8.0
pytest-django==4.8.0
responses==0.25.3

# mypy and PEP 561 stubs
mypy==1.11.1
django-stubs==5.0.4
djangorestframework-stubs==3.15.0
types-requests==2.32.0.20240712
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
boto3==1.34.158
Django==5.0.8
django-cors-headers==4.4.0
djangorestframework==3.15.2
djangorestframework-camel-case==1.4.2
django-storages==1.14.4
django-stubs-ext==5.0.4
djangorestframework==3.15.2
djangorestframework-camel-case==1.4.2
drf-yasg[validation]==1.21.7
safe-eth-py[django]==5.8.0
eth-typing==4.1.0
eth-utils==4.1.1
gunicorn==23.0.0
Pillow==10.4.0
psycopg2-binary==2.9.9
requests==2.32.3
safe-eth-py[django]==5.8.0
web3==6.9.0
Loading