Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# P2PP Development Rules

## Project Overview
P2PP post-processing tool for Palette 2 printers. Python + PyQt5. uv package manager.

## Critical Rules

### Architecture
- NEVER use Universal2 builds - PyQt5/QtWebEngine breaks
- Always separate Intel (x86_64) and ARM (arm64) for macOS
- Error: "mach-o file, but is an incompatible architecture"

### Commands
```bash
python3 scripts/check_architecture.py # Check system
python3 scripts/dev.py test-unit # Unit tests
python3 scripts/dev.py all # All checks
```

### Setup
```bash
uv venv
source .venv/bin/activate
uv sync --extra dev --no-build
```

## Code Standards

### Comments
- No "what" comments - only "why" comments
- Bad: `# Create virtual environment`
- Good: `# Isolated environment prevents system conflicts`

### DRY Principle
- Extract common patterns into functions
- Use constants for repeated values
- Consolidate similar logic

### Testing
- All tests must run and pass
- Test real functionality, not implementation details

## Tool Rules

### Cursor Users
- Use `python3 scripts/dev.py` commands
- Check README.md for project standards

### GitHub Copilot Users
- Check pyproject.toml for available commands
- Use type hints and docstrings
- Reference existing tests in tests/

### All AI Assistants
- Test generated code before suggesting
- Prefer built-in Python modules
- Use uv for development, setup.py for building

## Quick Reference

### Commands
```bash
python3 scripts/check_architecture.py # Check download needed
python3 scripts/dev.py test-unit # 19 unit tests
python3 scripts/dev.py all # Full verification
```

### Building
```bash
# macOS Intel
export ARCHFLAGS="-arch x86_64"
python setup.py py2app --arch=x86_64

# macOS ARM
export ARCHFLAGS="-arch arm64"
python setup.py py2app --arch=arm64

# Windows/Linux
python setup.py bdist_msi
python setup.py bdist_rpm
```

## Python Version
- Development: Python 3.9+
- Building: Python 3.11 (cx_Freeze compatibility)

83 changes: 75 additions & 8 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM mcr.microsoft.com/devcontainers/python:3.8
FROM mcr.microsoft.com/devcontainers/python:3.12

ENV DEBIAN_FRONTEND=noninteractive
ENV QT_DEBUG_PLUGINS=1
ENV PYTHONPATH=/workspace
ENV QT_QPA_PLATFORM=xcb
ENV DISPLAY=:1

# Update package list and install basic dependencies
# Update package list and install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
# Qt and GUI dependencies
libegl1 \
libgl1 \
libxcb-icccm4 \
Expand All @@ -26,23 +28,88 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libxcursor1 \
libxi6 \
libxrender-dev \
libxcb1 \
libx11-xcb-dev \
libglu1-mesa-dev \
libxi-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev \
# Python and PyQt5 system packages
python3-pip \
python3-pyqt5 \
python3-pyqt5.qtwebengine \
python3-pyqt5.qtwebkit \
qttools5-dev-tools \
qttools5-dev \
libssl-dev \
python3-openssl \
libxcb1 \
libx11-xcb-dev \
libglu1-mesa-dev \
libxi-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev \
# Build tools and dependencies
build-essential \
pkg-config \
# Testing dependencies (for headless GUI testing)
xvfb \
xauth \
# Development tools
git \
curl \
wget \
unzip \
# Build dependencies for Python packages
libffi-dev \
libcairo2-dev \
libpango1.0-dev \
libgdk-pixbuf2.0-dev \
shared-mime-info \
# File compression tools (for build packages)
rpm \
debhelper \
python3-all \
dh-python \
python3-setuptools \
python3-stdeb \
&& rm -rf /var/lib/apt/lists/*

# Install uv (fast Python package manager)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.cargo/bin:$PATH"

# Upgrade pip for compatibility
RUN pip install --upgrade pip

# Create workspace directory
WORKDIR /workspace

# Create cache directory for uv
RUN mkdir -p /workspace/.uv-cache
ENV UV_CACHE_DIR=/workspace/.uv-cache

# Set up virtual display for headless GUI testing
RUN echo '#!/bin/bash\nXvfb :1 -screen 0 1024x768x24 > /dev/null 2>&1 &' > /usr/local/bin/start-xvfb \
&& chmod +x /usr/local/bin/start-xvfb

# Create a non-root user for development (optional but recommended)
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& chown -R $USERNAME:$USERNAME /workspace

# Switch to non-root user
USER $USERNAME

# Set up shell for the user
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> /home/vscode/.bashrc \
&& echo 'export UV_CACHE_DIR=/workspace/.uv-cache' >> /home/vscode/.bashrc \
&& echo 'alias ll="ls -la"' >> /home/vscode/.bashrc \
&& echo 'alias pytest="uv run test"' >> /home/vscode/.bashrc

# Install uv for the user as well
USER $USERNAME
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/home/vscode/.cargo/bin:$PATH"

WORKDIR /workspace


164 changes: 164 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# P2PP Development Container

This development container provides a complete, ready-to-use environment for P2PP development with all necessary tools pre-installed.

## What's Included

### Core Tools
- **Python 3.12** - Latest stable Python version
- **uv** - Fast Python package manager and task runner
- **Git** - Version control
- **VS Code Extensions** - Pre-configured for Python development

### Testing & Quality Tools
- **pytest** - Testing framework with coverage support
- **black** - Code formatter
- **isort** - Import sorter
- **flake8** - Linting
- **mypy** - Type checking
- **pre-commit** - Git hooks for code quality

### GUI Development
- **PyQt5** - GUI framework (system packages)
- **Xvfb** - Virtual display for headless GUI testing
- **Qt development tools** - For building Qt applications

### Build Tools
- **RPM tools** - For Linux RPM package building
- **DEB tools** - For Linux DEB package building
- **Build essentials** - Compilers and build tools

## Quick Start

1. **Open in Dev Container**
- VS Code: `Ctrl+Shift+P` → "Dev Containers: Reopen in Container"
- GitHub Codespaces: Click "Code" → "Create codespace"

2. **Wait for Setup**
- The container will automatically run `post-create.sh`
- This installs all dependencies and runs initial tests
- Takes ~2-3 minutes on first run

3. **Start Developing**
```bash
# Run tests
uv run test

# Check your architecture
uv run check-arch

# Format code
uv run format
```

## Environment Features

### Pre-configured VS Code Settings
- Python testing with pytest enabled
- Auto-formatting on save with black
- Import sorting with isort
- Linting with flake8 and mypy
- Integrated terminal with uv aliases

### Virtual Display Setup
For GUI testing without a physical display:
```bash
export DISPLAY=:1
# Or run commands with xvfb-run:
xvfb-run -a uv run test-e2e
```

### uv Cache Optimization
- UV cache is mounted to `.uv-cache/` for fast rebuilds
- Dependencies are cached between container rebuilds
- Significantly faster setup on subsequent starts

## Available Commands

All commands use uv for consistency and speed:

```bash
# Testing
uv run test # All tests
uv run test-unit # Unit tests only
uv run test-integration # Integration tests
uv run test-e2e # End-to-end tests
uv run test-coverage # With coverage report

# Code Quality
uv run format # Format with black + isort
uv run lint # Lint with flake8 + mypy

# Architecture & Building
uv run check-arch # Check system architecture
uv run test-arch # Test architecture builds
uv run clean # Clean build artifacts

# Development
uv run dev-setup # Install pre-commit hooks
```

## Troubleshooting

### GUI Applications
If you get display-related errors:
```bash
export DISPLAY=:1
/usr/local/bin/start-xvfb # Restart virtual display
```

### Permission Issues
The container runs as the `vscode` user (UID 1000):
```bash
sudo chown -R vscode:vscode /workspace
```

### uv Not Found
If uv commands don't work:
```bash
export PATH="$HOME/.cargo/bin:$PATH"
source ~/.bashrc
```

### PyQt5 Import Errors
For PyQt5 issues in headless mode:
```bash
export QT_QPA_PLATFORM=xcb
export DISPLAY=:1
```

## Container Specifications

| Component | Version/Source |
|-----------|---------------|
| Base Image | `mcr.microsoft.com/devcontainers/python:3.12` |
| Python | 3.12 |
| uv | Latest (installed from official script) |
| Operating System | Debian-based |
| Architecture | x86_64 (Intel/AMD64) |

## Performance Optimizations

1. **uv Caching**: Dependencies cached in mounted volume
2. **System Packages**: PyQt5 installed via apt for speed
3. **Multi-stage Setup**: Base dependencies in Dockerfile, dev tools in post-create
4. **Non-root User**: Better security and file permissions

## Extending the Container

To add new tools or dependencies:

1. **System packages**: Add to `Dockerfile`
2. **Python packages**: Add to `pyproject.toml`
3. **VS Code extensions**: Add to `devcontainer.json`
4. **Setup scripts**: Modify `post-create.sh`

## Related Documentation

- [Development Guide](../DEVELOPMENT.md) - Complete development workflow
- [Architecture Guide](../docs/ARCHITECTURE_BUILDS.md) - Architecture-specific builds
- [Project README](../README.md) - Main project documentation

---

💡 **Tip**: The dev container is optimized for P2PP's architecture-specific build requirements. It includes tools for testing both Intel and ARM compatibility, even on x86_64 hosts.
Loading