Building Python Projects with Buck2: A Complete Guide to Virtual Environments and Dependency Management
Building Python Projects with Buck2: A Complete Guide to Virtual Environments and Dependency Management
Section titled “Building Python Projects with Buck2: A Complete Guide to Virtual Environments and Dependency Management”A comprehensive walkthrough of setting up a modern Python project using Buck2, UV, virtual environments, and wheels.
Table of Contents
Section titled “Table of Contents”- Introduction
- Prerequisites
- Project Setup from Scratch
- Creating Your First Python Library
- Managing Dependencies with UV
- Testing Best Practices
- Building with Buck2
- Dependency Groups and Wheels
- Virtual Environments
- Troubleshooting
Introduction
Section titled “Introduction”Buck2 is a powerful build system created by Meta that makes building large-scale projects faster and more reliable. When combined with Python, UV (a fast Python package manager), and proper virtual environment management, you get a modern, efficient development workflow.
This guide walks through building a complete Python project with:
- Buck2 - Fast, reliable build system
- UV - Lightning-fast Python package manager
- Virtual environments - Isolated Python environments
- Wheels - Pre-built Python packages
- Test organization - Proper separation of concerns
- Dependency management - Multiple dependency groups
By the end, you’ll have a production-ready Python project structure that scales.
Prerequisites
Section titled “Prerequisites”Before starting, ensure you have:
- Python 3.8+ installed
- Git for version control
- 10-15 minutes to follow along
Install Required Tools
Section titled “Install Required Tools”# Install Buck2# macOS/Linuxcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shcargo install buck2
# Or download pre-built binaries# See: https://buck2.build/docs/getting_started/
# Install UV (Python package manager)# macOS/Linuxcurl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Verify installationsbuck2 --versionuv --versionpython --versionProject Setup from Scratch
Section titled “Project Setup from Scratch”Let’s create a complete Python project with proper structure, testing, and dependency management.
Step 1: Create Project Structure
Section titled “Step 1: Create Project Structure”# Create project directorymkdir buck2-python-projectcd buck2-python-project
# Initialize gitgit initgit config user.email "you@example.com"git config user.name "Your Name"
# Create main directoriesmkdir -p libmkdir -p testsmkdir -p toolchains
# Create package markerstouch lib/__init__.pytouch tests/__init__.pytouch toolchains/__init__.py
# Create PACKAGE files (Buck2 package markers)touch PACKAGEtouch lib/PACKAGEtouch tests/PACKAGEtouch toolchains/PACKAGEStep 2: Create Buck Configuration
Section titled “Step 2: Create Buck Configuration”# Create .buckconfigcat > .buckconfig << 'EOF'[cells] root = . prelude = prelude toolchains = toolchains none = none
[cell_aliases] config = prelude ovr_config = prelude fbcode = none fbsource = none fbcode_macros = none buck = none
[external_cells] prelude = bundled
[parser] target_platform_detector_spec = target:root//...->prelude//platforms:default \ target:prelude//...->prelude//platforms:default \ target:toolchains//...->prelude//platforms:default
[build] execution_platforms = prelude//platforms:default
[project] ignore = .gitEOF
# Create .buckroot markertouch .buckroot
# Create .gitignorecat > .gitignore << 'EOF'/buck-out.venv/*.pyc__pycache__/*.egg-info/dist/build/.pytest_cache/.mypy_cache/*.lockEOFStep 3: Create pyproject.toml
Section titled “Step 3: Create pyproject.toml”cat > pyproject.toml << 'EOF'[build-system]requires = ["hatchling"]build-backend = "hatchling.build"
[project]name = "buck2-example"version = "0.1.0"description = "A Buck2 Python project with diverse dependencies"readme = "README.md"requires-python = ">=3.8"license = {text = "MIT"}authors = [ {name = "Your Name", email = "you@example.com"}]
# Core runtime dependenciesdependencies = [ "requests>=2.28.0", # HTTP client library "click>=8.0", # CLI framework "pydantic>=2.0", # Data validation]
# Optional dependency groups[project.optional-dependencies]dev = [ "pytest>=7.0", # Testing framework "pytest-cov>=4.0", # Code coverage "black>=23.0", # Code formatter "ruff>=0.1.0", # Linter "mypy>=1.0", # Type checker]
docs = [ "sphinx>=6.0", # Documentation generator "sphinx-rtd-theme>=1.0", # ReadTheDocs theme]
api = [ "fastapi>=0.95.0", # Web framework "uvicorn>=0.20.0", # ASGI server "sqlalchemy>=2.0", # ORM]
data = [ "pandas>=2.0", # Data manipulation "numpy>=1.24", # Numerical computing]
# Tool configurations[tool.uv]python-version = "3.11"venv-dir = ".venv"
[tool.pytest.ini_options]testpaths = ["tests"]python_files = "test_*.py"
[tool.black]line-length = 100target-version = ["py311"]
[tool.ruff]line-length = 100select = ["E", "F", "W", "I"]
[tool.mypy]python_version = "3.11"warn_return_any = truedisallow_untyped_defs = falseEOFStep 4: Create Root BUCK File
Section titled “Step 4: Create Root BUCK File”cat > BUCK << 'EOF'genrule( name = "hello_world", out = "out.txt", cmd = "echo BUILT BY BUCK2> $OUT",)
python_library( name = "wheel_example", srcs = ["wheel_example.py"], base_module = "",)EOFStep 5: Create Toolchains BUCK File
Section titled “Step 5: Create Toolchains BUCK File”cat > toolchains/BUCK << 'EOF'load("@prelude//toolchains:demo.bzl", "system_demo_toolchains")
# Default toolchains for demo/prototypingsystem_demo_toolchains()EOFStep 6: Create Setup Scripts
Section titled “Step 6: Create Setup Scripts”For macOS/Linux:
cat > setup_venv.sh << 'EOF'#!/bin/bashset -e
RED='\033[0;31m'GREEN='\033[0;32m'YELLOW='\033[1;33m'NC='\033[0m'
echo -e "${GREEN}Buck2 Python Environment Setup${NC}\n"
if ! command -v uv &> /dev/null; then echo -e "${RED}Error: uv is not installed${NC}" echo "Install it with: curl -LsSf https://astral.sh/uv/install.sh | sh" exit 1fi
echo -e "${GREEN}✓ Found UV$(uv --version)${NC}"
if [ -d ".venv" ]; then echo -e "${YELLOW}Removing existing .venv directory...${NC}" rm -rf .venvfi
echo -e "\n${GREEN}Creating virtual environment...${NC}"uv venv --python 3.11
echo -e "${GREEN}Activating virtual environment...${NC}"source .venv/bin/activate
echo -e "\n${GREEN}Installing base dependencies...${NC}"uv pip install -e .
echo -e "\n${YELLOW}Optional dependency groups:${NC}"echo "1) dev - Development tools (pytest, black, ruff, mypy)"echo "2) docs - Documentation (sphinx, sphinx-rtd-theme)"echo "3) api - Web API (fastapi, uvicorn, sqlalchemy)"echo "4) data - Data science (pandas, numpy)"echo "5) all - Install all groups"echo "6) none - Skip optional dependencies"read -p "Select groups (1-6): " choice
case $choice in 1) uv pip install -e ".[dev]" ;; 2) uv pip install -e ".[docs]" ;; 3) uv pip install -e ".[api]" ;; 4) uv pip install -e ".[data]" ;; 5) uv pip install -e ".[dev,docs,api,data]" ;; 6) echo -e "${YELLOW}Skipping optional dependencies${NC}" ;; *) echo -e "${RED}Invalid choice${NC}"; exit 1 ;;esac
echo -e "\n${GREEN}Creating lock file...${NC}"uv pip freeze > uv-lock.txt
echo -e "\n${GREEN}✓ Setup complete!${NC}"echo -e "${YELLOW}To activate environment in future:${NC}"echo " source .venv/bin/activate"echo ""echo -e "${GREEN}Ready to use! 🚀${NC}"EOF
chmod +x setup_venv.shFor Windows:
cat > setup_venv.bat << 'EOF'@echo offsetlocal enabledelayedexpansion
echo Buck2 Python Environment Setupecho.
where uv >nul 2>nulif %ERRORLEVEL% NEQ 0 ( echo Error: uv is not installed echo Install it with: powershell -c "irm https://astral.sh/uv/install.ps1 | iex" exit /b 1)
echo Found UV - Creating virtual environment...
if exist ".venv" ( echo Removing existing .venv directory... rmdir /s /q .venv)
echo.echo Creating virtual environment...call uv venv --python 3.11
echo Activating virtual environment...call .venv\Scripts\activate.bat
echo.echo Installing base dependencies...call uv pip install -e .
echo.echo Optional dependency groups:echo 1) dev - Development toolsecho 2) docs - Documentationecho 3) api - Web APIecho 4) data - Data scienceecho 5) all - Install all groupsecho 6) none - Skip optionalset /p choice="Select groups (1-6): "
if "%choice%"=="1" ( call uv pip install -e ".[dev]") else if "%choice%"=="5" ( call uv pip install -e ".[dev,docs,api,data]")
echo.echo Creating lock file...call uv pip freeze > uv-lock.txt
echo.echo Setup complete!echo.echo To activate environment in future:echo .venv\Scripts\activate.batEOFCreating Your First Python Library
Section titled “Creating Your First Python Library”Step 1: Create Utility Functions
Section titled “Step 1: Create Utility Functions”cat > lib/utils.py << 'EOF'"""Utility functions for the project."""
def add(a: int, b: int) -> int: """Add two numbers.
Args: a: First number b: Second number
Returns: Sum of a and b """ return a + b
def multiply(a: int, b: int) -> int: """Multiply two numbers.
Args: a: First number b: Second number
Returns: Product of a and b """ return a * bEOFStep 2: Create HTTP Utilities
Section titled “Step 2: Create HTTP Utilities”cat > lib/http_utils.py << 'EOF'"""HTTP utilities using external library dependencies."""
def fetch_status(url: str, timeout: int = 5): """Fetch HTTP status code from a URL.
Args: url: URL to fetch timeout: Request timeout in seconds
Returns: HTTP status code or None if requests not available """ try: import requests response = requests.get(url, timeout=timeout) return response.status_code except ImportError: print("requests library not installed") return None except Exception as e: print(f"Error fetching {url}: {e}") return None
def fetch_json(url: str, timeout: int = 5): """Fetch and parse JSON from a URL.
Args: url: URL to fetch JSON from timeout: Request timeout in seconds
Returns: Parsed JSON dict or None if error """ try: import requests response = requests.get(url, timeout=timeout) response.raise_for_status() return response.json() except ImportError: print("requests library not installed") return None except Exception as e: print(f"Error fetching JSON: {e}") return NoneEOFStep 3: Create lib/BUCK File
Section titled “Step 3: Create lib/BUCK File”cat > lib/BUCK << 'EOF'python_library( name = "utils", srcs = ["utils.py"], visibility = ["//..."],)
python_library( name = "http_utils", srcs = ["http_utils.py"], visibility = ["//..."],)EOFManaging Dependencies with UV
Section titled “Managing Dependencies with UV”Understanding Dependency Groups
Section titled “Understanding Dependency Groups”Dependencies are organized in pyproject.toml into groups:
Core dependencies - Always installed:
dependencies = [ "requests>=2.28.0", # HTTP client "click>=8.0", # CLI framework "pydantic>=2.0", # Data validation]Development group - For developers:
[project.optional-dependencies]dev = [ "pytest>=7.0", # Testing "black>=23.0", # Code formatting "ruff>=0.1.0", # Linting]Other groups - For specific use cases:
api = ["fastapi>=0.95.0", "uvicorn>=0.20.0"]data = ["pandas>=2.0", "numpy>=1.24"]docs = ["sphinx>=6.0"]Installing Dependencies
Section titled “Installing Dependencies”# Create virtual environmentuv venv --python 3.11
# Activate itsource .venv/bin/activate # Linux/macOS# or.venv\Scripts\activate.bat # Windows
# Install base dependenciesuv pip install -e .
# Install with development toolsuv pip install -e ".[dev]"
# Install multiple groupsuv pip install -e ".[dev,api,data]"
# Install everythinguv pip install -e ".[dev,docs,api,data]"
# Install specific packageuv pip install requests
# Update packageuv pip install --upgrade requests
# Create reproducible lock fileuv pip freeze > uv-lock.txt
# Use lock file (for reproducibility)uv pip install -r uv-lock.txtCreating Reproducible Environments
Section titled “Creating Reproducible Environments”A lock file pins exact versions of all dependencies:
# Generate lock fileuv pip freeze > uv-lock.txt
# View lock file structurecat uv-lock.txt# Output:# requests==2.31.0# certifi==2024.2.2# charset-normalizer==3.3.2# idna==3.6
# Commit to version controlgit add uv-lock.txtgit commit -m "Add dependency lock file"
# Team members use ituv pip install -r uv-lock.txtBenefits:
- ✅ Exact versions for all team members
- ✅ Transitive dependencies pinned
- ✅ No surprises from newer versions
- ✅ Perfect for CI/CD pipelines
Testing Best Practices
Section titled “Testing Best Practices”Step 1: Create Test Files
Section titled “Step 1: Create Test Files”cat > tests/test_utils.py << 'EOF'"""Unit tests for lib.utils module."""
import unittest
try: from lib.utils import add, multiplyexcept ImportError: import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib')) from utils import add, multiply
class TestUtils(unittest.TestCase): """Test cases for utility functions."""
def test_add(self): """Test the add function.""" self.assertEqual(add(2, 3), 5) self.assertEqual(add(-1, 1), 0) self.assertEqual(add(0, 0), 0)
def test_add_floats(self): """Test add with floating point numbers.""" self.assertAlmostEqual(add(1.5, 2.5), 4.0)
def test_multiply(self): """Test the multiply function.""" self.assertEqual(multiply(2, 3), 6) self.assertEqual(multiply(-1, 5), -5) self.assertEqual(multiply(0, 100), 0)
if __name__ == "__main__": unittest.main()EOFcat > tests/test_http_utils.py << 'EOF'"""Unit tests for lib.http_utils module."""
import unittest
try: from lib.http_utils import fetch_status, fetch_jsonexcept ImportError: import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib')) from http_utils import fetch_status, fetch_json
class TestHttpUtils(unittest.TestCase): """Test cases for HTTP utility functions."""
def test_fetch_status_graceful_failure(self): """Test that fetch_status handles missing requests gracefully.""" result = fetch_status("https://example.com") self.assertTrue(result is None or isinstance(result, int))
def test_fetch_json_graceful_failure(self): """Test that fetch_json handles missing requests gracefully.""" result = fetch_json("https://api.example.com/data") self.assertTrue(result is None or isinstance(result, dict))
if __name__ == "__main__": unittest.main()EOFStep 2: Create tests/BUCK File
Section titled “Step 2: Create tests/BUCK File”cat > tests/BUCK << 'EOF'python_test( name = "test_utils", srcs = ["test_utils.py"], deps = ["//lib:utils"],)
python_test( name = "test_http_utils", srcs = ["test_http_utils.py"], deps = ["//lib:http_utils"],)EOFBest Practices
Section titled “Best Practices”✅ DO:
- Separate tests from library code
- Use clear, descriptive test names
- Test both success and failure cases
- Organize tests in classes
- Use explicit dependencies in BUCK files
❌ DON’T:
- Mix library and test code
- Test implementation details
- Ignore errors
- Use circular dependencies
Building with Buck2
Section titled “Building with Buck2”Initialize and Build
Section titled “Initialize and Build”# Verify Buck2 is installedbuck2 --version
# List all build targetsbuck2 uquery "//..."
# Build all targetsbuck2 build //...
# Build specific targetbuck2 build //:hello_worldbuck2 build //lib:utils
# Build with verbose outputbuck2 build //... -v
# View build artifactsls -la buck-out/v2/gen/Running Tests
Section titled “Running Tests”# Run all testsbuck2 test //...
# Run specific testbuck2 test //tests:test_utils
# Run with verbose outputbuck2 test //... -v
# View test resultsbuck2 test //... --show-outputBuild Output
Section titled “Build Output”BUILD ID: abc123def456[2024-02-18T10:30:45.123Z] Build ID: abc123def456[2024-02-18T10:30:45.456Z] Cache hits: 75%[2024-02-18T10:30:45.789Z] Commands: 10 (cached: 8, remote: 0, local: 2)[2024-02-18T10:30:45.999Z] Network: Up: 50MB Down: 120MB
✓ Pass: root//tests:test_utils (0.8s)✓ Pass: root//tests:test_http_utils (0.9s)
BUILD SUCCEEDEDDependency Groups and Wheels
Section titled “Dependency Groups and Wheels”Understanding Wheels
Section titled “Understanding Wheels”Wheels are pre-built Python packages (.whl files):
package_name-1.0-py3-none-any.whl│ │ │ │ ││ │ │ │ └─ OS compatibility│ │ │ └──── ABI compatibility│ │ └─────── Python version│ └────────── Version└──────────────────── Package nameAdvantages:
- ✅ Faster installation (no build needed)
- ✅ No compiler required
- ✅ Reproducible builds
- ✅ Easy to cache
Managing Wheels in Buck2
Section titled “Managing Wheels in Buck2”# Using local wheelshttp_file( name = "requests_wheel", url = "https://files.pythonhosted.org/.../requests-2.31.0-py3-none-any.whl", sha256 = "d434c6e...",)
python_library( name = "http_utils", srcs = ["http_utils.py"], resources = [":requests_wheel"],)Downloading Wheels
Section titled “Downloading Wheels”# Create wheels directorymkdir wheelscd wheels
# Download specific wheelpip download requests==2.31.0
# Download all project dependenciespip download -r ../requirements.txt
# List downloaded wheelsls -lh
# Output:# requests-2.31.0-py3-none-any.whl# certifi-2024.2.2-py3-none-any.whl# urllib3-2.1.0-py3-none-any.whl# ...Using Wheels in Development
Section titled “Using Wheels in Development”# Install from wheel filepip install wheels/requests-2.31.0-py3-none-any.whl
# Install all wheels in directorypip install wheels/*
# Create requirements.txt from wheelspip install --no-index --find-links=wheels requestsVirtual Environments
Section titled “Virtual Environments”What is a Virtual Environment?
Section titled “What is a Virtual Environment?”A virtual environment is an isolated Python installation:
System Python (global) └── site-packages/ ├── Package A (v1.0) ├── Package B (v2.0) └── Package C (v1.5)
Project 1 Venv └── site-packages/ ├── Package A (v1.0) ├── Package B (v2.0) └── Package C (v1.5)
Project 2 Venv └── site-packages/ ├── Package A (v1.2) ├── Package B (v3.0) └── Package D (v1.0)Benefits:
- ✅ Isolate project dependencies
- ✅ Avoid version conflicts
- ✅ Easy cleanup (delete venv)
- ✅ Reproducible environments
Creating and Managing Venv
Section titled “Creating and Managing Venv”# Create venv with UVuv venv --python 3.11
# Activate venvsource .venv/bin/activate # Linux/macOS.venv\Scripts\activate.bat # Windows
# Check which Python is activewhich python # Should show .venv pathpython --version # Should show 3.11.x
# Install packagesuv pip install requests
# List installed packagesuv pip list
# Deactivate venv (return to system Python)deactivate
# Delete venvrm -rf .venvVenv in .gitignore
Section titled “Venv in .gitignore”# Add to .gitignoreecho ".venv/" >> .gitignoreecho "*.egg-info/" >> .gitignoreecho "dist/" >> .gitignoreecho "build/" >> .gitignore
# Commit changesgit add .gitignoregit commit -m "Add venv to gitignore"Venv with Buck2
Section titled “Venv with Buck2”Setup once:
uv venv --python 3.11source .venv/bin/activateuv pip install -e ".[dev]"uv pip freeze > uv-lock.txtBuck2 automatically:
- ✓ Detects Python in active venv
- ✓ Uses installed packages
- ✓ Resolves from pyproject.toml
- ✓ Builds and tests successfully
Complete Workflow
Section titled “Complete Workflow”Initial Setup (One Time)
Section titled “Initial Setup (One Time)”# 1. Create projectmkdir my-buck2-projectcd my-buck2-projectgit init
# 2. Copy all files from this guide OR use setup script./setup_venv.sh # macOS/Linux# or.\setup_venv.bat # Windows
# 3. Activate venvsource .venv/bin/activate
# 4. Verify everythingbuck2 build //...buck2 test //...Daily Development
Section titled “Daily Development”# 1. Start sessioncd my-buck2-projectsource .venv/bin/activate
# 2. Write code and tests# ... edit files ...
# 3. Build and testbuck2 build //...buck2 test //...
# 4. Format and lint (if dev group installed)black lib/ tests/ruff check lib/ tests/mypy lib/ tests/
# 5. Commit changesgit add lib/ tests/ pyproject.tomlgit commit -m "Add new feature"
# 6. End sessiondeactivateTeam Collaboration
Section titled “Team Collaboration”# Team member clones repogit clone <repo-url>cd project
# Recreate exact environmentsource .venv/bin/activateuv pip install -r uv-lock.txt
# Same environment as original developer!buck2 build //...buck2 test //...Troubleshooting
Section titled “Troubleshooting”Issue: “buck2: command not found”
Section titled “Issue: “buck2: command not found””Solution:
# Ensure buck2 is installed# macOS/Linuxcurl -LsSf https://github.com/facebookincubator/buck2/releases/download/latest/buck2-x86_64-apple-darwin.zst | unzstd | install -m 755 /dev/stdin ~/.local/bin/buck2
# Add to PATHexport PATH="$HOME/.local/bin:$PATH"Issue: “ModuleNotFoundError: No module named ‘requests’”
Section titled “Issue: “ModuleNotFoundError: No module named ‘requests’””Solution:
# 1. Verify venv is activatedwhich python # Should show .venv path
# 2. Install packageuv pip install requests
# 3. Verify installationuv pip list | grep requests
# 4. Try build againbuck2 build //...Issue: “error: Error looking up configured node”
Section titled “Issue: “error: Error looking up configured node””Solution:
# Ensure all PACKAGE files existtouch PACKAGEtouch lib/PACKAGEtouch tests/PACKAGEtouch toolchains/PACKAGE
# Verify BUCK files existls -la */BUCK
# Try build againbuck2 build //...Issue: “Python version mismatch”
Section titled “Issue: “Python version mismatch””Solution:
# Check current Pythonpython --version
# Recreate venv with specific versionrm -rf .venvuv venv --python 3.11uv pip install -e ".[dev]"Issue: “Test failures with missing dependencies”
Section titled “Issue: “Test failures with missing dependencies””Solution:
# Check what's installeduv pip list
# Install missing dependenciesuv pip install -e ".[dev,api,data]"
# Create new lock fileuv pip freeze > uv-lock.txt
# Run tests againbuck2 test //...Issue: “Buck2 using wrong Python”
Section titled “Issue: “Buck2 using wrong Python””Solution:
# 1. Check which Python Buck2 is usingbuck2 build //:hello_world -v 2>&1 | grep -i python
# 2. Ensure venv is activatedsource .venv/bin/activatewhich python
# 3. Verify Python pathecho $VIRTUAL_ENV
# 4. Try againbuck2 build //...Summary and Key Takeaways
Section titled “Summary and Key Takeaways”Architecture
Section titled “Architecture”Your Local Machine├── .venv/ (Virtual environment)│ └── lib/python3.11/│ └── site-packages/ (Installed wheels)├── pyproject.toml (Dependency declaration)├── uv-lock.txt (Pinned versions)├── BUCK files (Build targets)└── buck-out/ (Build artifacts)Workflow
Section titled “Workflow”Code Changes ↓uv pip install (manage dependencies) ↓buck2 build (compile) ↓buck2 test (verify) ↓uv pip freeze (update lock file) ↓git commit (version control)Key Commands
Section titled “Key Commands”| Purpose | Command |
|---|---|
| Create venv | uv venv --python 3.11 |
| Activate | source .venv/bin/activate |
| Install all | uv pip install -e ".[dev]" |
| Build | buck2 build //... |
| Test | buck2 test //... |
| Format | black lib/ tests/ |
| Lint | ruff check lib/ tests/ |
| Lock | uv pip freeze > uv-lock.txt |
Best Practices
Section titled “Best Practices”✅ Always:
- Use virtual environments
- Create lock files
- Separate tests from libraries
- Use explicit dependencies
- Commit lock files to git
❌ Never:
- Use global Python for projects
- Skip testing
- Mix library and test code
- Ignore dependency conflicts
- Assume others have same setup
Conclusion
Section titled “Conclusion”By following this guide, you now have a modern Python development setup with:
- Buck2 - Fast, scalable builds
- UV - Quick dependency resolution
- Virtual Environments - Isolated, reproducible Python environments
- Wheels - Pre-built, fast packages
- Proper Testing - Organized, maintainable tests
- Dependency Management - Multiple groups for different use cases
This setup scales from small projects to large, team-based development. The combination of Buck2 and UV provides speed and reliability, while virtual environments ensure reproducibility across team members and CI/CD pipelines.
Start with the basic setup, add your own libraries and tests, and expand dependency groups as your project grows. The foundation is solid, flexible, and production-ready.
Happy building! 🚀
Additional Resources
Section titled “Additional Resources”- Buck2 Documentation
- UV Package Manager
- Python Virtual Environments
- Python Wheels
- PEP 517 - Python packaging
- pyproject.toml Guide
Written: February 2024 Updated: February 2024 Version: 1.0