diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 50464fc..f8d1ef6 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 530c7fa..9070f3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5cf58a9..f978e55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/README.md b/README.md index f116338..70a13db 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/makefile b/makefile index b709514..53e4d95 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index df3596d..1ff487c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]