Skip to content

Commit 37cb1cf

Browse files
authored
Add Breaking Check Without Tox (#43988)
* migrate * format * clean * minor * edit readme for breaking * address comments * FORMAT
1 parent 58fcb0a commit 37cb1cf

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

doc/tool_usage_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This repo is currently migrating all checks from a slower `tox`-based framework,
2727
|`verifysdist`| Verify directories included in sdist and contents in manifest file. Also ensures that py.typed configuration is correct within the setup.py. | `azpysdk verifysdist .` |
2828
|`verify_keywords`| Verify that the keyword 'azure sdk' is present in the targeted package's keywords. | `azpysdk verify_keywords .` |
2929
|`import_all`| Installs the package w/ default dependencies, then attempts to `import *` from the base namespace. Ensures that all imports will resolve after a base install and import. | `azpysdk import_all .` |
30+
|`breaking`| Checks for breaking changes. | `azpysdk breaking .` |
3031

3132
## Common arguments
3233

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import argparse
2+
import os
3+
import sys
4+
5+
from typing import Optional, List
6+
from subprocess import CalledProcessError, check_call
7+
8+
from .Check import Check
9+
from ci_tools.functions import install_into_venv
10+
from ci_tools.scenario.generation import create_package_and_install
11+
from ci_tools.variables import discover_repo_root, set_envvar_defaults
12+
from ci_tools.logging import logger
13+
14+
JSONDIFF_VERSION = "1.2.0"
15+
REPO_ROOT = discover_repo_root()
16+
BREAKING_CHECKER_PATH = os.path.join(REPO_ROOT, "scripts", "breaking_changes_checker")
17+
18+
19+
class breaking(Check):
20+
def __init__(self) -> None:
21+
super().__init__()
22+
23+
def register(
24+
self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None
25+
) -> None:
26+
"""Register the breaking change check. The breaking change check checks for breaking changes against the target package."""
27+
parents = parent_parsers or []
28+
p = subparsers.add_parser("breaking", parents=parents, help="Run the breaking change check")
29+
p.set_defaults(func=self.run)
30+
31+
def run(self, args: argparse.Namespace) -> int:
32+
"""Run the breaking change check command."""
33+
logger.info("Running breaking check...")
34+
35+
set_envvar_defaults()
36+
targeted = self.get_targeted_directories(args)
37+
38+
results: List[int] = []
39+
40+
for parsed in targeted:
41+
package_dir = parsed.folder
42+
package_name = parsed.name
43+
executable, staging_directory = self.get_executable(args.isolate, args.command, sys.executable, package_dir)
44+
logger.info(f"Processing {package_name} for breaking check...")
45+
46+
# install dependencies
47+
self.install_dev_reqs(executable, args, package_dir)
48+
49+
try:
50+
install_into_venv(
51+
executable,
52+
[f"jsondiff=={JSONDIFF_VERSION}", "-e", BREAKING_CHECKER_PATH],
53+
package_dir,
54+
)
55+
except CalledProcessError as e:
56+
logger.error(
57+
f"Failed to install jsondiff or breaking change checker while processing {package_name}: {e}"
58+
)
59+
results.append(1)
60+
continue
61+
62+
create_package_and_install(
63+
distribution_directory=staging_directory,
64+
target_setup=package_dir,
65+
skip_install=False,
66+
cache_dir=None,
67+
work_dir=staging_directory,
68+
force_create=False,
69+
package_type="sdist",
70+
pre_download_disabled=False,
71+
python_executable=executable,
72+
)
73+
74+
try:
75+
cmd = [
76+
executable,
77+
os.path.join(BREAKING_CHECKER_PATH, "detect_breaking_changes.py"),
78+
"--target",
79+
package_dir,
80+
]
81+
check_call(cmd)
82+
except CalledProcessError as e:
83+
logger.error(f"Breaking check failed for {package_name}: {e}")
84+
results.append(1)
85+
continue
86+
87+
return max(results) if results else 0

eng/tools/azure-sdk-tools/azpysdk/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .verify_whl import verify_whl
2929
from .bandit import bandit
3030
from .verify_keywords import verify_keywords
31+
from .breaking import breaking
3132

3233
from ci_tools.logging import configure_logging, logger
3334

@@ -87,6 +88,7 @@ def build_parser() -> argparse.ArgumentParser:
8788
verify_whl().register(subparsers, [common])
8889
bandit().register(subparsers, [common])
8990
verify_keywords().register(subparsers, [common])
91+
breaking().register(subparsers, [common])
9092

9193
return parser
9294

scripts/breaking_changes_checker/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ The breaking changes tool compares the last stable/GA version of the library (if
77

88
Add your package name to the `RUN_BREAKING_CHANGES_PACKAGES` found [here](https://github.com/Azure/azure-sdk-for-python/tree/main/scripts/breaking_changes_checker/breaking_changes_allowlist.py).
99

10+
## Run locally with `azpysdk`
11+
12+
**1) Install azpysdk:**
13+
14+
`pip install -e eng/tools/azure-sdk-tools[build]`
15+
16+
**2) Run the `breaking` check.**
17+
18+
Here we run the breaking changes tool against azure-storage-blob, for example:
19+
20+
```bash
21+
cd ./sdk/storage/azure-storage-blob
22+
azpysdk breaking .
23+
```
24+
1025
## Run locally with tox
1126

1227
**1) Install tox:**

0 commit comments

Comments
 (0)