Skip to main content

Repo-as-Template (RAT) engine with lockfile and incremental upgrades.

Project description

retemplar

Repo-as-Template engine for structural lifecycle management at scale

Keep many repos in sync with a living template — without trampling local changes.

Purpose

Organizations often have dozens or hundreds of repositories that share a common structure (CI workflows, lint configs, Dockerfiles, etc.). Over time, these repos drift from the original template. retemplar solves this by:

  • Using any repo as a living template (Repo-as-Template, RAT)
  • Letting other repos adopt that template version
  • Applying template-to-template deltas as small, explainable PRs
  • Supporting managed paths, section-level rules, and inline blocks to control ownership
  • Recording provenance in a .retemplar.lock file

The result: consistent, auditable upgrades across your entire fleet of repos.

Current Status

  • Phase: MVP Implementation Complete ✅
  • Version: 0.0.0a0 (Alpha)
  • Primary Doc: docs/design-doc.md
  • Ready: Core CLI + lockfile management + template engine

Installation

# Install from source (development)
git clone <repo-url>
cd retemplar
pip install -e .

Quick Start

1. Adopt a Template

Make your repo adopt another repo as a template:

# Adopt a local template
retemplar adopt --template rat:../my-template-repo

# Adopt a GitHub template at a specific tag
retemplar adopt --template rat:gh:org/template-repo@v1.0.0

This creates a .retemplar.lock file tracking the template relationship.

2. Plan Template Updates

See what changes would be applied when updating to a new template version:

# Preview upgrade to latest
retemplar plan --to rat:../my-template-repo

# Preview upgrade to specific version
retemplar plan --to rat:gh:org/template-repo@v1.1.0

3. Apply Changes

Apply the planned changes:

# Apply changes locally
retemplar apply --to rat:../my-template-repo

# Apply and create GitHub PR (when GitHub provider is ready)
retemplar apply --to rat:../my-template-repo --pr

4. Check for Drift

Detect when your repo has drifted from the template:

retemplar drift

Configuration

Lockfile (.retemplar.lock)

After running adopt, you'll get a lockfile like:

schema_version: "1.0.0"
template:
  kind: rat
  repo: gh:org/template-repo
  ref: v1.0.0
version: rat@v1.0.0

managed_paths:
  - path: ".github/workflows/**"
    strategy: enforce
  - path: "pyproject.toml"
    strategy: patch
    rules:
      - path: "tool.ruff"
        action: enforce
      - path: "project.dependencies"
        action: preserve

ignore_paths:
  - "README.md"
  - "docs/**"

Edit this file to control what the template manages:

  • enforce: Template always wins
  • preserve: Local changes always win
  • merge: Attempt 3-way merge
  • patch: Section-level rules for structured files

Inline Managed Blocks

For fine-grained control within files:

# retemplar:begin id=imports
import os
import sys
# retemplar:end

# Your local code here
print("Hello world")

# retemplar:begin id=main-logic
def main():
    pass
# retemplar:end

Modes:

  • Default: Template manages the block content
  • # retemplar:begin id=myblock mode=ignore: Keep local content untouched
  • # retemplar:begin id=myblock mode=protect: Create conflict for review

Features

  • Repo-as-Template (RAT): Use any repo/tag as a living template
  • Incremental Updates: Small, explainable template-to-template diffs
  • Ownership Control: Path-level and section-level ownership rules
  • Drift Detection: Detect conflicts between template and local changes
  • 3-Way Merges: Smart merging with conflict markers when needed
  • Inline Blocks: Manage specific sections within files
  • Variable Substitution: Template variables with persistence
  • Lockfile Tracking: Full provenance and upgrade history
  • 🚧 GitHub Integration: Use github link as reference

Examples

Template Upgrade Workflow

# Check current status
retemplar drift

# Plan upgrade
retemplar plan --to rat:gh:org/template@v2.0.0

# Review the changes, then apply
retemplar apply --to rat:gh:org/template@v2.0.0

Managing Conflicts

When local and template changes conflict, you'll see:

<<<<<<< local
line-length = 120
=======
line-length = 88
>>>>>>> template

Resolve manually, then commit the resolution.

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Lint and format
ruff check --fix
ruff format

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retemplar-0.0.0a1.tar.gz (90.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retemplar-0.0.0a1-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file retemplar-0.0.0a1.tar.gz.

File metadata

  • Download URL: retemplar-0.0.0a1.tar.gz
  • Upload date:
  • Size: 90.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for retemplar-0.0.0a1.tar.gz
Algorithm Hash digest
SHA256 741eaca27d7c9bdef9b8a085153746cacde779b95620b530a5a39edbb1635ae6
MD5 1b3e0a6e981704460fd10f24f96af386
BLAKE2b-256 477d8d272bf20754e4263c722761ba8197d94c5c5e8bdffc2401ee5081a9305c

See more details on using hashes here.

File details

Details for the file retemplar-0.0.0a1-py3-none-any.whl.

File metadata

  • Download URL: retemplar-0.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for retemplar-0.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef815a186fe4273127f908f5baecb700687bbccc5ae84602503f7b7072c742b9
MD5 1f5d4182f8971b65b12c8a791a01a8a2
BLAKE2b-256 7619d467033a76932954656375a6c6ddfd54527470e808b8603b02a6f24cd378

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page