Skip to content

Commit c60b9b2

Browse files
Copilotswathipil
andauthored
Pass --skip-pylint to apistubgen only when --md is specified (Azure#46158)
* Initial plan * Add --skip-pylint to apistub cmds when --md is passed, add tests Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/e76821d9-4504-4627-9352-c4538aa79e9f Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com> * Make test_generate_md_adds_skip_pylint hermetic by patching subprocess.run and creating token JSON Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/6aaa6910-2dab-4716-a109-89bc72d2c96e Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
1 parent 782b30e commit c60b9b2

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def run(self, args: argparse.Namespace) -> int:
148148
cmds.extend(["--out-path", out_token_path])
149149
if cross_language_mapping_path:
150150
cmds.extend(["--mapping-path", cross_language_mapping_path])
151+
if getattr(args, "generate_md", False):
152+
cmds.append("--skip-pylint")
151153

152154
logger.info("Running apistub {}.".format(cmds))
153155

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,83 @@ def fake_pwsh(cmd, **kwargs):
187187
assert cmds[out_idx + 1] == os.path.abspath(staging)
188188
assert os.path.exists(os.path.join(staging, "api.md"))
189189
assert os.path.exists(os.path.join(staging, "azure-core_python.json"))
190+
191+
@patch(
192+
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
193+
)
194+
@patch("azpysdk.apistub.PYTHON_VERSION_LIMIT", (99, 99))
195+
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
196+
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
197+
@patch("azpysdk.apistub.create_package_and_install")
198+
@patch("azpysdk.apistub.install_into_venv")
199+
@patch("azpysdk.apistub.set_envvar_defaults")
200+
def test_generate_md_adds_skip_pylint(self, _env, _install, _create, _get_whl, _get_mapping, tmp_path, monkeypatch):
201+
"""When --md is passed (generate_md=True), --skip-pylint must be in the cmds."""
202+
monkeypatch.chdir(os.getcwd())
203+
stub = apistub()
204+
staging = str(tmp_path / "staging")
205+
os.makedirs(staging, exist_ok=True)
206+
fake_parsed = MagicMock()
207+
fake_parsed.folder = str(tmp_path)
208+
fake_parsed.name = "azure-core"
209+
210+
captured_cmds = []
211+
212+
def fake_apistub_run(exe, cmds, **kwargs):
213+
captured_cmds.append(cmds)
214+
# Create the token JSON so the markdown generation branch can proceed
215+
out_idx = cmds.index("--out-path")
216+
out_dir = cmds[out_idx + 1]
217+
os.makedirs(out_dir, exist_ok=True)
218+
open(os.path.join(out_dir, "azure-core_python.json"), "w").close()
219+
220+
def fake_pwsh(cmd, **kwargs):
221+
return MagicMock(returncode=0, stdout=None)
222+
223+
with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
224+
stub, "get_executable", return_value=(sys.executable, staging)
225+
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
226+
stub, "run_venv_command", side_effect=fake_apistub_run
227+
), patch(
228+
"azpysdk.apistub.run", side_effect=fake_pwsh
229+
):
230+
stub.run(self._make_args(generate_md=True))
231+
232+
assert len(captured_cmds) == 1
233+
assert "--skip-pylint" in captured_cmds[0]
234+
235+
@patch(
236+
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
237+
)
238+
@patch("azpysdk.apistub.PYTHON_VERSION_LIMIT", (99, 99))
239+
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
240+
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
241+
@patch("azpysdk.apistub.create_package_and_install")
242+
@patch("azpysdk.apistub.install_into_venv")
243+
@patch("azpysdk.apistub.set_envvar_defaults")
244+
def test_no_generate_md_omits_skip_pylint(
245+
self, _env, _install, _create, _get_whl, _get_mapping, tmp_path, monkeypatch
246+
):
247+
"""When --md is not passed (generate_md=False), --skip-pylint must not be in the cmds."""
248+
monkeypatch.chdir(os.getcwd())
249+
stub = apistub()
250+
staging = str(tmp_path / "staging")
251+
os.makedirs(staging, exist_ok=True)
252+
fake_parsed = MagicMock()
253+
fake_parsed.folder = str(tmp_path)
254+
fake_parsed.name = "azure-core"
255+
256+
captured_cmds = []
257+
258+
def fake_apistub_run(exe, cmds, **kwargs):
259+
captured_cmds.append(cmds)
260+
261+
with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
262+
stub, "get_executable", return_value=(sys.executable, staging)
263+
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
264+
stub, "run_venv_command", side_effect=fake_apistub_run
265+
):
266+
stub.run(self._make_args(generate_md=False))
267+
268+
assert len(captured_cmds) == 1
269+
assert "--skip-pylint" not in captured_cmds[0]

0 commit comments

Comments
 (0)