From ml-research
Setup development environment with modern Python tooling (uv/pixi), install dependencies, and configure development tools (ruff, ty, pytest). Use when setting up new ML projects, configuring environments, or installing dependencies.
npx claudepluginhub nishide-dev/claude-code-ml-researchThis skill uses the workspace's default tool permissions.
Setup development environment with modern Python tooling (uv/pixi), install dependencies, and configure development tools.
Verifies tests pass on completed feature branch, presents options to merge locally, create GitHub PR, keep as-is or discard; executes choice and cleans up worktree.
Guides root cause investigation for bugs, test failures, unexpected behavior, performance issues, and build failures before proposing fixes.
Writes implementation plans from specs for multi-step tasks, mapping files and breaking into TDD bite-sized steps before coding.
Share bugs, ideas, or general feedback.
Setup development environment with modern Python tooling (uv/pixi), install dependencies, and configure development tools.
First, check what's already configured:
# Check for existing package managers
ls pyproject.toml 2>/dev/null && echo "Found pyproject.toml (uv/pip)"
ls pixi.toml 2>/dev/null && echo "Found pixi.toml (pixi)"
ls requirements.txt 2>/dev/null && echo "Found requirements.txt (pip)"
If no package manager is configured, ask the user:
Package Manager Choice:
uv (recommended for pure Python projects)
pixi (recommended for ML projects with GPU)
pip (traditional, not recommended for new projects)
For uv:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Verify installation
uv --version
For pixi:
# Install pixi
curl -fsSL https://pixi.sh/install.sh | sh
# Verify installation
pixi --version
With uv:
# Initialize pyproject.toml if not exists
uv init --name ml-project
# Add ML dependencies
uv add torch pytorch-lightning hydra-core
uv add --dev pytest pytest-cov ruff mypy
# Create virtual environment and install
uv sync
With pixi:
# Initialize pixi.toml if not exists
pixi init
# Add ML dependencies with CUDA
pixi add pytorch pytorch-cuda=12.1 pytorch-lightning hydra-core
pixi add --feature dev pytest ruff mypy
# Install environment
pixi install
Setup ruff (linting and formatting):
# Create ruff.toml if not exists
cat > ruff.toml << 'EOF'
line-length = 100
target-version = "py310"
[lint]
select = ["E", "F", "I", "N", "UP", "ANN", "B", "LOG", "G"]
ignore = ["ANN101", "ANN102"]
[lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/*" = ["ANN", "S101"]
EOF
Setup mypy (type checking):
# Add mypy config to pyproject.toml
cat >> pyproject.toml << 'EOF'
[tool.mypy]
python_version = "3.10"
strict = true
ignore_missing_imports = true
EOF
Setup pytest:
# Add pytest config to pyproject.toml
cat >> pyproject.toml << 'EOF'
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
addopts = ["--cov=src", "--cov-report=html"]
EOF
# Install pre-commit
uv add --dev pre-commit # or: pixi add --feature dev pre-commit
# Create .pre-commit-config.yaml
cat > .pre-commit-config.yaml << 'EOF'
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
EOF
# Install hooks
pre-commit install
# Create standard ML project directories
mkdir -p src/{models,data,utils}
mkdir -p tests
mkdir -p configs/{model,data,trainer,logger,experiment}
mkdir -p notebooks
mkdir -p scripts
# Create __init__.py files
touch src/__init__.py
touch src/models/__init__.py
touch src/data/__init__.py
touch src/utils/__init__.py
touch tests/__init__.py
Run validation checks to ensure everything is setup correctly:
# Check package manager
if command -v uv &> /dev/null; then
echo "✓ uv is installed"
uv --version
elif command -v pixi &> /dev/null; then
echo "✓ pixi is installed"
pixi --version
fi
# Check ruff
uv run ruff check . || pixi run ruff check .
echo "✓ Ruff is configured"
# Check pytest
uv run pytest --collect-only || pixi run pytest --collect-only
echo "✓ Pytest is configured"
# Check Python version
python --version
echo "✓ Python environment is active"
Create README.md with setup instructions:
# ML Project
## Setup
### Prerequisites
- Python 3.10+
- [uv](https://astral.sh/uv) or [pixi](https://pixi.sh)
### Installation
**With uv:**
\`\`\`bash
uv sync
\`\`\`
**With pixi:**
\`\`\`bash
pixi install
\`\`\`
### Development
\`\`\`bash
# Run tests
uv run pytest # or: pixi run pytest
# Lint code
uv run ruff check . # or: pixi run ruff check .
# Format code
uv run ruff format . # or: pixi run ruff format .
# Type check
uv run mypy src/ # or: pixi run mypy src/
\`\`\`
### Training
\`\`\`bash
# Run training
uv run python src/train.py # or: pixi run python src/train.py
\`\`\`
With pixi (automatic):
pixi add pytorch pytorch-cuda=12.1
# CUDA toolkit and drivers are handled automatically
With uv (manual):
# Install PyTorch with CUDA
uv add torch --index-url https://download.pytorch.org/whl/cu121
# Verify CUDA
uv run python -c "import torch; print(torch.cuda.is_available())"
# With uv
uv add torch # MPS support included by default
# With pixi
pixi add pytorch
# With uv (use PowerShell)
irm https://astral.sh/uv/install.ps1 | iex
uv add torch --index-url https://download.pytorch.org/whl/cu121
# With pixi
iwr -useb https://pixi.sh/install.ps1 | iex
pixi add pytorch pytorch-cuda=12.1
Solution: Add uv to PATH
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
Solution: Verify CUDA installation
nvidia-smi # Check GPU
python -c "import torch; print(torch.cuda.is_available())"
If using uv, install correct CUDA version:
uv add torch --index-url https://download.pytorch.org/whl/cu121
Solution: Run without sudo (install to user directory)
# Don't use sudo with uv/pixi installers
curl -LsSf https://astral.sh/uv/install.sh | sh
Your ML development environment is ready!