adds comments to makefile
This commit is contained in:
parent
039f9190e6
commit
234dc4d172
125
Makefile
125
Makefile
@ -1,107 +1,132 @@
|
|||||||
|
# List of phony targets (targets that don't represent files)
|
||||||
.PHONY: all clean venv run format format-check lint mypy test dist reformat dev
|
.PHONY: all clean venv run format format-check lint mypy test dist reformat dev
|
||||||
|
|
||||||
|
# Define Python and pip executables inside virtual environment
|
||||||
PYTHON := venv/bin/python
|
PYTHON := venv/bin/python
|
||||||
PIP := venv/bin/pip
|
PIP := venv/bin/pip
|
||||||
|
|
||||||
|
# Default target that runs the application
|
||||||
all: run
|
all: run
|
||||||
|
|
||||||
|
# Remove all generated files and directories
|
||||||
clean:
|
clean:
|
||||||
rm -rf venv build dist .pytest_cache .mypy_cache *.egg-info
|
rm -rf venv build dist .pytest_cache .mypy_cache *.egg-info
|
||||||
|
|
||||||
DB_PATH=scipaperloader/papers# Backup the database
|
# Define database path
|
||||||
|
DB_PATH=scipaperloader/papers.db
|
||||||
|
|
||||||
|
# Backup the database with timestamp
|
||||||
backup-db:
|
backup-db:
|
||||||
@mkdir -p backups
|
@mkdir -p backups
|
||||||
@timestamp=$$(date +%Y%m%d_%H%M%S); \
|
@timestamp=$$(date +%Y%m%d_%H%M%S); \
|
||||||
cp $(DB_PATH) backups/papers_$$timestamp.db && \
|
cp $(DB_PATH) backups/papers_$$timestamp.db && \
|
||||||
echo "Database backed up to backups/papers_$$timestamp.db"
|
echo "Database backed up to backups/papers_$$timestamp.db"
|
||||||
|
|
||||||
# Create sample test data
|
# Create sample test data for development and testing
|
||||||
sample-data: venv
|
sample-data: venv
|
||||||
$(PYTHON) scipaperloader/scripts/create_sample_data.py
|
$(PYTHON) scipaperloader/scripts/create_sample_data.py
|
||||||
|
|
||||||
# Export database as SQL
|
# Export database as SQL script with timestamp
|
||||||
export-db: venv
|
export-db: venv
|
||||||
@mkdir -p exports
|
@mkdir -p exports
|
||||||
@timestamp=$$(date +%Y%m%d_%H%M%S); \
|
@timestamp=$$(date +%Y%m%d_%H%M%S); \
|
||||||
$(PYTHON) -c "import sqlite3; conn = sqlite3.connect('$(DB_PATH)'); with open('exports/papers_$$timestamp.sql', 'w') as f: f.write(''.join(conn.iterdump()));" && \
|
$(PYTHON) -c "import sqlite3; conn = sqlite3.connect('$(DB_PATH)'); with open('exports/papers_$$timestamp.sql', 'w') as f: f.write(''.join(conn.iterdump()));" && \
|
||||||
echo "Database exported to exports/papers_$$timestamp.sql" # Run with production settings
|
echo "Database exported to exports/papers_$$timestamp.sql"
|
||||||
run-prod: venv
|
|
||||||
FLASK_ENV=production venv/bin/flask --app scipaperloader run --host=0.0.0.0
|
|
||||||
|
|
||||||
# Check for security vulnerabilities
|
# Run the application with production settings
|
||||||
|
run-prod: venv
|
||||||
|
FLASK_ENV=production venv/bin/flask --app scipaperloader run --host=0.0.0.0
|
||||||
|
|
||||||
|
# Check for security vulnerabilities in dependencies
|
||||||
security-check: venv
|
security-check: venv
|
||||||
$(PIP) install safety
|
$(PIP) install safety
|
||||||
venv/bin/safety check
|
venv/bin/safety check
|
||||||
|
|
||||||
# Run specific migration commands
|
# Create a new database migration with provided message
|
||||||
db-migrate: venv
|
db-migrate: venv
|
||||||
venv/bin/flask --app scipaperloader db migrate -m "$(message)"
|
venv/bin/flask --app scipaperloader db migrate -m "$(message)"
|
||||||
|
|
||||||
|
# Apply pending database migrations
|
||||||
db-upgrade: venv
|
db-upgrade: venv
|
||||||
venv/bin/flask --app scipaperloader db upgrade
|
venv/bin/flask --app scipaperloader db upgrade
|
||||||
|
|
||||||
|
# Revert the last database migration
|
||||||
db-downgrade: venv
|
db-downgrade: venv
|
||||||
venv/bin/flask --app scipaperloader db downgrade # Generate API documentation using sphinx
|
venv/bin/flask --app scipaperloader db downgrade
|
||||||
|
|
||||||
|
# Generate API documentation using Sphinx
|
||||||
docs: venv
|
docs: venv
|
||||||
$(PIP) install sphinx sphinx_rtd_theme
|
$(PIP) install sphinx sphinx_rtd_theme
|
||||||
cd docs && venv/bin/sphinx-build -b html source build
|
cd docs && venv/bin/sphinx-build -b html source build
|
||||||
|
|
||||||
# Create a code coverage report
|
# Create a code coverage report for the test suite
|
||||||
coverage: venv
|
coverage: venv
|
||||||
$(PYTHON) -m pytest --cov=scipaperloader --cov-report=html
|
$(PYTHON) -m pytest --cov=scipaperloader --cov-report=html
|
||||||
@echo "Coverage report generated in htmlcov/"
|
@echo "Coverage report generated in htmlcov/"
|
||||||
|
|
||||||
# Generate a requirements.txt file
|
# Generate a requirements.txt file from current environment
|
||||||
requirements: venv
|
requirements: venv
|
||||||
$(PIP) freeze > requirements.txt
|
$(PIP) freeze > requirements.txt
|
||||||
@echo "Requirements file updated" # Show project stats
|
@echo "Requirements file updated"
|
||||||
stats:
|
|
||||||
@echo "Lines of Python code:"
|
|
||||||
@find scipaperloader -name "*.py" | xargs wc -l | sort -nr
|
|
||||||
@echo "Number of routes:"
|
|
||||||
@grep -r "@bp.route" scipaperloader | wc -l
|
|
||||||
@echo "Database file size:"
|
|
||||||
@du -h $(DB_PATH) 2>/dev/null || echo "Database file not found"
|
|
||||||
|
|
||||||
# Show TODOs in code
|
|
||||||
todos:
|
|
||||||
@grep -r "TODO\|FIXME" scipaperloader || echo "No TODOs found".db
|
|
||||||
|
|
||||||
|
# Show project statistics (code lines, routes, database size)
|
||||||
|
stats:
|
||||||
|
@echo "Lines of Python code:"
|
||||||
|
@find scipaperloader -name "*.py" | xargs wc -l | sort -nr
|
||||||
|
@echo "Number of routes:"
|
||||||
|
@grep -r "@bp.route" scipaperloader | wc -l
|
||||||
|
@echo "Database file size:"
|
||||||
|
@du -h $(DB_PATH) 2>/dev/null || echo "Database file not found"
|
||||||
|
|
||||||
|
# Show TODOs and FIXMEs in code
|
||||||
|
todos:
|
||||||
|
@grep -r "TODO\|FIXME" scipaperloader || echo "No TODOs found"
|
||||||
|
|
||||||
|
# Reset the database: delete, initialize, and migrate
|
||||||
reset-db:
|
reset-db:
|
||||||
rm -f $(DB_PATH)
|
rm -f $(DB_PATH)
|
||||||
flask db init || true
|
flask db init || true
|
||||||
flask db migrate -m "Initial migration"
|
flask db migrate -m "Initial migration"
|
||||||
flask db upgrade
|
flask db upgrade
|
||||||
|
|
||||||
|
# Create and set up virtual environment
|
||||||
venv:
|
venv:
|
||||||
python3 -m venv venv && \
|
python3 -m venv venv && \
|
||||||
$(PIP) install --upgrade pip setuptools && \
|
$(PIP) install --upgrade pip setuptools && \
|
||||||
$(PIP) install --editable ".[dev]"
|
$(PIP) install --editable ".[dev]"
|
||||||
|
|
||||||
|
# Run the application in debug mode
|
||||||
run: venv
|
run: venv
|
||||||
venv/bin/flask --app scipaperloader --debug run
|
venv/bin/flask --app scipaperloader --debug run
|
||||||
|
|
||||||
|
# Format code using Black and isort
|
||||||
format:
|
format:
|
||||||
venv/bin/black .
|
venv/bin/black .
|
||||||
venv/bin/isort .
|
venv/bin/isort .
|
||||||
|
|
||||||
|
# Check if code meets formatting standards
|
||||||
format-check:
|
format-check:
|
||||||
venv/bin/black --check .
|
venv/bin/black --check .
|
||||||
venv/bin/isort --check .
|
venv/bin/isort --check .
|
||||||
|
|
||||||
|
# Reformat and lint code
|
||||||
reformat: format lint
|
reformat: format lint
|
||||||
|
|
||||||
|
# Check code for style issues using flake8
|
||||||
lint:
|
lint:
|
||||||
venv/bin/flake8 .
|
venv/bin/flake8 .
|
||||||
|
|
||||||
|
# Run static type checking with mypy
|
||||||
mypy:
|
mypy:
|
||||||
venv/bin/mypy scipaperloader
|
venv/bin/mypy scipaperloader
|
||||||
|
|
||||||
|
# Run the test suite
|
||||||
test:
|
test:
|
||||||
venv/bin/pytest
|
venv/bin/pytest
|
||||||
|
|
||||||
|
# Build distribution package after running checks
|
||||||
dist: format-check lint mypy test
|
dist: format-check lint mypy test
|
||||||
$(PIP) wheel --wheel-dir dist --no-deps .
|
$(PIP) wheel --wheel-dir dist --no-deps .
|
||||||
|
|
||||||
|
# Set up complete development environment
|
||||||
dev: clean venv
|
dev: clean venv
|
||||||
|
Loading…
x
Reference in New Issue
Block a user