bmsdna-devtools 0.57.2__tar.gz → 0.59.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/PKG-INFO +1 -1
  2. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/cli.py +5 -2
  3. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/cli_tools.py +187 -6
  4. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_pr.py +11 -3
  5. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_build.py +15 -2
  6. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/pyproject.toml +1 -1
  7. bmsdna_devtools-0.59.0/tests/test_wait_timeout.py +499 -0
  8. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/uv.lock +1 -1
  9. bmsdna_devtools-0.57.2/tests/test_wait_timeout.py +0 -187
  10. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/.github/workflows/auto-release.yml +0 -0
  11. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/.github/workflows/python-publish.yml +0 -0
  12. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/.github/workflows/python-test.yml +0 -0
  13. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/.gitignore +0 -0
  14. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/.python-version +0 -0
  15. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/README.md +0 -0
  16. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/__init__.py +0 -0
  17. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/_api_dump.py +0 -0
  18. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ado_auth.py +0 -0
  19. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ado_issue.py +0 -0
  20. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/agent_mentions.py +0 -0
  21. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/api_usage.py +0 -0
  22. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/app_service_logs.py +0 -0
  23. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/azure_arm.py +0 -0
  24. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/azure_auth.py +0 -0
  25. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/bdt_config.py +0 -0
  26. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/business_user.py +0 -0
  27. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ci_plan.py +0 -0
  28. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ci_plan_env.py +0 -0
  29. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/commit.py +0 -0
  30. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/dead_code.py +0 -0
  31. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/__init__.py +0 -0
  32. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/advisories.py +0 -0
  33. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/cli.py +0 -0
  34. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/cooldown.py +0 -0
  35. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/lockfiles.py +0 -0
  36. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/osv.py +0 -0
  37. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/versions.py +0 -0
  38. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/env_config.py +0 -0
  39. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/env_files.py +0 -0
  40. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/find_injection.py +0 -0
  41. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/find_repo.py +0 -0
  42. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_args.py +0 -0
  43. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_issue.py +0 -0
  44. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/github_api.py +0 -0
  45. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gitrepo.py +0 -0
  46. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/injection_frontend.py +0 -0
  47. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/injection_python.py +0 -0
  48. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_do.py +0 -0
  49. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_show.py +0 -0
  50. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_watch.py +0 -0
  51. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint.py +0 -0
  52. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_findings.py +0 -0
  53. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_models.py +0 -0
  54. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_sql.py +0 -0
  55. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_sql_files.py +0 -0
  56. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_tooling.py +0 -0
  57. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_typescript.py +0 -0
  58. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/logs.py +0 -0
  59. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_cancel.py +0 -0
  60. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_choice.py +0 -0
  61. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_create_args.py +0 -0
  62. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_drift.py +0 -0
  63. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_info.py +0 -0
  64. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_issue_link.py +0 -0
  65. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_labels.py +0 -0
  66. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_markdown.py +0 -0
  67. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
  68. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_ref.py +0 -0
  69. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pull.py +0 -0
  70. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/testdb.py +0 -0
  71. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/translate.py +0 -0
  72. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/__init__.py +0 -0
  73. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/cli.py +0 -0
  74. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/pipeline.py +0 -0
  75. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/pricing.py +0 -0
  76. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/report.py +0 -0
  77. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
  78. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
  79. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
  80. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
  81. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
  82. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
  83. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
  84. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/bmsdna/devtools/worktree.py +0 -0
  85. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/justfile +0 -0
  86. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/skills/bmsdna-devtools/SKILL.md +0 -0
  87. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/conftest.py +0 -0
  88. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/fake_github.py +0 -0
  89. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_ado_auth.py +0 -0
  90. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_ado_issue.py +0 -0
  91. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_ado_issue_flow.py +0 -0
  92. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_agent_mentions.py +0 -0
  93. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_api_usage.py +0 -0
  94. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_app_service_logs.py +0 -0
  95. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_azure_arm.py +0 -0
  96. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_bdt_config.py +0 -0
  97. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_business_user.py +0 -0
  98. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_ci_plan.py +0 -0
  99. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_ci_plan_env.py +0 -0
  100. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_cleanup.py +0 -0
  101. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_commit.py +0 -0
  102. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_deps.py +0 -0
  103. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_issue.py +0 -0
  104. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_pr_create.py +0 -0
  105. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_pr_id.py +0 -0
  106. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_pull.py +0 -0
  107. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_tools.py +0 -0
  108. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_cli_version.py +0 -0
  109. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_commit.py +0 -0
  110. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_deps_advisories.py +0 -0
  111. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_deps_cooldown.py +0 -0
  112. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_deps_lockfiles.py +0 -0
  113. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_deps_osv.py +0 -0
  114. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_deps_versions.py +0 -0
  115. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_env_config.py +0 -0
  116. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_env_files.py +0 -0
  117. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_find_injection.py +0 -0
  118. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_find_repo.py +0 -0
  119. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_gh_issue.py +0 -0
  120. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_gh_pr.py +0 -0
  121. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_github_api.py +0 -0
  122. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_gitrepo.py +0 -0
  123. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_issue_do.py +0 -0
  124. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_issue_for_me.py +0 -0
  125. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_issue_show.py +0 -0
  126. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_issue_watch.py +0 -0
  127. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint.py +0 -0
  128. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint_models.py +0 -0
  129. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint_sql.py +0 -0
  130. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint_sql_files.py +0 -0
  131. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint_tooling.py +0 -0
  132. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_lint_typescript.py +0 -0
  133. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_logs.py +0 -0
  134. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_build.py +0 -0
  135. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_build_create_options.py +0 -0
  136. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_build_flow.py +0 -0
  137. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_cancel_build.py +0 -0
  138. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_choice.py +0 -0
  139. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_create_args.py +0 -0
  140. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_description_not_truncated.py +0 -0
  141. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_drift.py +0 -0
  142. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_info.py +0 -0
  143. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_issue_link.py +0 -0
  144. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_labels.py +0 -0
  145. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_markdown.py +0 -0
  146. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pr_merge_defaults.py +0 -0
  147. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_pull.py +0 -0
  148. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_testdb.py +0 -0
  149. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_translate.py +0 -0
  150. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_usage.py +0 -0
  151. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.59.0}/tests/test_worktree_clean.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bmsdna-devtools
3
- Version: 0.57.2
3
+ Version: 0.59.0
4
4
  Summary: Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects
5
5
  Requires-Python: >=3.14
6
6
  Requires-Dist: azure-identity>=1.19.0
@@ -38,7 +38,7 @@ from . import translate as translate_mod
38
38
  from . import pr_build, pr_cancel, pr_info as pr_info_mod, pr_issue_link, pr_merge_defaults, pr_ref, pr_labels, pull as pull_mod, worktree as worktree_mod
39
39
  from .ado_auth import AdoAuthError, ado_session, auth_header
40
40
  from .bdt_config import find_pyproject, load_bdt_table
41
- from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, require_gh
41
+ from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, limit_by_enclosing_timeout, require_gh
42
42
  from .github_api import GitHubClient
43
43
  from .pr_create_args import PrCreateArgsError, extract_labels, parse_pr_create_args, resolve_body, unsupported_notes
44
44
  from .deps.cli import deps_app
@@ -575,7 +575,8 @@ def pr_status(
575
575
  "--timeout",
576
576
  help="With --wait: stop after this many seconds if the checks are still running, print their current state and exit "
577
577
  f"{EXIT_WAIT_TIMEOUT} (0 = wait forever, the default). Use it where the caller's own time limit is shorter than CI, "
578
- "e.g. an agent's shell tool, then re-run the same command to keep waiting",
578
+ "e.g. an agent's shell tool, then re-run the same command to keep waiting. Under an enclosing `timeout N` (as in "
579
+ "`timeout 590 bdt pr status --wait`) it is cut to end shortly before that kills us, even without --timeout",
579
580
  ),
580
581
  pr_id: int | None = typer.Option(None, "--pr-id", help=_PR_ID_HELP),
581
582
  pat: str | None = typer.Option(None, "--pat", envvar=["AZURE_DEVOPS_EXT_PAT", "AZURE_DEVOPS_PAT"], help="Azure DevOps PAT (else uses DefaultAzureCredential, e.g. your `az login`)"),
@@ -586,6 +587,8 @@ def pr_status(
586
587
  if timeout and not wait:
587
588
  raise typer.BadParameter("--timeout only works together with --wait", param_hint="--timeout")
588
589
  _check_poll_options(None, timeout)
590
+ if wait:
591
+ timeout = limit_by_enclosing_timeout(timeout)
589
592
  remote = current_remote()
590
593
  if isinstance(remote, GitHubRemote):
591
594
  gh = require_gh()
@@ -9,12 +9,17 @@ concerns for arguments that come from user input, e.g. PR titles).
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
+ import math
12
13
  import os
14
+ import re
13
15
  import shutil
16
+ import signal
17
+ import subprocess
14
18
  import sys
15
19
  import time
16
20
  from collections.abc import Callable
17
21
  from dataclasses import dataclass
22
+ from types import FrameType, TracebackType
18
23
  from typing import NoReturn
19
24
 
20
25
  PSQL_INSTALL_HINT = "Install the PostgreSQL client tools (psql): https://www.postgresql.org/download/"
@@ -39,6 +44,11 @@ EXIT_WAIT_TIMEOUT = 4
39
44
  # not to spam a captured log.
40
45
  POLL_HEARTBEAT_SECS = 600.0
41
46
 
47
+ # How long before an enclosing `timeout N bdt pr status --wait` would kill us the wait loop gives up on its own
48
+ # (see `limit_by_enclosing_timeout`): enough for a poll that is in flight (HTTP_TIMEOUT_SECS) plus printing the
49
+ # per-build details of the final status.
50
+ ENCLOSING_TIMEOUT_MARGIN_SECS = 30.0
51
+
42
52
  # Bounds a single call to an external CLI (`gh`/`az`/`git`) or a single Azure DevOps REST
43
53
  # request. Without a timeout, a stalled network call or the CLI blocking on an interactive
44
54
  # prompt (e.g. an expired `az`/`gh` login) could hang a command -- most importantly a
@@ -78,30 +88,100 @@ class PollHeartbeat:
78
88
  self._last_print = now
79
89
 
80
90
 
91
+ # Windows: how long `WaitDeadline.sleep` sleeps at a time, so a stop signal is answered within about that long.
92
+ WINDOWS_SLEEP_SLICE_SECS = 1.0
93
+
94
+ # What asks a `--wait` loop to stop and report: SIGTERM (what `timeout`, `kill`, `docker stop` and most agent harnesses
95
+ # send first) and, on Windows, where SIGTERM is never delivered by the OS, Ctrl+Break. Windows lacks the rest.
96
+ _STOP_SIGNALS = tuple(sig for sig in (getattr(signal, "SIGTERM", None), getattr(signal, "SIGBREAK", None)) if sig is not None)
97
+
98
+
99
+ _SignalHandler = Callable[[int, FrameType | None], object] | int | None # what `signal.getsignal` returns
100
+
101
+
102
+ class _WaitStopped(Exception):
103
+ """Raised by the stop-signal handler inside `WaitDeadline.sleep` to cut the sleep short."""
104
+
105
+
81
106
  class WaitDeadline:
82
107
  """Optional overall time limit of a `--wait` poll loop (`timeout_secs` of 0 / None = wait forever).
83
108
 
84
109
  Exists because a caller often can't wait as long as CI takes: an agent's shell tool kills a command
85
110
  after a few minutes and throws its output away. Giving up on our own terms lets us report where things
86
111
  stand and exit with `EXIT_WAIT_TIMEOUT` so the caller knows to re-run.
112
+
113
+ With `stop_on_signal` (use it as a context manager, which puts the previous signal handlers back) a stop signal
114
+ does the same thing at once: `expired()` turns true and a running `sleep` ends, so the loop reports and exits
115
+ on its own instead of dying silently. The handler only sets a flag, and a second signal terminates as usual --
116
+ a loop stuck in a slow request can still be killed.
87
117
  """
88
118
 
89
- def __init__(self, timeout_secs: float | None) -> None:
119
+ def __init__(self, timeout_secs: float | None, *, stop_on_signal: bool = False) -> None:
90
120
  self.timeout_secs = timeout_secs or 0.0
91
121
  self._end = time.monotonic() + self.timeout_secs if self.timeout_secs else None
122
+ self.stopped_by_signal = False
123
+ self._sleeping = False
124
+ self._previous_handlers: dict[int, _SignalHandler] = {}
125
+ if stop_on_signal:
126
+ for sig in _STOP_SIGNALS:
127
+ try:
128
+ self._previous_handlers[sig] = signal.signal(sig, self._on_stop_signal)
129
+ except (ValueError, OSError): # not the main thread (ValueError), or the OS refuses this signal
130
+ pass
131
+
132
+ def __enter__(self) -> WaitDeadline:
133
+ return self
134
+
135
+ def __exit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None:
136
+ self._restore_handlers()
137
+
138
+ def _restore_handlers(self) -> None:
139
+ for sig, previous in self._previous_handlers.items():
140
+ try:
141
+ signal.signal(sig, previous if previous is not None else signal.SIG_DFL)
142
+ except (ValueError, OSError):
143
+ pass
144
+ self._previous_handlers.clear()
145
+
146
+ def _on_stop_signal(self, signum: int, frame: FrameType | None) -> None:
147
+ self.stopped_by_signal = True
148
+ self._restore_handlers()
149
+ if self._sleeping:
150
+ raise _WaitStopped
92
151
 
93
152
  def expired(self) -> bool:
94
- return self._end is not None and time.monotonic() >= self._end
153
+ return self.stopped_by_signal or (self._end is not None and time.monotonic() >= self._end)
95
154
 
96
155
  def sleep(self, secs: float) -> None:
97
- """`time.sleep(secs)`, cut short so the loop wakes up right at the deadline."""
98
- time.sleep(secs if self._end is None else max(0.0, min(secs, self._end - time.monotonic())))
156
+ """`time.sleep(secs)`, cut short so the loop wakes up right at the deadline (or when a stop signal arrives).
157
+ `_sleeping` goes up before the signal check, so a signal landing anywhere in between still ends the sleep;
158
+ the outer `try` also covers one landing in the `finally` that puts it back down."""
159
+ try:
160
+ self._sleeping = True
161
+ try:
162
+ if not self.stopped_by_signal:
163
+ self._sleep(secs if self._end is None else max(0.0, min(secs, self._end - time.monotonic())))
164
+ finally:
165
+ self._sleeping = False
166
+ except _WaitStopped:
167
+ pass
168
+
169
+ def _sleep(self, secs: float) -> None:
170
+ if sys.platform != "win32":
171
+ time.sleep(secs)
172
+ return
173
+ # Windows only runs a signal handler once `time.sleep` returns (it is woken by Ctrl+C alone): in slices, so
174
+ # a Ctrl+Break is answered within a second instead of after the full sleep
175
+ end = time.monotonic() + secs
176
+ while not self.stopped_by_signal and (left := end - time.monotonic()) > 0:
177
+ time.sleep(min(left, WINDOWS_SLEEP_SLICE_SECS))
99
178
 
100
179
 
101
180
  def status_rerun_cmd(pr_id: int | None, timeout_secs: float) -> str:
102
181
  """The command that keeps waiting where a timed-out `pr status --wait` stopped. Pins `--pr-id` to the PR that
103
182
  was being watched, so re-running can't resolve to a different PR (e.g. another branch checked out since)."""
104
- return f"bdt pr status --pr-id {pr_id} --wait --timeout {timeout_secs:g}" if pr_id else f"bdt pr status --wait --timeout {timeout_secs:g}"
183
+ cmd = f"bdt pr status --pr-id {pr_id} --wait" if pr_id else "bdt pr status --wait"
184
+ return f"{cmd} --timeout {timeout_secs:g}" if timeout_secs else cmd
105
185
 
106
186
 
107
187
  def exit_wait_timeout(msg: str, print_details: Callable[[], object], deadline: WaitDeadline, rerun_cmd: str) -> NoReturn:
@@ -110,10 +190,111 @@ def exit_wait_timeout(msg: str, print_details: Callable[[], object], deadline: W
110
190
  print(msg)
111
191
  print("\nDetails:")
112
192
  print_details()
113
- print(f"\nStill running after {deadline.timeout_secs:g} s. Re-run `{rerun_cmd}` to keep waiting.")
193
+ if deadline.stopped_by_signal:
194
+ print(f"\nTerminated while still running. Re-run `{rerun_cmd}` to keep waiting.")
195
+ else:
196
+ print(f"\nStill running after {deadline.timeout_secs:g} s. Re-run `{rerun_cmd}` to keep waiting.")
114
197
  sys.exit(EXIT_WAIT_TIMEOUT)
115
198
 
116
199
 
200
+ _TIMEOUT_COMMANDS = ("timeout", "gtimeout") # GNU coreutils; macOS has it as `gtimeout` unless aliased
201
+ _TIMEOUT_LONG_OPTIONS_WITH_VALUE = ("--kill-after", "--signal")
202
+ _DURATION_UNITS = {"": 1, "s": 1, "m": 60, "h": 3600, "d": 86400}
203
+ _ETIME_RE = re.compile(r"^(?:(?:(\d+)-)?(\d+):)?(\d+):(\d+)$") # [[dd-]hh:]mm:ss, as printed by `ps -o etime`
204
+ _MAX_ANCESTORS = 8
205
+
206
+
207
+ def parse_timeout_command(args: list[str]) -> float | None:
208
+ """The duration (seconds) of a `timeout [OPTION]... DURATION COMMAND...` command line, or None if `args` isn't
209
+ one, the duration is 0 / infinite (= no limit) or the options can't be read with confidence: not detecting a
210
+ limit is harmless, a wrong one would cut the wait short."""
211
+ if not args or os.path.basename(args[0]) not in _TIMEOUT_COMMANDS:
212
+ return None
213
+ rest = iter(args[1:])
214
+ for arg in rest:
215
+ if arg == "--":
216
+ arg = next(rest, "")
217
+ elif arg.startswith("--"):
218
+ # getopt accepts any unambiguous prefix of a long option (`--kill 5`)
219
+ if "=" not in arg and len(arg) > 2 and any(opt.startswith(arg) for opt in _TIMEOUT_LONG_OPTIONS_WITH_VALUE):
220
+ next(rest, None)
221
+ continue
222
+ elif arg.startswith("-") and arg != "-":
223
+ for pos, flag in enumerate(arg[1:], start=1):
224
+ if flag in "ks": # the value is the rest of the cluster (`-k5`), else the next argument
225
+ if pos == len(arg) - 1:
226
+ next(rest, None)
227
+ break
228
+ if flag not in "fpv":
229
+ return None
230
+ continue
231
+ return _parse_duration(arg)
232
+ return None
233
+
234
+
235
+ def _parse_duration(text: str) -> float | None:
236
+ m = re.fullmatch(r"(.+?)([smhd]?)", text)
237
+ try:
238
+ seconds = float(m.group(1)) * _DURATION_UNITS[m.group(2)] if m else 0.0
239
+ except ValueError:
240
+ return None
241
+ return seconds if math.isfinite(seconds) and seconds > 0 else None
242
+
243
+
244
+ def _parse_etime(text: str) -> float | None:
245
+ m = _ETIME_RE.match(text.strip())
246
+ if not m:
247
+ return None
248
+ days, hours, minutes, seconds = (int(g or 0) for g in m.groups())
249
+ return float(((days * 24 + hours) * 60 + minutes) * 60 + seconds)
250
+
251
+
252
+ def _process_info(pid: int) -> tuple[int, float, list[str]] | None:
253
+ """(parent pid, seconds since it started, command line) of process `pid`, via `ps` (Linux and macOS; None
254
+ anywhere it isn't available, e.g. Windows)."""
255
+ try:
256
+ r = subprocess.run(["ps", "-o", "ppid=,etime=,args=", "-p", str(pid)], capture_output=True, encoding="utf-8", timeout=CLI_TIMEOUT_SECS, check=False)
257
+ except (OSError, subprocess.SubprocessError):
258
+ return None
259
+ parts = r.stdout.split(None, 2)
260
+ if r.returncode != 0 or len(parts) < 3 or not parts[0].isdigit():
261
+ return None
262
+ elapsed = _parse_etime(parts[1])
263
+ return (int(parts[0]), elapsed, parts[2].split()) if elapsed is not None else None
264
+
265
+
266
+ def enclosing_timeout_remaining() -> float | None:
267
+ """Seconds until a `timeout N ...` wrapped around this process (as in `timeout 590 bdt pr status --wait`) kills
268
+ it, or None when there is none (the closest limit when several are nested). Best-effort: walks up the parent
269
+ processes, so it also sees through the shells and launcher shims in between."""
270
+ remaining: float | None = None
271
+ pid = os.getppid()
272
+ for _ in range(_MAX_ANCESTORS):
273
+ if pid < 1 or (info := _process_info(pid)) is None:
274
+ break
275
+ ppid, elapsed, args = info
276
+ limit = parse_timeout_command(args)
277
+ if limit is not None:
278
+ remaining = min(remaining if remaining is not None else limit, max(limit - elapsed, 0.0))
279
+ pid = ppid
280
+ return remaining
281
+
282
+
283
+ def limit_by_enclosing_timeout(timeout_secs: float) -> float:
284
+ """`timeout_secs` of a `--wait` loop (0 = forever), cut down to end `ENCLOSING_TIMEOUT_MARGIN_SECS` before an
285
+ enclosing `timeout N` would kill us. Otherwise that kill drops everything we would have printed, which is
286
+ exactly what `--timeout` is there to avoid -- and callers (agents) keep wrapping the command in `timeout`
287
+ instead of passing `--timeout`."""
288
+ remaining = enclosing_timeout_remaining()
289
+ if remaining is None:
290
+ return timeout_secs
291
+ limit = max(remaining - ENCLOSING_TIMEOUT_MARGIN_SECS, 1.0)
292
+ if timeout_secs and timeout_secs <= limit:
293
+ return timeout_secs
294
+ print(f"Enclosing `timeout` ends in {remaining:.0f} s: giving up waiting after {limit:.0f} s so the status gets printed first.", file=sys.stderr)
295
+ return limit
296
+
297
+
117
298
  def is_claude_code() -> bool:
118
299
  """True if this process is running as a subprocess of Claude Code.
119
300
 
@@ -550,9 +550,13 @@ def exit_needs_approval(msg: str, item_lines: list[str], rerun_cmd: str) -> None
550
550
 
551
551
  def run(gh: GitHubClient, wait: bool, pr_id: int | None = None, timeout: float = 0) -> None:
552
552
  """`timeout` (seconds, only with `wait`): stop polling after that long and exit `EXIT_WAIT_TIMEOUT`
553
- with the current state; 0 = wait until every check is done."""
553
+ with the current state; 0 = wait until every check is done. A SIGTERM while waiting does the same at once."""
554
+ with WaitDeadline(timeout, stop_on_signal=wait) as deadline:
555
+ _status(gh, wait, pr_id, timeout, deadline)
556
+
557
+
558
+ def _status(gh: GitHubClient, wait: bool, pr_id: int | None, timeout: float, deadline: WaitDeadline) -> None:
554
559
  heartbeat = PollHeartbeat()
555
- deadline = WaitDeadline(timeout)
556
560
  draft_notice_shown = False
557
561
  while True:
558
562
  pr = get_pr(gh, pr_id)
@@ -562,7 +566,11 @@ def run(gh: GitHubClient, wait: bool, pr_id: int | None = None, timeout: float =
562
566
  # isn't safe (could spin forever if it never resolves) — only retry
563
567
  # when the caller already opted into waiting.
564
568
  if pr.get("mergeable") == UNKNOWN_MERGEABLE and wait:
565
- time.sleep(3)
569
+ if deadline.expired():
570
+ exit_wait_timeout(
571
+ f"PR #{pr.get('number')}: {pr.get('title', '?')} | mergeability not computed yet", lambda: None, deadline, status_rerun_cmd(pr.get("number"), timeout)
572
+ )
573
+ deadline.sleep(3)
566
574
  continue
567
575
 
568
576
  conflict = merge_conflict_message(pr)
@@ -1216,7 +1216,21 @@ def run(
1216
1216
  timeout: float = 0,
1217
1217
  ) -> None:
1218
1218
  """`timeout` (seconds, only with `wait`): stop polling after that long and exit `EXIT_WAIT_TIMEOUT`
1219
- with the current state; 0 = wait until every pipeline is done."""
1219
+ with the current state; 0 = wait until every pipeline is done. A SIGTERM while waiting does the same at once."""
1220
+ with WaitDeadline(timeout, stop_on_signal=wait) as deadline:
1221
+ _status(remote, pat, target_branch, wait, source_branch, pr_id, timeout, deadline)
1222
+
1223
+
1224
+ def _status(
1225
+ remote: AdoRemote,
1226
+ pat: str | None,
1227
+ target_branch: str | None,
1228
+ wait: bool,
1229
+ source_branch: str | None,
1230
+ pr_id: int | None,
1231
+ timeout: float,
1232
+ deadline: WaitDeadline,
1233
+ ) -> None:
1220
1234
  session = ado_session(pat)
1221
1235
 
1222
1236
  def fetch_pr() -> dict:
@@ -1254,7 +1268,6 @@ def run(
1254
1268
  drift_notice_shown: str | None = None
1255
1269
  policy_checked = False
1256
1270
  heartbeat = PollHeartbeat()
1257
- deadline = WaitDeadline(timeout)
1258
1271
 
1259
1272
  def time_out(msg: str, builds: list, pr_number: int) -> NoReturn:
1260
1273
  exit_wait_timeout(msg, lambda: [print_build(session, remote, b) for b in builds], deadline, status_rerun_cmd(pr_number, timeout))
@@ -10,7 +10,7 @@ packages = ["bmsdna"]
10
10
 
11
11
  [project]
12
12
  name = "bmsdna-devtools"
13
- version = "0.57.2"
13
+ version = "0.59.0"
14
14
  description = "Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects"
15
15
  readme = "README.md"
16
16
  requires-python = ">=3.14" # pgdevkit>=0.7.1 requires 3.14; was >=3.11 before adding it as a dependency