From aa46612215b805df8b289719daad911074cb9ac4 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 19 Oct 2025 18:50:43 +0200 Subject: [PATCH] Fix issues related to venv --- Makefile | 96 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 61a73349..76b4c629 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,25 @@ -# LetzShop API Makefile (Windows Compatible) +# Multitenant ecommerce application Makefile (Windows Compatible) .PHONY: install install-dev install-docs install-all dev test test-coverage lint format check docker-build docker-up docker-down clean help +# Detect if we're in a virtual environment and set Python path accordingly +PYTHON := python +PIP := pip + # ============================================================================= # INSTALLATION & SETUP # ============================================================================= install: - pip install -r requirements.txt + $(PIP) install -r requirements.txt install-dev: install - pip install -r requirements-dev.txt + $(PIP) install -r requirements-dev.txt install-test: - pip install -r requirements-test.txt + $(PIP) install -r requirements-test.txt install-docs: - pip install -r requirements-docs.txt + $(PIP) install -r requirements-docs.txt install-all: install install-dev install-test install-docs @@ -28,13 +32,13 @@ setup: install-all migrate-up # ============================================================================= dev: - uvicorn main:app --reload --host 0.0.0.0 --port 8000 + $(PYTHON) -m uvicorn main:app --reload --host 0.0.0.0 --port 8000 dev-with-docs: @echo Starting API and documentation servers... - @start /B uvicorn main:app --reload --host 0.0.0.0 --port 8000 + @start /B $(PYTHON) -m uvicorn main:app --reload --host 0.0.0.0 --port 8000 @timeout /t 3 >nul - @mkdocs serve --dev-addr=0.0.0.0:8001 + @$(PYTHON) -m mkdocs serve --dev-addr=0.0.0.0:8001 dev-full: dev-with-docs @echo Development environment ready! @@ -47,63 +51,62 @@ dev-full: dev-with-docs # ============================================================================= migrate-create: - @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create message="your_description") else (alembic revision --autogenerate -m "$(message)") + @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create message="your_description") else ($(PYTHON) -m alembic revision --autogenerate -m "$(message)") migrate-create-manual: - @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create-manual message="your_description") else (alembic revision -m "$(message)") + @if "$(message)"=="" (echo Error: Please provide a message. Usage: make migrate-create-manual message="your_description") else ($(PYTHON) -m alembic revision -m "$(message)") migrate-up: @echo Running database migrations... - alembic upgrade head + $(PYTHON) -m alembic upgrade head @echo Migrations completed successfully migrate-down: @echo Rolling back last migration... - alembic downgrade -1 + $(PYTHON) -m alembic downgrade -1 @echo Rollback completed migrate-status: @echo Current migration status: - alembic current + $(PYTHON) -m alembic current @echo. @echo Migration history: - alembic history --verbose + $(PYTHON) -m alembic history --verbose backup-db: @echo Creating database backup... - @python scripts/backup_database.py + @$(PYTHON) scripts/backup_database.py # ============================================================================= # TESTING # ============================================================================= test: - pytest tests/ -v + $(PYTHON) -m pytest tests/ -v test-unit: - pytest tests/ -v -m unit + $(PYTHON) -m pytest tests/ -v -m unit test-integration: - pytest tests/ -v -m integration + $(PYTHON) -m pytest tests/ -v -m integration test-coverage: - pytest tests/ --cov=app --cov=models --cov=utils --cov=middleware --cov-report=html --cov-report=term-missing + $(PYTHON) -m pytest tests/ --cov=app --cov=models --cov=utils --cov=middleware --cov-report=html --cov-report=term-missing test-fast: - pytest tests/ -v -m "not slow" + $(PYTHON) -m pytest tests/ -v -m "not slow" -# Run slow tests only test-slow: - pytest tests/ -v -m slow + $(PYTHON) -m pytest tests/ -v -m slow test-auth: - pytest tests/test_auth.py -v + $(PYTHON) -m pytest tests/test_auth.py -v test-products: - pytest tests/test_products.py -v + $(PYTHON) -m pytest tests/test_products.py -v test-inventory: - pytest tests/test_inventory.py -v + $(PYTHON) -m pytest tests/test_inventory.py -v # ============================================================================= # CODE QUALITY @@ -111,14 +114,20 @@ test-inventory: format: @echo Running black... - black . --exclude venv + $(PYTHON) -m black . --exclude venv @echo Running isort... - isort . --skip venv + $(PYTHON) -m isort . --skip venv lint: @echo Running linting... - flake8 . --max-line-length=120 --extend-ignore=E203,W503,I201,I100 --exclude=venv,__pycache__,.git - mypy . --ignore-missing-imports --exclude venv + $(PYTHON) -m ruff check . --exclude venv + $(PYTHON) -m mypy . --ignore-missing-imports --exclude venv + +# Alternative lint if still using flake8 +lint-flake8: + @echo Running linting... + $(PYTHON) -m flake8 . --max-line-length=120 --extend-ignore=E203,W503,I201,I100 --exclude=venv,__pycache__,.git + $(PYTHON) -m mypy . --ignore-missing-imports --exclude venv # Combined format and lint check: format lint @@ -136,15 +145,15 @@ qa: format lint test-coverage docs-check docs-serve: @echo Starting documentation server... - mkdocs serve --dev-addr=0.0.0.0:8001 + $(PYTHON) -m mkdocs serve --dev-addr=0.0.0.0:8001 docs-build: @echo Building documentation... - mkdocs build --clean --strict + $(PYTHON) -m mkdocs build --clean --strict docs-deploy: @echo Deploying documentation... - mkdocs gh-deploy --clean + $(PYTHON) -m mkdocs gh-deploy --clean docs-clean: @if exist site rmdir /s /q site @@ -152,7 +161,7 @@ docs-clean: docs-check: @echo Checking documentation for issues... - mkdocs build --strict --verbose + $(PYTHON) -m mkdocs build --strict --verbose # ============================================================================= # DOCKER @@ -193,7 +202,22 @@ clean: verify-setup: @echo Running setup verification... - @python scripts/verify_setup.py + @$(PYTHON) scripts/verify_setup.py + +# Check Python and virtual environment +check-env: + @echo Checking Python environment... + @echo Python version: + @$(PYTHON) --version + @echo. + @echo Python location: + @where $(PYTHON) + @echo. + @echo Virtual environment active: + @$(PYTHON) -c "import sys; print('YES' if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) else 'NO')" + @echo. + @echo Python executable: + @$(PYTHON) -c "import sys; print(sys.executable)" # ============================================================================= # HELP @@ -227,7 +251,8 @@ help: @echo. @echo === CODE QUALITY === @echo format - Format code (black + isort) - @echo lint - Run linting (flake8 + mypy) + @echo lint - Run linting (ruff + mypy) + @echo lint-flake8 - Run linting (flake8 + mypy - alternative) @echo check - Format + lint @echo ci - Full CI pipeline @echo qa - Quality assurance (format, lint, test, docs check) @@ -249,6 +274,7 @@ help: @echo === UTILITIES === @echo clean - Clean build artifacts @echo verify-setup - Verify project setup + @echo check-env - Check Python and virtual environment @echo. @echo === DAILY WORKFLOW === @echo make dev # Start development