Codeowners Parser

0.8.0 · active · verified Thu Apr 09

A Python library for parsing and working with CODEOWNERS files, typically used in Git repositories to define ownership for different parts of the codebase. It provides methods to identify the owners of specific file paths based on the rules defined in a CODEOWNERS file. The current version is 0.8.0. Releases are infrequent, usually for minor bug fixes or small feature additions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Codeowners` parser and retrieve the owners for specific file paths. It creates a temporary CODEOWNERS file to illustrate usage.

from codeowners import Codeowners

# Create a dummy CODEOWNERS file for demonstration
with open('.github/CODEOWNERS', 'w') as f:
    f.write("*.py @python-devs\n/src/docs/* @docs-team\n/src/app/core/ @core-maintainers")

# Initialize the parser with the path to the CODEOWNERS file
# Note: The library searches default paths if not explicitly given, 
# but providing the path is best practice.
co = Codeowners('.github/CODEOWNERS')

# Get owners for a specific file path
owners_py = co.of('src/app/utils.py')
print(f"Owners for src/app/utils.py: {owners_py}")

owners_doc = co.of('src/docs/guide.md')
print(f"Owners for src/docs/guide.md: {owners_doc}")

owners_core = co.of('src/app/core/models.py')
print(f"Owners for src/app/core/models.py: {owners_core}")

# Clean up the dummy file
import os
os.remove('.github/CODEOWNERS')

view raw JSON →