108 lines
2.7 KiB
Makefile
108 lines
2.7 KiB
Makefile
.PHONY: all clean venv run format format-check lint mypy test dist reformat dev
|
|
|
|
PYTHON := venv/bin/python
|
|
PIP := venv/bin/pip
|
|
|
|
all: run
|
|
|
|
clean:
|
|
rm -rf venv build dist .pytest_cache .mypy_cache *.egg-info
|
|
|
|
DB_PATH=scipaperloader/papers# Backup the database
|
|
backup-db:
|
|
@mkdir -p backups
|
|
@timestamp=$$(date +%Y%m%d_%H%M%S); \
|
|
cp $(DB_PATH) backups/papers_$$timestamp.db && \
|
|
echo "Database backed up to backups/papers_$$timestamp.db"
|
|
|
|
# Create sample test data
|
|
sample-data: venv
|
|
$(PYTHON) scipaperloader/scripts/create_sample_data.py
|
|
|
|
# Export database as SQL
|
|
export-db: venv
|
|
@mkdir -p exports
|
|
@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()));" && \
|
|
echo "Database exported to exports/papers_$$timestamp.sql" # Run with production settings
|
|
run-prod: venv
|
|
FLASK_ENV=production venv/bin/flask --app scipaperloader run --host=0.0.0.0
|
|
|
|
# Check for security vulnerabilities
|
|
security-check: venv
|
|
$(PIP) install safety
|
|
venv/bin/safety check
|
|
|
|
# Run specific migration commands
|
|
db-migrate: venv
|
|
venv/bin/flask --app scipaperloader db migrate -m "$(message)"
|
|
|
|
db-upgrade: venv
|
|
venv/bin/flask --app scipaperloader db upgrade
|
|
|
|
db-downgrade: venv
|
|
venv/bin/flask --app scipaperloader db downgrade # Generate API documentation using sphinx
|
|
|
|
docs: venv
|
|
$(PIP) install sphinx sphinx_rtd_theme
|
|
cd docs && venv/bin/sphinx-build -b html source build
|
|
|
|
# Create a code coverage report
|
|
coverage: venv
|
|
$(PYTHON) -m pytest --cov=scipaperloader --cov-report=html
|
|
@echo "Coverage report generated in htmlcov/"
|
|
|
|
# Generate a requirements.txt file
|
|
requirements: venv
|
|
$(PIP) freeze > requirements.txt
|
|
@echo "Requirements file updated" # Show project stats
|
|
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
|
|
|
|
reset-db:
|
|
rm -f $(DB_PATH)
|
|
flask db init || true
|
|
flask db migrate -m "Initial migration"
|
|
flask db upgrade
|
|
|
|
venv:
|
|
python3 -m venv venv && \
|
|
$(PIP) install --upgrade pip setuptools && \
|
|
$(PIP) install --editable ".[dev]"
|
|
|
|
run: venv
|
|
venv/bin/flask --app scipaperloader --debug run
|
|
|
|
format:
|
|
venv/bin/black .
|
|
venv/bin/isort .
|
|
|
|
format-check:
|
|
venv/bin/black --check .
|
|
venv/bin/isort --check .
|
|
|
|
reformat: format lint
|
|
|
|
lint:
|
|
venv/bin/flake8 .
|
|
|
|
mypy:
|
|
venv/bin/mypy scipaperloader
|
|
|
|
test:
|
|
venv/bin/pytest
|
|
|
|
dist: format-check lint mypy test
|
|
$(PIP) wheel --wheel-dir dist --no-deps .
|
|
|
|
dev: clean venv
|