From 19d01f8564a36d4f4c4e40c847c729d98a928d1e Mon Sep 17 00:00:00 2001 From: Gabriele Venturi Date: Mon, 14 Oct 2024 19:08:10 +0200 Subject: [PATCH] dev: unify pre-commit for backend and frontend --- .pre-commit-config.yaml | 46 ++++++++++------------- README.md | 76 ++++++++++++++++++++++++++++---------- frontend/.husky/pre-commit | 7 +++- 3 files changed, 81 insertions(+), 48 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5bf5a96..4712aeb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,40 +7,32 @@ repos: - id: check-yaml - id: check-added-large-files - - repo: https://github.com/psf/black - rev: 24.3.0 - hooks: - - id: black - language_version: python3.11 - - - repo: https://github.com/pycqa/isort - rev: 5.13.2 + - repo: local hooks: - - id: isort - args: ["--profile", "black"] + - id: frontend-lint + name: Frontend Lint + entry: bash -c 'cd frontend && npm run lint' + language: system + files: ^frontend/ + pass_filenames: false - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.4 - hooks: - - id: ruff - args: [--fix, --exit-non-zero-on-fix] + - id: backend-lint + name: Backend Lint + entry: bash -c 'cd backend && poetry run ruff check .' + language: system + files: ^backend/ + pass_filenames: false - - repo: local - hooks: - - id: pytest-check - name: pytest-check + - id: backend-test + name: Backend Test entry: bash -c 'cd backend && poetry run pytest' language: system + files: ^backend/ pass_filenames: false - always_run: false - files: ^(backend/|tests/) - types: [python] - - id: coverage-check - name: coverage-check + - id: backend-coverage + name: Backend Coverage entry: bash -c 'cd backend && poetry run coverage erase && poetry run coverage run -m pytest && poetry run coverage report -m && poetry run coverage xml' language: system + files: ^backend/ pass_filenames: false - always_run: false - files: ^(backend/|tests/) - types: [python] diff --git a/README.md b/README.md index 19d7e67..b2b1b18 100644 --- a/README.md +++ b/README.md @@ -17,21 +17,29 @@ PandaETL is an open-source, no-code ETL (Extract, Transform, Load) tool designed ### 📋 Prerequisites -- Node.js -- yarn -- Python (for backend) -- Poetry (for Python dependency management) +- Node.js and npm (or yarn) +- Python 3.x +- Conda +- Poetry (Python package manager) -### 🖥️ Frontend Setup +### 🖥️ Project Setup 1. Clone the repository: ```bash git clone https://github.com/yourusername/panda-etl.git - cd panda-etl/frontend/ + cd panda-etl ``` -2. Install dependencies: +### Frontend Setup + +1. Navigate to the frontend directory: + + ```bash + cd frontend + ``` + +2. Install dependencies (including Husky): ```bash yarn install @@ -44,47 +52,67 @@ PandaETL is an open-source, no-code ETL (Extract, Transform, Load) tool designed NEXT_PUBLIC_STORAGE_URL=http://localhost:3000/api/assets ``` - or - - copy the `.env.example` file to `.env` + or copy the `.env.example` file to `.env` 4. Run the development server: ```bash + npm run dev + # or yarn dev ``` 5. Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. -### 🛠️ Backend Setup +### Backend Setup 1. Navigate to the backend directory: ```bash - cd ../backend + cd backend ``` -2. Create an environment file from the example: +2. Create and activate a Conda environment: ```bash - cp .env.example .env + conda create -n pandaetl python=3.x + conda activate pandaetl ``` -3. Install dependencies: +3. Install Poetry within the Conda environment: + + ```bash + conda install poetry + ``` + +4. Install dependencies using Poetry (including pre-commit): ```bash poetry install ``` -4. Apply database migrations: +5. Set up pre-commit hooks: + + ```bash + poetry run pre-commit install + ``` + +6. Create an environment file from the example: ```bash - make migrate + cp .env.example .env ``` -5. Start the backend server: +7. Apply database migrations: + ```bash - make run + poetry run make migrate + ``` + +8. Start the backend server: + + ```bash + poetry run make run ``` ## 📚 Usage @@ -125,3 +153,13 @@ We would like to thank all the contributors and the open-source community for th ## 📞 Contact For any questions or feedback, please open an issue on GitHub. + +## Development Setup + +This project uses pre-commit hooks in the backend and Husky in the frontend to ensure code quality and consistency. + +### Frontend (Husky) + +Husky is set up in the frontend to run linting checks before each commit. + +To manually run the frontend linting: diff --git a/frontend/.husky/pre-commit b/frontend/.husky/pre-commit index 9c12759..11fc9b9 100644 --- a/frontend/.husky/pre-commit +++ b/frontend/.husky/pre-commit @@ -1,2 +1,5 @@ -cd frontend && npx lint-staged -cd ../backend && poetry run ruff check . +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# Run pre-commit hooks +pre-commit run --hook-stage pre-commit --files $(git diff --cached --name-only)