Skip to content

Commit 6b4dc7f

Browse files
committed
use griffe python api
1 parent 10bf2aa commit 6b4dc7f

File tree

4 files changed

+66
-60
lines changed

4 files changed

+66
-60
lines changed

scripts/eachdist.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,6 @@ def setup_instparser(instparser):
272272
),
273273
)
274274

275-
listparser = subparsers.add_parser(
276-
"list",
277-
help="List all packages with their relative paths",
278-
)
279-
listparser.set_defaults(func=list_args)
280-
listparser.add_argument(
281-
"--mode",
282-
"-m",
283-
default="DEFAULT",
284-
help=cleandoc(
285-
"""Section of config file to use for target selection configuration.
286-
See description of exec for available options."""
287-
),
288-
)
289-
290275
return parser.parse_args(args)
291276

292277

@@ -756,22 +741,6 @@ def version_args(args):
756741
print(cfg[args.mode]["version"])
757742

758743

759-
def list_args(args):
760-
rootpath = find_projectroot()
761-
targets = find_targets(args.mode, rootpath)
762-
763-
if not targets:
764-
sys.exit(f"Error: No targets selected (root: {rootpath})")
765-
766-
excluded_dirs = ["docs", "scripts"]
767-
768-
for target in targets:
769-
rel_path = target.relative_to(rootpath)
770-
if any(excluded in str(rel_path) for excluded in excluded_dirs):
771-
continue
772-
print(str(rel_path))
773-
774-
775744
def main():
776745
args = parse_args()
777746
args.func(args)

scripts/griffe_check.py

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

scripts/griffe_check.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ deps =
318318
toml
319319
commands =
320320
; griffe check before to fail fast if there are any issues
321-
{toxinidir}/scripts/griffe_check.sh
321+
python {toxinidir}/scripts/griffe_check.py
322322
python {toxinidir}/scripts/public_symbols_checker.py
323323

324324
[testenv:generate-workflows]

0 commit comments

Comments
 (0)