Skip to content

Commit

Permalink
Linting and formatting with pre-commit (#17)
Browse files Browse the repository at this point in the history
* locally + GH action against main
* run hooks on existing files
  • Loading branch information
thekaveman authored Mar 8, 2021
1 parent 97c6d16 commit e872bd1
Show file tree
Hide file tree
Showing 61 changed files with 348 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .aws/ecs-task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"cpu": "512",
"volumes": [
]
}
}
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postStartCommand": ["/bin/bash", "bin/init.sh"],

// Set *default* container specific settings.json values on container create.
"settings": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
},
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ server/
.*ignore
*.db
docker-compose.yml
Dockerfile*
Dockerfile*
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
max-line-length = 127
max-line-length = 127
3 changes: 1 addition & 2 deletions .github/workflows/deploy-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defaults:

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -57,4 +56,4 @@ jobs:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: cal-itp-benefits-client
cluster: cal-itp-clientCluster
wait-for-service-stability: true
wait-for-service-stability: true
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint and formatting

on:
push:
branches: main
pull_request:
branches: main

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.env
*.mo
static/
!benefits/static
!benefits/static
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
types:
- python
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
types:
- python
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/usr/local/bin/python",
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ RUN chown -R $USER /home/$USER/app/benefits/locale
USER $USER

# configure container executable
ENTRYPOINT ["/bin/bash", "bin/start.sh"]
ENTRYPOINT ["/bin/bash", "bin/start.sh"]
3 changes: 2 additions & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ FROM benefits_client:latest
USER root

RUN apt-get install -qq --no-install-recommends curl git jq ssh && \
pip install --no-cache-dir flake8 debugpy
pip install --no-cache-dir flake8 debugpy pre-commit && \
pre-commit install
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ Requires [Docker][docker] and [Docker Compose][docker-compose].

Clone the repository:

```bash
```console
git clone https://github.com/cal-itp/benefits
cd benefits
```

Create an environment file from the sample:

```bash
```console
cp .env.sample .env
```

Build the Docker image using Docker Compose:

```bash
```console
docker-compose build [--no-cache] client
```

### Start the client

```bash
```console
docker-compose up [-d] client
```

Expand All @@ -40,30 +40,46 @@ By default, sample data from [`data/client.json`](./data/client.json) is used to

* Modify the sample data file; or
* Point `DJANGO_INIT_PATH` at a different data file; or
* Hardcode the JSON in `DJANGO_INIT_JSON` e.g.
* Hardcode the JSON in `DJANGO_INIT_JSON` e.g.
`DJANGO_INIT_JSON='[{"model":"core.eligibilitytype",...}]'`; or

* (If `DJANGO_ADMIN=true`) use the backend administrative interface CRUD

Stop the running services with:

```bash
```console
docker-compose down
```

### Test verification server

A basic eligibility verification server is available for testing:

```bash
```console
docker-compose up [-d] --build server
```

The API endpoint is running at `http://localhost:5000/verify`.

Sample users and eligibility can be found in [`data/server.json`](./data/server.json).

## VS Code with Dev Containers
## Development

This repository uses [`pre-commit`][pre-commit] hooks to check and format code.

Ensure you have `pre-commit` installed:

```console
pip install pre-commit
```

Then run (from the root of this repository):

```console
pre-commit install
```

### VS Code with Dev Containers

**This is the recommended development setup**.

Expand All @@ -89,21 +105,24 @@ Once running inside a container, press **`F5`** to attach a debugger to the clie
The test eligibility verification server endpoint is running at `http://localhost:5000/verify` on your host machine.
Access the server endpoint from within the Dev Container at `http://server:5000/verify`.

`pre-commit` hooks are also installed and activated within the Dev Container.

To close out of the container and re-open the directory locally in Visual Studio Code:

1. `Ctrl+Shift+P` to bring up the command palette in Visual Studio Code
1. Type `Remote-Containers` to filter the commands
1. Select `Reopen Locally`

[config-file]: ./.devcontainer.json
[docker]: https://docs.docker.com/
[docker-compose]: https://docs.docker.com/compose/
[vscode]: https://code.visualstudio.com/
[vscode-containers]: https://code.visualstudio.com/docs/remote/containers

## Token signing and encryption

The Eligiblity Verification API makes use of Signed and Encrypted JSON Web Tokens (JWS, JWE, JWT) as a means of data transfer.

A public/private keypair must be generated by each party (Benefits Client and Eligibility Verification Server). [Example keys](./keys)
are included for the test verification server and sample agencies.

[config-file]: ./.devcontainer.json
[docker]: https://docs.docker.com/
[docker-compose]: https://docs.docker.com/compose/
[vscode]: https://code.visualstudio.com/
[pre-commit]: https://pre-commit.com/
[vscode-containers]: https://code.visualstudio.com/docs/remote/containers
4 changes: 1 addition & 3 deletions benefits/core/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


class Response():
class Response:
"""Base API response."""

def __init__(self, status_code, error=None, message=None):
Expand Down
2 changes: 1 addition & 1 deletion benefits/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
raise AttributeError("Agency not configured for session")


class DebugSession():
class DebugSession:
"""Middleware to configure debug context in the request session."""

def __init__(self, get_response):
Expand Down
Loading

0 comments on commit e872bd1

Please sign in to comment.