1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
import argparse
import sys
import griffe
from eachdist import find_projectroot, find_targets
def get_modules() -> list[str]:
rootpath = find_projectroot()
targets = find_targets("DEFAULT", rootpath)
dirs_to_exclude = [
"docs",
"scripts",
"opentelemetry-docker-tests",
"examples",
"_template",
]
packages = []
for target in targets:
rel_path = target.relative_to(rootpath)
if not any(excluded in str(rel_path) for excluded in dirs_to_exclude):
packages.append(str(rel_path / "src"))
return packages
def main():
parser = argparse.ArgumentParser(
description="Check for breaking changes using griffe",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--module",
default="opentelemetry",
help="Name of the module to check for breaking changes (e.g., opentelemetry, opentelemetry.sdk, opentelemetry.sdk.resources)",
)
parser.add_argument(
"--against",
default="main",
help="Git ref to compare against (e.g., branch, tag, or commit)",
)
args = parser.parse_args()
modules = get_modules()
base = griffe.load(args.module, search_paths=modules)
against = griffe.load_git(
args.module, ref=args.against, search_paths=modules
)
breakages = list(griffe.find_breaking_changes(against, base))
# exclude version bumps from breakages as they are expected
breakages = [b for b in breakages if b._format_title() != "__version__"]
if breakages:
for b in breakages:
# We can use `b.explain()` to get a detailed explanation of the breaking change
# and we can iterate over breakages to perform more complex logic
# like skipping per object.path or breakage type
print(b.explain())
return 1
return 0
if __name__ == "__main__":
sys.exit(main())
|