Skip to content

Commit

Permalink
🎨 Apply flake8 for code style
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 13, 2024
1 parent d7c5dba commit 99a4ec1
Show file tree
Hide file tree
Showing 86 changed files with 324 additions and 307 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ jobs:
run: |
black --check --diff src
flake8:
name: Code style (flake8)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up backend environment
uses: maykinmedia/setup-django-backend@v1
with:
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gdal-bin'
python-version: '3.11'
setup-node: 'no'
- name: Run flake8
id: flake8
run: |
flake8 src 2>&1 | tee flake8_output.txt
result_code=${PIPESTATUS[0]}
report="$(cat flake8_output.txt)"
report="${report//$'\n'/'%0A'}" # escape newlines
echo "flake8_output=${report}" >> $GITHUB_OUTPUT
exit $result_code
- name: Emit flake8 flake8 output
if: ${{ failure() }}
run: |
echo "${{ steps.flake8.outputs.flake8_output }}"
echo 'flake8 found some issues' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '| File | Line | Column | Issue |' >> $GITHUB_STEP_SUMMARY
echo '| :--- | ---- | ------ | :---- |' >> $GITHUB_STEP_SUMMARY
python ./bin/flake8_summary.py "${{ steps.flake8.outputs.flake8_output }}" >> $GITHUB_STEP_SUMMARY
migrations:
name: Check for model changes not present in the migrations
runs-on: ubuntu-latest
Expand Down
53 changes: 27 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,40 @@ If you want to contribute, we ask you to follow these guidelines.

## Reporting bugs

If you have encountered a bug in this project, please check if an issue already
exists in the list of existing [issues][issues]. If such an issue does not
exist, you can create a [new issue][new_issue]. When writing the bug report,
If you have encountered a bug in this project, please check if an issue already
exists in the list of existing [issues][issues]. If such an issue does not
exist, you can create a [new issue][new_issue]. When writing the bug report,
try to add a clear example that shows how to reproduce said bug.

## Adding new features

Before making making changes to the code, we advise you to first check the list
of existing [issues][issues] for this project to see if an issue for the
suggested changes already exists. If such an issue does not exist, you can
create a [new issue][new_issue]. Creating an issue gives an opportunity for
Before making making changes to the code, we advise you to first check the list
of existing [issues][issues] for this project to see if an issue for the
suggested changes already exists. If such an issue does not exist, you can
create a [new issue][new_issue]. Creating an issue gives an opportunity for
other developers to give tips even before you start coding.

### Code style

To keep the code clean and readable, this project uses:

- [`isort`](https://github.com/timothycrosley/isort) to order the imports
- [`black`](https://github.com/psf/black) to format the Python code and keep diffs for
- [`black`](https://github.com/psf/black) to format the Python code and keep diffs for
pull requests small
- [`prettier`](https://github.com/prettier/prettier) to format the JS code and keep diffs for
- [`flake8`](https://github.com/PyCQA/flake8) to clean up code (removing unused imports, etc.)
- [`prettier`](https://github.com/prettier/prettier) to format the JS code and keep diffs for
pull requests small
Whenever a branch is pushed or a pull request is made, the code will be checked
in CI by the tools mentioned above, so make sure to install these tools and run
Whenever a branch is pushed or a pull request is made, the code will be checked
in CI by the tools mentioned above, so make sure to install these tools and run
them locally before pushing branches/making pull requests.

This project aims to meet the criteria of the
[Standard for Public Code][Standard_for_Public_Code]. Please make sure that
This project aims to meet the criteria of the
[Standard for Public Code][Standard_for_Public_Code]. Please make sure that
your pull requests are compliant, that will make the reviews quicker.

### Forking the repository

In order to implement changes to this project when you do not have rights for
In order to implement changes to this project when you do not have rights for
this [repository][repository], you must first fork the repository. Once the
repository is forked, you can clone it to your local machine.

Expand All @@ -46,26 +47,26 @@ On your local machine, create a new branch, and name it like:
- `feature/some-new-feature`, if the changes implement a new feature
- `issue/some-issue`, if the changes fix an issue

Once you have made changes or additions to the code, you can commit them (try
to keep the commit message descriptive but short). If an issue already exists
in the list of existing [issues][issues] for the changes you made, be sure to
format your commit message like
`:gitmoji: Fixes #<issue_id> -- description of changes made`, where
`<issue_id>` corresponds to the number of the issue on GitHub. To demonstrate
that the changes implement the new feature/fix the issue, make sure to also add
Once you have made changes or additions to the code, you can commit them (try
to keep the commit message descriptive but short). If an issue already exists
in the list of existing [issues][issues] for the changes you made, be sure to
format your commit message like
`:gitmoji: Fixes #<issue_id> -- description of changes made`, where
`<issue_id>` corresponds to the number of the issue on GitHub. To demonstrate
that the changes implement the new feature/fix the issue, make sure to also add
tests to the existing Django testsuite.

### Making a pull request

If all changes have been committed, you can push the branch to your fork of the
repository and create a pull request to the `develop` branch of this project's
repository. Your pull request will be reviewed, if applicable, feedback will be
If all changes have been committed, you can push the branch to your fork of the
repository and create a pull request to the `develop` branch of this project's
repository. Your pull request will be reviewed, if applicable, feedback will be
given and if everything is approved, it will be merged.

### Reviews on releases

All pull requests will be reviewed by a project member before they are merged
to a release branch.
All pull requests will be reviewed by a project member before they are merged
to a release branch.


[issues]: https://github.com/maykinmedia/open-inwoner/issues
Expand Down
12 changes: 12 additions & 0 deletions bin/flake8_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
import sys


def main(flake8_output: str):
for line in flake8_output.splitlines():
file, line, column, error = line.split(":", 3)
print(f"| {file} | {line} | {column} | {error.strip()} |")


if __name__ == "__main__":
main(sys.argv[1])
25 changes: 22 additions & 3 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ billiard==3.6.4.0
# -c requirements/base.txt
# -r requirements/base.txt
# celery
black==22.12.0
# via -r requirements/test-tools.in
boltons==21.0.0
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -81,6 +83,7 @@ click==8.1.3
# via
# -c requirements/base.txt
# -r requirements/base.txt
# black
# celery
# click-didyoumean
# click-plugins
Expand Down Expand Up @@ -499,6 +502,8 @@ factory-boy==3.2.0
# via -r requirements/test-tools.in
faker==9.9.0
# via factory-boy
flake8==3.9.2
# via -r requirements/test-tools.in
fontawesomefree==6.4.2
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -568,7 +573,9 @@ isodate==0.6.1
# -r requirements/base.txt
# maykin-python3-saml
isort==5.9.3
# via pylint
# via
# -r requirements/test-tools.in
# pylint
josepy==1.13.0
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -628,7 +635,9 @@ maykin-python3-saml==1.14.0.post0
# -r requirements/base.txt
# django-digid-eherkenning
mccabe==0.6.1
# via pylint
# via
# flake8
# pylint
messagebird==2.1.0
# via
# -c requirements/base.txt
Expand All @@ -642,6 +651,8 @@ mozilla-django-oidc-db==0.12.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
mypy-extensions==1.0.0
# via black
notifications-api-common==0.2.2
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -670,6 +681,8 @@ packaging==23.0
# -c requirements/base.txt
# -r requirements/base.txt
# djangocms-text-ckeditor
pathspec==0.12.1
# via black
pep8==1.7.1
# via -r requirements/test-tools.in
phonenumbers==8.12.33
Expand All @@ -685,7 +698,9 @@ pillow==10.1.0
# reportlab
# weasyprint
platformdirs==2.4.0
# via pylint
# via
# black
# pylint
playwright==1.41.0
# via
# -c requirements/base.txt
Expand All @@ -704,6 +719,8 @@ psycopg2==2.9.9
# via
# -c requirements/base.txt
# -r requirements/base.txt
pycodestyle==2.7.0
# via flake8
pycparser==2.20
# via
# -c requirements/base.txt
Expand All @@ -719,6 +736,8 @@ pyee==11.0.1
# -c requirements/base.txt
# -r requirements/base.txt
# playwright
pyflakes==2.3.1
# via flake8
pyjwt==2.8.0
# via
# -c requirements/base.txt
Expand Down
3 changes: 0 additions & 3 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
pip-tools

# Code formatting
black
isort
flake8
bandit

# Debug tooling
Expand Down
30 changes: 22 additions & 8 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ billiard==3.6.4.0
# -r requirements/ci.txt
# celery
black==22.12.0
# via -r requirements/dev.in
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
blinker==1.7.0
# via flask
boltons==21.0.0
Expand Down Expand Up @@ -555,7 +557,9 @@ faker==9.9.0
# -r requirements/ci.txt
# factory-boy
flake8==3.9.2
# via -r requirements/dev.in
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
flask==3.0.0
# via
# flask-basicauth
Expand Down Expand Up @@ -654,7 +658,6 @@ isort==5.9.3
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# -r requirements/dev.in
# pylint
itsdangerous==2.1.2
# via flask
Expand Down Expand Up @@ -750,8 +753,11 @@ mozilla-django-oidc-db==0.12.0
# -r requirements/ci.txt
msgpack==1.0.7
# via locust
mypy-extensions==0.4.3
# via black
mypy-extensions==1.0.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# black
notifications-api-common==0.2.2
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -782,8 +788,11 @@ packaging==23.0
# build
# djangocms-text-ckeditor
# sphinx
pathspec==0.9.0
# via black
pathspec==0.12.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# black
pbr==5.9.0
# via stevedore
pep517==0.11.0
Expand Down Expand Up @@ -834,6 +843,8 @@ psycopg2==2.9.9
# -r requirements/ci.txt
pycodestyle==2.7.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# autopep8
# flake8
pycparser==2.20
Expand All @@ -852,7 +863,10 @@ pyee==11.0.1
# -r requirements/ci.txt
# playwright
pyflakes==2.3.1
# via flake8
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# flake8
pygments==2.12.0
# via sphinx
pyjwt==2.8.0
Expand Down
5 changes: 5 additions & 0 deletions requirements/test-tools.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ pyquery # integrates with webtest
requests-mock
tblib

# Code formatting
black
isort
flake8

# DigidLocal
pyopenssl
Loading

0 comments on commit 99a4ec1

Please sign in to comment.