Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fd2ab3d
Add generate_api_text.py script.
tjprescott May 28, 2026
ebb3870
Add PR creation script.
tjprescott May 29, 2026
2d24fa9
Review feedback.
tjprescott May 29, 2026
e4b2876
Add scripts for syncing api.md
tjprescott Jun 2, 2026
dd1b565
Refactor create_api_review_pr from Python to JS in a module way.
tjprescott Jun 2, 2026
688e16f
Remove update process and just have a consistency check.
tjprescott Jun 2, 2026
323d4f3
Add minor change to azure-template to test pipeline.
tjprescott Jun 2, 2026
93184af
Add API.md to test mismatch.
tjprescott Jun 2, 2026
7680ff6
Apply actual api.md
tjprescott Jun 2, 2026
33c39cf
Update GitHub Actions to latest major versions
Copilot Jun 3, 2026
15534d7
Add shared JS scripts from rest-api-specs repo.
tjprescott Jun 3, 2026
19f65ac
Refactor scripts to use shared code and simplify.
tjprescott Jun 3, 2026
9d0946e
Code review feedback.
tjprescott Jun 3, 2026
ec760b0
Add generated API.md for azure-template
Copilot Jun 3, 2026
d04b5db
Refactor to use `azpysdk apistub --md` command.
tjprescott Jun 3, 2026
825c684
Merge branch 'GenerateAPITextScript' of https://github.com/Azure/azur…
tjprescott Jun 3, 2026
7f8eeb5
Remove Python 3.10 limit on apistub.py.
tjprescott Jun 3, 2026
c75faac
Refactor `azpysdk apistub` command. Extract metadata from API.md.
tjprescott Jun 3, 2026
dfe985c
Add validation for select metadata fields.
tjprescott Jun 3, 2026
9d8137c
CI fixes.
tjprescott Jun 3, 2026
760fc63
Add skill for generating review PR.
tjprescott Jun 3, 2026
1517d58
Update review generation logic.
tjprescott Jun 3, 2026
258a36a
fix(python adapter): add shell:true on Windows for spawnSync
tjprescott Jun 3, 2026
89e6c98
fix(python adapter): pass --dest-dir so API.md lands in package dir
tjprescott Jun 3, 2026
62f81e3
fix(python adapter): skip _generated dirs in readVersion to avoid sta…
tjprescott Jun 3, 2026
92e0c92
Make script idempotent and reuse branches with the same API hash.
tjprescott Jun 4, 2026
bb253fa
Code review feedback.
tjprescott Jun 5, 2026
317bd4c
Updates.
tjprescott Jun 5, 2026
a82a7ee
Make review PR creation only work for updates, not new packages.
tjprescott Jun 5, 2026
8d07492
CI fixes.
tjprescott Jun 5, 2026
da6a96e
Use shared helper method.
tjprescott Jun 8, 2026
8fdfca0
Add metadata to review PRs.
tjprescott Jun 8, 2026
341ee63
Code review feedback.
tjprescott Jun 8, 2026
6c93b82
Add package-lock.json
tjprescott Jun 8, 2026
c7903bc
Merge branch 'main' into GenerateAPITextScript
tjprescott Jun 9, 2026
8859f30
Refactor to use simple-git and octokit
tjprescott Jun 9, 2026
7e82410
Code review feedback.
tjprescott Jun 9, 2026
3d207c2
Remove template APIs.
tjprescott Jun 9, 2026
650f534
Code review feedback.
tjprescott Jun 9, 2026
c151395
Refactor review create script to Python.
tjprescott Jun 10, 2026
a94221a
Test consistency refactor.
tjprescott Jun 10, 2026
109aec8
Improve failure logging. Fix CI
tjprescott Jun 10, 2026
58ff53e
Test resovling consistency
tjprescott Jun 10, 2026
a7cabe5
Script fixes.
tjprescott Jun 10, 2026
dd3e9d9
Tweaks and remove APIs (more testing)
tjprescott Jun 10, 2026
143033b
Code review feedback.
tjprescott Jun 10, 2026
75f904e
Consolidate package.json.
tjprescott Jun 10, 2026
094fedf
Code review feedback
tjprescott Jun 12, 2026
91e5d84
restore chronus
mikeharder Jun 12, 2026
223227e
remove .github/package.json
mikeharder Jun 12, 2026
fed552b
remove unnecessary shared src
mikeharder Jun 12, 2026
d993261
add readme with "copied from"
mikeharder Jun 12, 2026
0f28a92
Merge branch 'main' into GenerateAPITextScript
mikeharder Jun 12, 2026
edab959
Merge branch 'main' into GenerateAPITextScript
mikeharder Jun 12, 2026
414b967
Fix CI
tjprescott Jun 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions scripts/generate_api_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/env python
"""Generate API.md for an Azure SDK package.

Usage:
python scripts/generate_api_text.py azure-ai-projects
"""
Comment thread
tjprescott marked this conversation as resolved.
Outdated
Comment thread
tjprescott marked this conversation as resolved.
Outdated

import argparse
import glob
import os
import shutil
import subprocess
import sys
import tempfile


REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
APIVIEW_REQS = os.path.join(REPO_ROOT, "eng", "apiview_reqs.txt")
AZURE_SDK_INDEX = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
EXPORT_SCRIPT = os.path.join(REPO_ROOT, "eng", "common", "scripts", "Export-APIViewMarkdown.ps1")


def find_package_dir(package_name: str) -> str:
"""Find the package directory under sdk/*/{package_name}/."""
pattern = os.path.join(REPO_ROOT, "sdk", "*", package_name)
matches = glob.glob(pattern)
# Filter to directories that contain a pyproject.toml or setup.py
valid = [
m for m in matches
if os.path.isdir(m) and (
os.path.exists(os.path.join(m, "pyproject.toml"))
or os.path.exists(os.path.join(m, "setup.py"))
)
]
if not valid:
raise FileNotFoundError(f"Package '{package_name}' not found under sdk/*/")
if len(valid) > 1:
raise ValueError(f"Multiple matches for '{package_name}': {valid}")
return valid[0]


def get_installed_version(package: str) -> str | None:
"""Get the currently installed version of a package, or None."""
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "show", package],
capture_output=True, text=True, check=True,
)
for line in result.stdout.splitlines():
if line.startswith("Version:"):
return line.split(":", 1)[1].strip()
except subprocess.CalledProcessError:
pass
return None


def get_latest_version(package: str) -> str | None:
"""Query the Azure SDK feed for the latest version of a package."""
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "index", "versions", package,
"--index-url", AZURE_SDK_INDEX],
capture_output=True, text=True, check=True,
)
# Output format: "apiview-stub-generator (0.3.28)"
for line in result.stdout.splitlines():
if package in line and "(" in line:
version = line.split("(")[1].split(")")[0].strip()
return version
except subprocess.CalledProcessError:
pass
return None


def ensure_latest_apiview_stub_generator():
"""Ensure the latest apiview-stub-generator is installed from the Azure SDK feed."""
installed = get_installed_version("apiview-stub-generator")
latest = get_latest_version("apiview-stub-generator")

Comment thread
tjprescott marked this conversation as resolved.
Outdated
print(f"apiview-stub-generator: installed={installed}, latest={latest}")

if installed and latest and installed == latest:
print("Already at latest version.")
return

# Install from apiview_reqs.txt first (gets dependencies right)
print("Installing apiview_reqs.txt...")
subprocess.run(
[sys.executable, "-m", "pip", "install", "-r", APIVIEW_REQS,
f"--index-url={AZURE_SDK_INDEX}"],
check=True,
)
Comment thread
tjprescott marked this conversation as resolved.
Outdated

# Override with latest version (not the pinned one)
print("Upgrading apiview-stub-generator to latest...")
subprocess.run(
[sys.executable, "-m", "pip", "install", "--upgrade", "apiview-stub-generator",
f"--index-url={AZURE_SDK_INDEX}"],
check=True,
)
Comment thread
tjprescott marked this conversation as resolved.
Outdated

new_version = get_installed_version("apiview-stub-generator")
print(f"apiview-stub-generator now at version {new_version}")
Comment thread
tjprescott marked this conversation as resolved.
Outdated


def build_wheel(package_dir: str, output_dir: str) -> str:
"""Build a wheel for the package and return the path to the .whl file."""
subprocess.run(
[sys.executable, "-m", "pip", "wheel", package_dir, "--no-deps", "-w", output_dir],
check=True,
)
whls = glob.glob(os.path.join(output_dir, "*.whl"))
if not whls:
raise FileNotFoundError(f"No .whl file found in {output_dir}")
return whls[0]


def run_apistub(whl_path: str, out_path: str):
"""Run apiview-stub-generator on the wheel."""
subprocess.run(
[sys.executable, "-m", "apistub",
"--pkg-path", whl_path,
"--out-path", out_path,
"--skip-pylint"],
check=True,
)
Comment thread
tjprescott marked this conversation as resolved.
Outdated


def export_api_markdown(token_json_path: str, output_path: str):
"""Run the Export-APIViewMarkdown.ps1 script to convert token JSON to API.md."""
subprocess.run(
["pwsh", EXPORT_SCRIPT, "-TokenJsonPath", token_json_path, "-OutputPath", output_path],
check=True,
)
Comment thread
tjprescott marked this conversation as resolved.
Outdated


def main():
parser = argparse.ArgumentParser(description="Generate API.md for an Azure SDK package.")
parser.add_argument("package", help="Package name (e.g. azure-ai-projects)")
args = parser.parse_args()

package_name = args.package
print(f"Generating API.md for {package_name}...")

# Find the package
package_dir = find_package_dir(package_name)
print(f"Found package at: {package_dir}")

# Ensure latest apiview-stub-generator
ensure_latest_apiview_stub_generator()

# Build wheel in a temp directory
tmp_dir = tempfile.mkdtemp(prefix="apistub_")
try:
print("Building wheel...")
whl_path = build_wheel(package_dir, tmp_dir)
print(f"Built: {os.path.basename(whl_path)}")

# Run apiview-stub-generator
print("Running apiview-stub-generator...")
run_apistub(whl_path, tmp_dir)

# Find the generated token JSON
token_json = os.path.join(tmp_dir, f"{package_name}_python.json")
if not os.path.exists(token_json):
# Try with underscores (package name normalization)
normalized = package_name.replace("-", "_")
token_json = os.path.join(tmp_dir, f"{normalized}_python.json")
if not os.path.exists(token_json):
# Find any json file
jsons = glob.glob(os.path.join(tmp_dir, "*_python.json"))
if jsons:
token_json = jsons[0]
else:
raise FileNotFoundError(f"No token JSON found in {tmp_dir}")

# Export to API.md
api_md_path = os.path.join(package_dir, "API.md")
print("Exporting API.md...")
export_api_markdown(token_json, api_md_path)
print(f"Generated: {api_md_path}")

finally:
# Clean up temp directory (wheel + token json)
shutil.rmtree(tmp_dir, ignore_errors=True)


if __name__ == "__main__":
main()
Loading