Skip to content

Commit 28ab242

Browse files
tjprescottCopilot
andauthored
Fix issue with --dest-dir for CI usage (#47792)
* Fix issue with --dest-dir for CI usage. * Run black. * Code review feedback. * Fix black formatting: restore blank line in test_dispatch_checks.py Co-authored-by: tjprescott <5723682+tjprescott@users.noreply.github.com> * Code review feedback. * Fix verify-azpysdk-checks mypy feed auth failure Co-authored-by: tjprescott <5723682+tjprescott@users.noreply.github.com> * Revert "Fix verify-azpysdk-checks mypy feed auth failure" This reverts commit 16c0ddb. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tjprescott <5723682+tjprescott@users.noreply.github.com>
1 parent 4378d83 commit 28ab242

3 files changed

Lines changed: 102 additions & 7 deletions

File tree

eng/scripts/dispatch_checks.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ci_tools.scenario.generation import build_whl_for_req, replace_dev_reqs
1717
from ci_tools.logging import configure_logging, logger
1818
from ci_tools.environment_exclusions import is_check_enabled, CHECK_DEFAULTS
19-
from ci_tools.parsing import get_config_setting
19+
from ci_tools.parsing import ParsedSetup, get_config_setting
2020
from devtools_testutils.proxy_startup import prepare_local_tool
2121
from packaging.requirements import Requirement
2222

@@ -77,6 +77,15 @@ def _normalize_newlines(text: str) -> str:
7777
return text.replace("\r\n", "\n").replace("\r", "\n")
7878

7979

80+
def get_check_dest_dir(
81+
package: str, check: str, dest_dir: Optional[str]
82+
) -> Optional[str]:
83+
if dest_dir and check == "apistub":
84+
package_name = ParsedSetup.from_path(package).name
85+
return os.path.join(dest_dir, package_name)
86+
return dest_dir
87+
88+
8089
async def _tee_stream(
8190
proc: "asyncio.subprocess.Process", package: str, check: str
8291
) -> tuple:
@@ -222,8 +231,10 @@ async def run_check(
222231
cmd += ["--service", service]
223232
if mark_arg:
224233
cmd += ["--mark_arg", mark_arg]
225-
if dest_dir and check == "apistub":
226-
cmd += ["--dest-dir", dest_dir]
234+
if check == "apistub":
235+
check_dest_dir = get_check_dest_dir(package, check, dest_dir)
236+
if check_dest_dir:
237+
cmd += ["--dest-dir", check_dest_dir]
227238
logger.info(f"[START {idx}/{total}] {check} :: {package}\nCMD: {' '.join(cmd)}")
228239
env = os.environ.copy()
229240
env["PROXY_URL"] = f"http://localhost:{proxy_port}"
@@ -500,14 +511,12 @@ def handler(signum, frame):
500511

501512

502513
if __name__ == "__main__":
503-
parser = argparse.ArgumentParser(
504-
description="""
514+
parser = argparse.ArgumentParser(description="""
505515
This script is the single point for all checks invoked by CI within this repo. It works in two phases.
506516
1. Identify which packages in the repo are in scope for this script invocation, based on a glob string and a service directory.
507517
2. Invoke one or multiple `checks` environments for each package identified as in scope.
508518
In the case of an environment invoking `pytest`, results can be collected in a junit xml file, and test markers can be selected via --mark_arg.
509-
"""
510-
)
519+
""")
511520

512521
parser.add_argument(
513522
"glob_string",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import sys
3+
from types import SimpleNamespace
4+
from unittest.mock import patch
5+
6+
REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
7+
TOOLS_ROOT = os.path.join(REPO_ROOT, "eng", "tools", "azure-sdk-tools")
8+
if TOOLS_ROOT not in sys.path:
9+
sys.path.insert(0, TOOLS_ROOT)
10+
if REPO_ROOT not in sys.path:
11+
sys.path.insert(0, REPO_ROOT)
12+
13+
from eng.scripts.dispatch_checks import get_check_dest_dir
14+
15+
16+
def test_apistub_dest_dir_uses_package_subdirectory():
17+
package_dir = os.path.join(REPO_ROOT, "sdk", "core", "azure-core")
18+
artifact_dir = os.path.join(REPO_ROOT, "artifacts")
19+
20+
with patch(
21+
"eng.scripts.dispatch_checks.ParsedSetup.from_path",
22+
return_value=SimpleNamespace(name="azure-core"),
23+
):
24+
result = get_check_dest_dir(package_dir, "apistub", artifact_dir)
25+
26+
assert result == os.path.join(artifact_dir, "azure-core")
27+
28+
29+
def test_non_apistub_dest_dir_is_unchanged():
30+
package_dir = os.path.join(REPO_ROOT, "sdk", "core", "azure-core")
31+
artifact_dir = os.path.join(REPO_ROOT, "artifacts")
32+
33+
with patch("eng.scripts.dispatch_checks.ParsedSetup.from_path") as parsed_setup:
34+
result = get_check_dest_dir(package_dir, "pylint", artifact_dir)
35+
36+
assert result == artifact_dir
37+
parsed_setup.assert_not_called()
38+
39+
40+
def test_empty_dest_dir_is_unchanged():
41+
package_dir = os.path.join(REPO_ROOT, "sdk", "core", "azure-core")
42+
43+
with patch("eng.scripts.dispatch_checks.ParsedSetup.from_path") as parsed_setup:
44+
result = get_check_dest_dir(package_dir, "apistub", None)
45+
46+
assert result is None
47+
parsed_setup.assert_not_called()

scripts/api_md_workflow/create_api_review_pr_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,45 @@ def test_main_preflights_azsdk_first(self):
605605

606606
find_package_dir.assert_not_called()
607607

608+
def test_generate_api_for_package_uses_package_dir_destination(self):
609+
package_dir = Path("sdk/example/azure-example")
610+
with (
611+
patch.object(workflow, "find_package_dir", return_value=package_dir),
612+
patch.object(workflow, "run", return_value=command_result()) as run,
613+
):
614+
workflow.generate_api_for_package("azure-example", runtime_executable=None)
615+
616+
run.assert_called_once_with(
617+
["azpysdk", "apistub", "--dest-dir", str(package_dir), "azure-example"],
618+
check=True,
619+
shell=workflow.sys.platform == "win32",
620+
)
621+
622+
def test_generate_api_for_package_runtime_executable_uses_package_dir_destination(
623+
self,
624+
):
625+
package_dir = Path("sdk/example/azure-example")
626+
with (
627+
patch.object(workflow, "find_package_dir", return_value=package_dir),
628+
patch.object(workflow, "run", return_value=command_result()) as run,
629+
):
630+
workflow.generate_api_for_package(
631+
"azure-example", runtime_executable="python"
632+
)
633+
634+
run.assert_called_once_with(
635+
[
636+
"python",
637+
"-m",
638+
"azpysdk.main",
639+
"apistub",
640+
"--dest-dir",
641+
str(package_dir),
642+
"azure-example",
643+
],
644+
check=True,
645+
)
646+
608647
def test_resolve_azsdk_uses_path_first(self):
609648
with patch.object(workflow.shutil, "which", return_value="C:/tools/azsdk.exe"):
610649
self.assertEqual(workflow.resolve_azsdk_executable(), "C:/tools/azsdk.exe")

0 commit comments

Comments
 (0)