CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mkdocs-git-revision-date-localized-plugin

MkDocs plugin that enables displaying the localized date of the last git modification of a markdown file.

Pending
Overview
Eval results
Files

utilities.mddocs/

File Exclusion & CI Integration

Utilities for excluding files from processing and handling CI/CD environment considerations for proper git history access. These functions help optimize plugin performance and ensure reliable operation in continuous integration environments.

Capabilities

File Exclusion

Pattern-based file exclusion system supporting glob patterns to exclude specific files or directories from git revision date processing.

def exclude(src_path: str, globs: List[str]) -> bool:
    """
    Determine if a file path should be excluded from processing.
    
    Parameters:
    - src_path (str): Relative source path of the file
    - globs (List[str]): List of glob patterns to match against
    
    Returns:
    bool: True if file should be excluded, False otherwise
    """

Usage:

from mkdocs_git_revision_date_localized_plugin.exclude import exclude

# Define exclusion patterns
exclusion_patterns = [
    "drafts/*",
    "*.tmp",
    "temp/**/*",
    "generated/*.md"
]

# Check if file should be excluded
file_path = "docs/drafts/my-draft.md"
should_exclude = exclude(file_path, exclusion_patterns)  # Returns True

file_path = "docs/index.md"
should_exclude = exclude(file_path, exclusion_patterns)  # Returns False

Supported Patterns:

# Examples of supported glob patterns
patterns = [
    "*.tmp",           # All .tmp files
    "drafts/*",        # All files in drafts directory
    "temp/**/*",       # All files in temp directory recursively
    "*/private.md",    # private.md in any directory
    "docs/old/*.md",   # All .md files in docs/old/
]

Configuration Integration:

plugins:
  - git-revision-date-localized:
      exclude:
        - "drafts/*"
        - "*.tmp"
        - "generated/**/*"
        - "private/*.md"

CI/CD Environment Detection

Functions for detecting and handling continuous integration environments that may have limited git history due to shallow clones.

def raise_ci_warnings(repo) -> None:
    """
    Raise warnings for CI environments with shallow git clones.
    
    Parameters:
    - repo: GitPython repository object
    """

def is_shallow_clone(repo) -> bool:
    """
    Determine if repository is a shallow clone.
    
    Parameters:
    - repo: GitPython repository object
    
    Returns:
    bool: True if repository is shallow, False otherwise
    """

def commit_count(repo) -> int:
    """
    Count the number of commits in repository.
    
    Parameters:
    - repo: GitPython repository object
    
    Returns:
    int: Number of commits in repository
    """

Usage:

from mkdocs_git_revision_date_localized_plugin.ci import raise_ci_warnings, is_shallow_clone, commit_count
from git import Repo

# Initialize repository
repo = Repo("/path/to/repo")

# Check if shallow clone
if is_shallow_clone(repo):
    print("Repository is a shallow clone")
    
    # Count commits
    num_commits = commit_count(repo)
    print(f"Repository has {num_commits} commits")
    
    # Raise appropriate warnings for CI environment
    raise_ci_warnings(repo)

CI Environment Detection

The plugin automatically detects and provides specific guidance for common CI/CD platforms:

GitHub Actions:

# Detects: GITHUB_ACTIONS environment variable
# Warning triggered when: commit_count == 1 (default fetch-depth: 1)
# Recommendation: Set fetch-depth: 0 in checkout action

GitLab CI:

# Detects: GITLAB_CI environment variable  
# Warning triggered when: commit_count < 50 (default GIT_DEPTH: 50)
# Recommendation: Set GIT_DEPTH: 0 in .gitlab-ci.yml

Bitbucket Pipelines:

# Detects: BITBUCKET_BUILD_NUMBER environment variable
# Warning triggered when: commit_count < 50 (default depth: 50)
# Recommendation: Set clone depth to full

Azure DevOps:

# Detects: Agent.Source.Git.ShallowFetchDepth environment variable
# Warning triggered when: configured depth < actual commits
# Recommendation: Remove shallow fetch settings

CI Configuration Examples

GitHub Actions:

- uses: actions/checkout@v4
  with:
    fetch-depth: 0  # Fetch full history

GitLab CI:

variables:
  GIT_DEPTH: 0  # Fetch full history

job:
  script:
    - mkdocs build

Bitbucket Pipelines:

pipelines:
  default:
    - step:
        name: Build docs
        clone:
          depth: full  # Fetch full history
        script:
          - mkdocs build

Azure DevOps:

- checkout: self
  fetchDepth: 0  # Fetch full history

Error Handling Integration

The utilities integrate with the plugin's error handling system through configuration options.

# Configuration options affecting utility behavior
config = {
    "fallback_to_build_date": True,   # Use build date when git fails
    "strict": False,                  # Don't treat warnings as errors
    "enable_parallel_processing": True # Use multiprocessing for performance
}

Error Recovery:

# When git operations fail, utilities can fall back to:
# 1. Current build timestamp
# 2. File modification time
# 3. Default epoch time

# Controlled by fallback_to_build_date configuration

Cross-Platform Compatibility

File exclusion handles cross-platform path differences automatically.

# Handles both Unix and Windows path separators
# Unix: "docs/drafts/file.md"
# Windows: "docs\\drafts\\file.md"

# Both patterns work on all platforms:
exclude_patterns = [
    "docs/drafts/*",    # Unix-style (works everywhere)
    "docs\\drafts\\*",  # Windows-style (converted automatically)
]

Performance Considerations

File Exclusion Optimization:

# Exclusion patterns are evaluated in order
# Place most common exclusions first for better performance
exclude_patterns = [
    "*.tmp",        # Fast: simple extension match
    "drafts/*",     # Fast: single directory match  
    "**/temp/*",    # Slower: recursive directory match
]

CI Detection Caching:

# CI warnings are cached per repository
# Multiple files in same repo don't trigger repeated warnings

Integration Examples

Plugin Configuration with Exclusions

plugins:
  - git-revision-date-localized:
      type: date
      exclude:
        - "drafts/*"
        - "*.tmp"
        - "generated/**/*"
      fallback_to_build_date: true
      strict: false

Custom Exclusion Logic

from mkdocs_git_revision_date_localized_plugin.exclude import exclude

def should_process_file(file_path, config):
    """Custom logic for determining file processing"""
    exclusion_patterns = config.get("exclude", [])
    
    # Use built-in exclusion
    if exclude(file_path, exclusion_patterns):
        return False
    
    # Add custom logic
    if file_path.startswith("api/") and not file_path.endswith(".md"):
        return False
        
    return True

CI Environment Handling

import os
from mkdocs_git_revision_date_localized_plugin.ci import is_shallow_clone, raise_ci_warnings

def configure_for_ci(config):
    """Adjust configuration for CI environments"""
    if any(ci_var in os.environ for ci_var in ["CI", "GITHUB_ACTIONS", "GITLAB_CI"]):
        # Enable fallback for CI environments
        config["fallback_to_build_date"] = True
        config["strict"] = False
        
        # Check for shallow clone issues
        if is_shallow_clone(repo):
            raise_ci_warnings(repo)
    
    return config

Install with Tessl CLI

npx tessl i tessl/pypi-mkdocs-git-revision-date-localized-plugin

docs

configuration.md

git-operations.md

index.md

template-integration.md

utilities.md

tile.json