Skip to content

Commit

Permalink
Merge pull request #56 from K-dash/improve-makefile-and-precommit
Browse files Browse the repository at this point in the history
Improve makefile and pre-commit
  • Loading branch information
ryansurf authored Jul 24, 2024
2 parents db7690b + 1a8d4bd commit 72e5204
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
pip install poetry
poetry config installer.max-workers 10
poetry install --no-interaction --no-ansi
- name: Run pre-commit
run: poetry run pre-commit run --all-files
- name: Run Lint
run: make lint
19 changes: 13 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.6
- repo: local
hooks:
# Run the linter.
- id: ruff
entry: ruff check . --fix
- id: lint
name: Lint
entry: make lint
types: [python]
language: system
pass_filenames: false
# Run the formatter.
- id: ruff-format
args: [ . ]
- id: format
name: Format
entry: make format
types: [python]
language: system
pass_filenames: false
8 changes: 3 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ Once you find an interesting issue let us know that you want to work on it by co

## Development
### Install our development environment
1. Please set up your development environment by referring to the `Setup` section in the `README.md`.
Please set up your development environment by referring to the `Setup` section in the `README.md`.

2. Install the `pre-commit`:
```
pre-commit install
```
> [!WARNING]
> Make sure to run `make install` to ensure that lint and format are executed reliably when using the `git commit` command.
### Code Style and Quality
- The [PEP 8](https://realpython.com/python-pep8/) styling convention is used.
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,12 @@ To use cli-surf, clone the project locally and install the necessary dependencie
cd cli-surf
```

3. Install dependencies using Poetry.
3. Install dependencies and Activate the virtual environment.
```bash
poetry install
make install
```

4. Activate the virtual environment.
```bash
poetry shell
```

5. Run the project. For example, if the entry point is `server.py`, use the following command.
4. Run the project. For example, if the entry point is `server.py`, use the following command.
```bash
python src/server.py
Expand Down
53 changes: 48 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
.PHONY: run run_docker test test_docker post_test docker_post_test send_email send_email_docker
.DEFAULT_GOAL := all
sources = src tests

.PHONY: install
install:
poetry install
poetry shell
pre-commit install

.PHONY: run
run:
poetry run python src/server.py

.PHONY: format
format:
poetry run ruff check --fix $(sources)
poetry run ruff format $(sources)

.PHONY: lint
lint:
poetry run ruff check $(sources)
poetry run ruff format --check $(sources)

.PHONY: run_docker
run_docker:
docker compose up -d

.PHONY: test
test:
poetry run pytest -s -x --cov=src -vv
poetry run pytest

.PHONY: test_docker
test_docker:
docker compose exec flask poetry run pytest -s -x --cov=src -vv
docker compose exec flask poetry run pytest

.PHONY: output_coverage
output_coverage:
poetry run coverage html
@rm -rf htmlcov
@mkdir -p htmlcov
poetry run coverage run -m pytest
poetry run coverage report
poetry run coverage html -d htmlcov

.PHONY: output_coverage_docker
output_coverage_docker:
docker compose exec flask poetry run coverage html
@docker compose exec flask rm -rf htmlcov
@docker compose exec flask mkdir -p htmlcov
docker compose exec flask poetry run coverage run -m pytest
docker compose exec flask poetry run coverage report
docker compose exec flask poetry run coverage html -d htmlcov

.PHONY: send_email
send_email:
poetry run python src/send_email.py

.PHONY: send_email_docker
send_email_docker:
docker compose exec flask poetry run python src/send_email.py

.PHONY: clean
clean:
rm -rf htmlcov
rm -rf .pytest_cache
rm -f .coverage
rm -f .coverage.*

.PHONY: all
all: format lint test
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ build-backend = "poetry.core.masonry.api"

# pytest settings
[tool.pytest.ini_options]
testpaths = 'tests'
pythonpath = "."
addopts = '-p no:warnings' # disable pytest warnings
log_format = '%(name)s %(levelname)s: %(message)s'

# ruff global settings
[tool.ruff]
Expand Down

1 comment on commit 72e5204

@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.py101694%30, 48, 70–71, 103–104
   art.py9367%24–25, 37
   cli.py23483%34, 50–51, 55
   gpt.py10640%16–21, 32–45
   helper.py1555863%53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 91, 102–106, 132, 134, 136, 145–153, 165, 178–179, 197–199, 209, 211–212, 234–235, 272–282, 289–297
   send_email.py24240%5–48
   server.py41410%5–82
   settings.py220100% 
TOTAL38514263% 

Tests Skipped Failures Errors Time
9 0 💤 0 ❌ 0 🔥 13.874s ⏱️

Please sign in to comment.