Skip to content

Latest commit

 

History

History
332 lines (234 loc) · 9.48 KB

CONTRIBUTING.md

File metadata and controls

332 lines (234 loc) · 9.48 KB

Contributing to syft

Thank you for your interest in contributing to syft! This document provides guidelines and setup instructions for contributors.

Development Setup

Prerequisites

  • Python 3.11 or higher
  • Git
  • uv (recommended) or pip

Initial Setup

  1. Clone the repository

    git clone https://github.com/OpenMined/PySyft.git
    cd PySyft
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    # Using uv (recommended)
    pip install uv
    uv pip install -e ".[test,dev]"
    
    # Or using pip
    pip install -e ".[test,dev]"
  4. Install pre-commit hooks

    pip install pre-commit
    pre-commit install

    This will automatically run code quality checks before each commit.

Code Quality Standards

This project enforces code quality through automated checks. All code must pass these checks before being merged.

Pre-commit Hooks

Pre-commit hooks run automatically before each commit. They include:

  • black: Code formatting (auto-fixes)
  • isort: Import sorting (auto-fixes)
  • flake8: Linting with complexity checks (max complexity: 10)
  • bandit: Security vulnerability scanning
  • mypy: Type checking
  • Standard checks: trailing whitespace, file endings, merge conflicts, etc.

Run manually:

pre-commit run --all-files

Linting

# Check formatting
black --check syft

# Auto-format code
black syft

# Check import order
isort --check-only syft

# Fix import order
isort syft

# Run flake8
flake8 syft

Type Checking

mypy syft --no-strict-optional --ignore-missing-imports

Security Scanning

bandit -r syft -c pyproject.toml

Development Workflow

1. Create a Feature Branch

git checkout -b feature/your-feature-name
# or
git checkout -b fix/bug-description

2. Make Your Changes

Follow dev-guidelines/guidelines.md: code style, testing, and Drive API calls.

3. Run Quality Checks

Before committing:

# Run all pre-commit hooks
pre-commit run --all-files

# Verify no issues
black syft
isort syft
flake8 syft
bandit -r syft -c pyproject.toml

4. Commit Your Changes

git add .
git commit -m "Description of changes"

Pre-commit hooks will run automatically. If they fail:

  • Some issues are auto-fixed (black, isort) - just commit again
  • Other issues need manual fixes - fix them and commit again

Skip hooks locally (if needed for speed):

git commit --no-verify -m "Description of changes"

⚠️ Note: CI will still catch any skipped issues, so use this only when you're confident or need to commit quickly. The PR will fail CI checks if there are any issues.

5. Push and Create PR

git push -u origin feature/your-feature-name

Then open a Pull Request against dev. Every PR must follow the pull request format below.

We do not accept PRs that only add tests, or PRs for features in beta, such as signed job receipts on the enclave. Keep each PR self-contained: a reviewer should understand it without following other PRs or issues. We may close a PR that leans on too many references, because it lacks context.

Pull Request Format

Every PR must follow this format. Reviewers check it, and the title check blocks the merge when the title is wrong.

  • Base branch: open the PR against dev, not main.
  • Before you push: run pre-commit run --all-files until every hook passes.
  • Title: type: short description in lowercase, for example fix: handle empty peer list. The allowed types are feat, fix, docs, chore, refactor, test, ci, perf and build. The table in .github/PULL_REQUEST_TEMPLATE.md says when to use each. The PR: Lint & Label check blocks the merge when the title does not match.
  • Body: fill in every section of .github/PULL_REQUEST_TEMPLATE.md. GitHub puts the template in the PR body for you.
    • Summary: one bullet per use case the PR changes: "When we do X, we previously did Y. Now we do Z." Give each change a user sees its own bullet, and say what changes for the user.
    • Guidelines: rate the PR against dev-guidelines/guidelines.md, one line per guideline: 🟢 follows it, 🟠 partly follows it, 🔴 breaks it. For 🟠 and 🔴, say why in one line. Reviewers check these ratings.
    • Security: how the PR changes the security properties of the system, or "No change."
    • Testing: how you checked that it works.
    • Asana task: the URL of the Asana task for this work.
  • Writing: write the description by the rules in dev-guidelines/language.md: simple language, the terms the code already uses, and no assumed context.

With Claude Code, the open-pr skill does all of this for you: it runs pre-commit, writes the title, and fills in the template.

CI/CD Pipeline

All PRs must pass automated checks:

  1. Lint and Format Check: black, isort, flake8 (strict - must pass)
  2. Security Scan: bandit (strict - must pass)
  3. Type Check: mypy (advisory - won't block merges)
  4. Pre-commit Hooks: All hooks must pass (strict - catches --no-verify skips)

These run automatically on every PR via GitHub Actions.

Local vs CI behavior:

  • Locally: You can skip hooks with --no-verify for speed
  • In CI: All checks run strictly and will fail the PR if there are issues
  • mypy only: Advisory locally (manual stage), but runs in CI for visibility

Code Style Guidelines

The code style, testing and Drive API rules are in dev-guidelines/guidelines.md. Claude Code follows the same file, and PR reviews check against it.

Security Guidelines

⚠️ Important for AI-Assisted Development:

  • Never commit credentials or API keys
  • Avoid hardcoded secrets - use environment variables
  • Be cautious with user input - validate and sanitize
  • Review AI-generated code carefully for security issues
  • The bandit security scanner will catch common issues

Testing

Unit Tests

pytest tests/unit/ -v

Integration Tests (Google Drive)

Integration tests require Google OAuth credentials to test Google Drive synchronization.

1. Create credentials folder

mkdir -p credentials

2. Get Google OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a project (or select existing one)
  3. Enable the Google Drive API:
    • Go to "APIs & Services" -> "Library"
    • Search for "Google Drive API" and click "Enable"
  4. Configure OAuth Consent Screen:
    • Go to "APIs & Services" -> "OAuth consent screen"
    • Choose "External" (or "Internal" for Google Workspace)
    • Add scopes: https://www.googleapis.com/auth/drive
    • Add your test user emails
  5. Add audience:
    • "APIs & Services" -> "OAuth Consent Screen" -> "Audience"
    • Add your email as a "Test users" by clicking "Add users"
  6. Create OAuth Credentials:
    • Go to "APIs & Services" -> "Credentials"
    • Click "Create Credentials" -> "OAuth client ID"
    • Application type: Desktop app
    • Download the JSON files

3. Generate OAuth Tokens

python scripts/create_token.py --cred-path path/to/credentials.json --token-path credentials/token_do.json
python scripts/create_token.py --cred-path path/to/credentials.json --token-path credentials/token_ds.json

A browser window will open for each user to authenticate.

4. Set Environment Variables

export AI_AUDIT_EMAIL_DO=your_do_email@gmail.com
export AI_AUDIT_EMAIL_DS=your_ds_email@gmail.com

5. Run Integration Tests

AI_AUDIT_EMAIL_DO=your_do_email@gmail.com AI_AUDIT_EMAIL_DS=your_ds_email@gmail.com pytest tests/integration/test_sync_manager.py -v -s

Or if you've already exported the variables:

pytest tests/integration/test_sync_manager.py -v -s

Security Notes

Getting Help

Branch Protection Rules

The main branch is protected with the following rules:

  • ✅ Require PR reviews (minimum 1 approval)
  • ✅ Require status checks to pass:
    • Lint and Format Check
    • Security Scan
    • Type Check (advisory)
    • Pre-commit Hooks
  • ✅ Require branches to be up to date before merging
  • ✅ No force pushes
  • ✅ No deletions

Tips for AI-Assisted Development

When using AI coding assistants (Claude Code, GitHub Copilot, etc.):

  1. Always run pre-commit hooks - they catch formatting and security issues
  2. Review generated code - AI can introduce vulnerabilities
  3. Check complexity - AI sometimes generates over-complicated code
  4. Verify type hints - ensure they're accurate
  5. Test security - run bandit on AI-generated code

The automated guardrails are specifically designed to catch common AI coding issues.

License

By contributing, you agree that your contributions will be licensed under the Apache-2.0 License.