Skip to content

Commit 650f534

Browse files
committed
Code review feedback.
1 parent 3d207c2 commit 650f534

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

.github/skills/create-api-review-pr/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ If the user asks to create an API review PR for a new package, explain that new
1818
3. The latest Node.js LTS must be installed.
1919
4. API.md workflow Node dependencies must be installed (`npm ci` from `scripts/api_md_workflow`).
2020
5. `azpysdk` must be installed (`pip install -e ./eng/tools/azure-sdk-tools`).
21+
6. ApiView stub generator dependencies must be installed (`pip install -r ./eng/apiview_reqs.txt`).
2122

2223
## Information to Gather
2324

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def run(self, args: argparse.Namespace) -> int:
112112
)
113113
logger.info(f"Processing {package_name} for apistub check")
114114

115-
if getattr(args, "install_deps", False):
115+
install_deps = getattr(args, "install_deps", False) or getattr(args, "isolate", False)
116+
117+
if install_deps:
116118
# install dependencies
117119
self.install_dev_reqs(executable, args, package_dir)
118120

@@ -143,7 +145,7 @@ def run(self, args: argparse.Namespace) -> int:
143145
python_executable=executable,
144146
)
145147

146-
if getattr(args, "install_deps", False):
148+
if install_deps:
147149
self.pip_freeze(executable)
148150

149151
pkg_path = get_package_wheel_path(package_dir)

eng/tools/azure-sdk-tools/tests/test_apistub.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,56 @@ def test_no_prebuilt_dir_falls_back_to_pkg_root(self, mock_find_whl, mock_parsed
7373
class TestRunOutputDirectory:
7474
"""Verify that dest_dir controls where the output token path ends up."""
7575

76-
def _make_args(self, dest_dir=None, generate_md=False):
76+
def _make_args(self, dest_dir=None, generate_md=False, isolate=False, install_deps=False):
7777
return argparse.Namespace(
7878
target=".",
79-
isolate=False,
79+
isolate=isolate,
8080
command="apistub",
8181
service=None,
8282
dest_dir=dest_dir,
8383
generate_md=generate_md,
84+
install_deps=install_deps,
8485
)
8586

87+
@patch(
88+
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
89+
)
90+
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
91+
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
92+
@patch("azpysdk.apistub.create_package_and_install")
93+
@patch("azpysdk.apistub.install_into_venv")
94+
@patch("azpysdk.apistub.set_envvar_defaults")
95+
def test_isolate_installs_dependencies(
96+
self, _env, install_into_venv, _create, _get_whl, _get_mapping, tmp_path, monkeypatch
97+
):
98+
"""When --isolate is passed, apistub should install dependencies."""
99+
monkeypatch.chdir(os.getcwd())
100+
stub = apistub()
101+
staging = str(tmp_path / "staging")
102+
os.makedirs(staging, exist_ok=True)
103+
fake_parsed = MagicMock()
104+
fake_parsed.folder = str(tmp_path)
105+
fake_parsed.name = "azure-core"
106+
107+
with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
108+
stub, "get_executable", return_value=(sys.executable, staging)
109+
), patch.object(stub, "install_dev_reqs") as install_dev_reqs, patch.object(
110+
stub, "pip_freeze"
111+
) as pip_freeze, patch.object(
112+
stub, "run_venv_command"
113+
):
114+
args = self._make_args(isolate=True)
115+
stub.run(args)
116+
117+
install_dev_reqs.assert_called_once_with(sys.executable, args, str(tmp_path))
118+
install_into_venv.assert_called_once()
119+
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
120+
assert install_into_venv.call_args.args[1][0:2] == [
121+
"-r",
122+
os.path.join(repo_root, "eng", "apiview_reqs.txt"),
123+
]
124+
pip_freeze.assert_called_once_with(sys.executable)
125+
86126
@patch(
87127
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
88128
)

0 commit comments

Comments
 (0)