From a81f4230076603c21be1daf86e10840408628f35 Mon Sep 17 00:00:00 2001 From: K <51281148+K-dash@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:43:14 +0900 Subject: [PATCH 1/4] feat: Add Makefile targets and improve pre-commit hooks - Add install, format, lint, and clean targets to the Makefile to automate various operations - Execute the install target to perform all project setup operations at once, preventing forgotten pre-commit installations - Modify pre-commit lint/format to reference the local repository and execute lint and format as defined in the Makefile - Modify HTML coverage report output process to clean up the directory beforehand - Set the 'all' target as the default for the make command, enabling simultaneous execution of format/lint/test --- .pre-commit-config.yaml | 19 ++++++++++----- makefile | 53 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 11 deletions(-) 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/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 From ba8f166866dd48fca39c493dbd909ece4902fe2c Mon Sep 17 00:00:00 2001 From: K <51281148+K-dash@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:49:50 +0900 Subject: [PATCH 2/4] chore: Configure pre-commit to run only Makefile's lint task --- .github/workflows/linter.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 2fc17b0c58fbcae815fe89e8b3be1d27d3b92e64 Mon Sep 17 00:00:00 2001 From: K <51281148+K-dash@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:50:21 +0900 Subject: [PATCH 3/4] chore: Improve pytest configuration Add `log_format` to enhance log readability --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) 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] From 1a8d4bd86baed15029973f15112e68c47fc6a50d Mon Sep 17 00:00:00 2001 From: K <51281148+K-dash@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:10:24 +0900 Subject: [PATCH 4/4] fix(docs): Update development setup steps and installation commands - Simplify development environment setup steps in CONTRIBUTING.md and add a warning about pre-commit configuration - Unify the method for installing dependencies and activating the virtual environment in README.md using `make install` --- CONTRIBUTING.md | 8 +++----- README.md | 11 +++-------- 2 files changed, 6 insertions(+), 13 deletions(-) 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