Skip to content

Commit 680989a

Browse files
Copilotswathipil
andauthored
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>
1 parent 597328b commit 680989a

2 files changed

Lines changed: 72 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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,73 @@ 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+
215+
with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
216+
stub, "get_executable", return_value=(sys.executable, staging)
217+
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
218+
stub, "run_venv_command", side_effect=fake_apistub_run
219+
):
220+
stub.run(self._make_args(generate_md=True))
221+
222+
assert len(captured_cmds) == 1
223+
assert "--skip-pylint" in captured_cmds[0]
224+
225+
@patch(
226+
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
227+
)
228+
@patch("azpysdk.apistub.PYTHON_VERSION_LIMIT", (99, 99))
229+
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
230+
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
231+
@patch("azpysdk.apistub.create_package_and_install")
232+
@patch("azpysdk.apistub.install_into_venv")
233+
@patch("azpysdk.apistub.set_envvar_defaults")
234+
def test_no_generate_md_omits_skip_pylint(
235+
self, _env, _install, _create, _get_whl, _get_mapping, tmp_path, monkeypatch
236+
):
237+
"""When --md is not passed (generate_md=False), --skip-pylint must not be in the cmds."""
238+
monkeypatch.chdir(os.getcwd())
239+
stub = apistub()
240+
staging = str(tmp_path / "staging")
241+
os.makedirs(staging, exist_ok=True)
242+
fake_parsed = MagicMock()
243+
fake_parsed.folder = str(tmp_path)
244+
fake_parsed.name = "azure-core"
245+
246+
captured_cmds = []
247+
248+
def fake_apistub_run(exe, cmds, **kwargs):
249+
captured_cmds.append(cmds)
250+
251+
with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
252+
stub, "get_executable", return_value=(sys.executable, staging)
253+
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
254+
stub, "run_venv_command", side_effect=fake_apistub_run
255+
):
256+
stub.run(self._make_args(generate_md=False))
257+
258+
assert len(captured_cmds) == 1
259+
assert "--skip-pylint" not in captured_cmds[0]

0 commit comments

Comments
 (0)