Development Setup¶
This guide will help you set up a development environment for contributing to Trunk8.
Prerequisites¶
- Python 3.12 or higher
- Git
- A code editor (VS Code, PyCharm, etc.)
- Basic knowledge of Flask and Python
Setting Up Your Environment¶
1. Fork and Clone¶
First, fork the repository on GitHub, then:
# Clone your fork
git clone https://github.com/YOUR-USERNAME/trunk8.git
cd trunk8
# Add upstream remote
git remote add upstream https://github.com/lancereinsmith/trunk8.git
2. Install uv (Recommended)¶
We recommend using uv for faster dependency management:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
3. Create Virtual Environment¶
# Using uv (recommended)
uv venv
# Or, `uv sync --extra dev` will create a virtual environment
# and install dependencies in one step.
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Or using standard Python
python -m venv .venv
source .venv/bin/activate
4. Install Dependencies¶
# Using uv (install all development dependencies)
uv sync --extra dev
# Or using pip (install all development dependencies)
pip install -e .[dev]
Available dependency groups:
uv sync
orpip install -e .
- Runtime dependencies onlyuv sync --extra test
orpip install -e .[test]
- With testing toolsuv sync --extra docs
orpip install -e .[docs]
- With documentation toolsuv sync --extra dev
orpip install -e .[dev]
- All development dependencies
5. Set Up Environment Variables¶
Create a .env
file for development:
# .env
TRUNK8_ADMIN_PASSWORD=admin # Change in production
TRUNK8_SECRET_KEY=your-secret-key #Change in production
TRUNK8_LOG_LEVEL=INFO
TRUNK8_PORT=5001
6. Verify Installation¶
# Run the development server
python run.py
# Run tests
pytest
# Check code coverage
pytest --cov=app
Development Tools¶
IDE Setup¶
VS Code¶
Recommended extensions:
- Python
- Pylance
- Python Test Explorer
- TOML Language Support
- Flask Snippets
.vscode/settings.json
:
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.testing.pytestEnabled": true
}
PyCharm¶
- Open project
- Configure Python interpreter to use
.venv
- Enable Flask support in project settings
- Configure pytest as test runner
Code Quality Tools¶
Linting¶
# Install linting tools using uv:
uv pip install pylint black isort mypy
# Or using pip:
pip install pylint black isort mypy
# Run linters
pylint app/
black app/
isort app/
mypy app/
Pre-commit Hooks¶
Create .pre-commit-config.yaml
:
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
Install:
Project Structure¶
trunk8/
├── app/ # Main application package
│ ├── __init__.py # Application factory
│ ├── auth/ # Authentication blueprint
│ ├── links/ # Links management blueprint
│ ├── main/ # Main routes blueprint
│ ├── utils/ # Utility modules
│ ├── static/ # CSS, JS, images
│ └── templates/ # Jinja2 templates
├── tests/ # Test files
├── docs/ # Documentation (MkDocs)
├── run.py # Application entry point
├── config/
│ ├── config.toml # App configuration
│ └── themes.toml # Available themes
├── links.toml # Links data storage
├── pyproject.toml # Project metadata
├── Dockerfile # Docker configuration
└── mkdocs.yml # Documentation config
Development Workflow¶
1. Create Feature Branch¶
# Update main branch
git checkout main
git pull upstream main
# Create feature branch
git checkout -b feature/add-new-feature
2. Make Changes¶
Follow these guidelines:
- Write clean, documented code
- Add type hints
- Follow PEP 8 style guide
- Update tests
- Update documentation
3. Test Your Changes¶
# Run all tests
pytest
# Run specific test file
pytest tests/test_links.py
# Run with coverage
pytest --cov=app --cov-report=html
# Open coverage report
open htmlcov/index.html # macOS
# xdg-open htmlcov/index.html # Linux
# start htmlcov/index.html # Windows
4. Test Manually¶
# Start development server
python run.py
# Test different scenarios:
# - Create various link types
# - Test expiration
# - Try different themes
# - Check error handling
5. Update Documentation¶
6. Commit and Push¶
# Stage changes
git add .
# Commit with descriptive message
git commit -m "Add feature: description of changes"
# Push to your fork
git push origin feature/add-new-feature
7. Create Pull Request¶
- Go to GitHub
- Create pull request from your branch
- Fill out PR template
- Wait for review
Common Development Tasks¶
Adding a New Route¶
-
Add route to appropriate blueprint:
-
Create template in
app/templates/
- Add tests in
tests/
- Update documentation
Adding a New Configuration Option¶
- Update
ConfigLoader
inapp/utils/config_loader.py
- Add default value
- Document in configuration guide
- Add tests
Modifying Templates¶
- Edit template in
app/templates/
- Use Jinja2 template inheritance
- Test with different themes
- Check mobile responsiveness
Adding Tests¶
Create test file in tests/
:
# tests/test_new_feature.py
import pytest
from app import create_app
class TestNewFeature:
def test_feature_works(self, client):
response = client.get('/new-route')
assert response.status_code == 200
Debugging¶
Flask Debug Mode¶
Debug mode is enabled by default in development:
Using Debugger¶
VS Code¶
-
Create
.vscode/launch.json
: -
Set breakpoints
- Press F5 to start debugging
PyCharm¶
- Right-click
run.py
- Select "Debug 'run'"
- Set breakpoints as needed
Logging¶
Add logging for debugging:
import logging
logger = logging.getLogger(__name__)
def some_function():
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
Performance Profiling¶
Using Flask-Profiler¶
Add to your code:
Memory Profiling¶
Database Development (Future)¶
When and if database support is added:
Migrations¶
# Initialize migrations
flask db init
# Create migration
flask db migrate -m "Add user table"
# Apply migration
flask db upgrade
Testing with Database¶
# tests/conftest.py
@pytest.fixture
def db_session():
# Create test database
# Yield session
# Cleanup
Documentation Development¶
Writing Docs¶
- Use Markdown format
- Follow existing structure
- Include code examples
Building Docs¶
# Serve locally
mkdocs serve
# Build static site
mkdocs build
# Deploy to GitHub Pages
mkdocs gh-deploy
Troubleshooting Development Issues¶
Import Errors¶
# Ensure you're in virtual environment
which python # Should show .venv path
# Reinstall in development mode
pip install -e .
Test Failures¶
# Run single test for debugging
pytest tests/test_file.py::test_name -v
# Show print statements
pytest -s
Configuration Issues¶
# Check TOML syntax
python -m toml config/config.toml
# Reset to defaults
rm config/config.toml links.toml
# Files recreated on next run
Resources¶
Next Steps¶
- Read Contributing Guide
- Review Architecture
- Explore Testing Guide
- Check API Reference