Skip to content

Commit

Permalink
Merge pull request #32 from K-dash/feature/introduce-pre-commit-and-u…
Browse files Browse the repository at this point in the history
…pdate-docs

Introduce pre-commit and update documentation
  • Loading branch information
ryansurf authored May 30, 2024
2 parents 95acbcf + 9af6a0d commit 5879033
Show file tree
Hide file tree
Showing 7 changed files with 51 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
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.6
hooks:
# Run the linter.
- id: ruff
args: [ ., --fix, --diff ]
# Run the formatter.
- id: ruff-format
args: [ . ]
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

1 comment on commit 5879033

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src
   __init__.py00100% 
   api.py85693%30, 48, 69–70, 101–102
   art.py9367%24–25, 37
   cli.py25484%32, 50–51, 55
   gpt.py5340%14–19
   helper.py1364666%47, 58–62, 95–103, 115, 128–129, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 178–180, 190, 192–193, 211–212, 249–257, 264–266
   send_email.py24240%5–48
   server.py41410%5–81
   settings.py190100% 
TOTAL34412763% 

Tests Skipped Failures Errors Time
6 0 💤 0 ❌ 0 🔥 9.452s ⏱️

Please sign in to comment.