Skip to content

Commit

Permalink
Introduce pre-commit and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
K-dash committed May 30, 2024
1 parent 95acbcf commit 9e0c323
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r dev-requirements.txt
- name: Lint with ruff
run: |
make lint
make format
- name: Run pre-commit
run: pre-commit run --all-files
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.6
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
51 changes: 31 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,37 @@ To find issues you can help with, go though the list of [good first issues](http
Once you find an interesting issue let us know that you want to work on it by commenting on the issue.

## Development
### Install our development environment
Install the development dependencies:
```
pip install -r requirements.txt -r dev-requirements.txt
```

Install the `pre-commit`:
```
pre-commit install
```

### Code Style and Quality
- The [PEP 8](https://realpython.com/python-pep8/) styling convention is used.
- This is achieved using the `ruff` Linter and Formatter.
- The Linter and Formatter are automatically executed before committing via pre-commit.
- If you want to run the Linter and Formatter at any time, execute `pre-commit run --all-files`.

### Testing
> [!NOTE]
> This project uses `Makefile` as a task runner. You need to set up your environment to be able to run the `make` command.
Run the following command in the project's root directory:
```
make test
```
You can generate a coverage report with the following command:
```
make post_test
```
Additionally, when a PR is raised, pytest will be executed by the GitHub Actions CI.

**Code Style and Quality**

The [PEP 8](https://realpython.com/python-pep8/) styling convention is used.

To make sure you are following it, you can install [black](https://pypi.org/project/black/)

`pip install black`

To run black:

`black .`

**Testing**

To run tests, install pytest, `pip install pytest` and navigate to `/test`.

Run `pytest`

On commit, git will run `pytest` for you to catch any errors.

## Questions, suggestions or new ideas

Expand All @@ -46,4 +57,4 @@ Feel free to [create a new issue](https://github.com/ryansurf/cli-surf/issues/ne

Be sure to explain in details the context and the outcome that you are lookign for. If reporting bugs, provide basic information like your OS version, whether using Docker, etc.

Thanks! :ocean: :surfer:
Thanks! :ocean: :surfer:
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Change `.env.example` to `.env`
| `PORT` | The port you want to open to run the application. Default = `8000` |
| `IP_ADDRESS` | The ip your server is running on. Default = `localhost` |
| `SMTP_SERVER` | The email server you are using. Default = smtp.gmail.com |
| `SMTP_PORT` | The email server port you are using. Default = `587` |
| `EMAIL` | The email you will send the report from. |
| `EMAIL_PW` | The sending email's password |
| `EMAIL_RECEIVER` | The email that will receive the report (your personal email) |
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ruff==0.4.6
pytest==8.2.1
pytest-cov==5.0.0
pre-commit==3.7.1
11 changes: 3 additions & 8 deletions docs/styling.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# Styling

## Code Style and Quality

The [PEP 8](https://realpython.com/python-pep8/) styling convention is used.

To make sure you are following it, you can install [black](https://pypi.org/project/black/)

`pip install black`

To run black:
This is achieved using the ruff Linter and Formatter.

`black .`
The Linter and Formatter are automatically executed before committing via pre-commit.

On a push/pull request, git will run `black .` for you!
If you want to run the Linter and Formatter at any time, execute `pre-commit run --all-files`.
9 changes: 3 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
.PHONY: lint format
.PHONY: run test post_test

lint:
ruff check . && ruff check . --diff

format:
ruff check . --fix && ruff format .
run:
cd src && python3 server.py

test:
pytest -s -x --cov=src -vv
Expand Down

0 comments on commit 9e0c323

Please sign in to comment.