()
| 72 | |
| 73 | |
| 74 | def main() -> None: |
| 75 | wheels = list(Path("dist").glob("*.whl")) |
| 76 | if len(wheels) != 1: |
| 77 | raise RuntimeError(f"Expected exactly one wheel in dist/, found: {wheels}") |
| 78 | |
| 79 | wheel = wheels[0] |
| 80 | with tempfile.TemporaryDirectory() as directory: |
| 81 | wheel_root = Path(directory) |
| 82 | with zipfile.ZipFile(wheel) as archive: |
| 83 | metadata_names = [name for name in archive.namelist() if name.endswith(".dist-info/METADATA")] |
| 84 | if len(metadata_names) != 1: |
| 85 | raise RuntimeError(f"Expected exactly one METADATA file in {wheel}, found: {metadata_names}") |
| 86 | |
| 87 | metadata = email.message_from_bytes(archive.read(metadata_names[0])) |
| 88 | archive.extractall(wheel_root) |
| 89 | |
| 90 | requirements = metadata.get_all("Requires-Dist", []) |
| 91 | botocore_requirements = [requirement for requirement in requirements if requirement.startswith("botocore")] |
| 92 | if len(botocore_requirements) != 2: |
| 93 | raise RuntimeError(f"Expected two Python-version-specific botocore requirements: {botocore_requirements}") |
| 94 | if any("[crt]" in requirement for requirement in botocore_requirements): |
| 95 | raise RuntimeError( |
| 96 | f"The Bedrock extra must not install the unused botocore CRT extra: {botocore_requirements}" |
| 97 | ) |
| 98 | if not all("extra == 'bedrock'" in requirement for requirement in botocore_requirements): |
| 99 | raise RuntimeError(f"Botocore requirements must belong to the Bedrock extra: {botocore_requirements}") |
| 100 | |
| 101 | environment = os.environ.copy() |
| 102 | for name in ( |
| 103 | "AWS_ACCESS_KEY_ID", |
| 104 | "AWS_SECRET_ACCESS_KEY", |
| 105 | "AWS_SESSION_TOKEN", |
| 106 | "AWS_PROFILE", |
| 107 | "AWS_REGION", |
| 108 | "AWS_DEFAULT_REGION", |
| 109 | "AWS_BEARER_TOKEN_BEDROCK", |
| 110 | "AWS_BEDROCK_BASE_URL", |
| 111 | "OPENAI_API_KEY", |
| 112 | "OPENAI_ORG_ID", |
| 113 | "OPENAI_PROJECT_ID", |
| 114 | "OPENAI_CUSTOM_HEADERS", |
| 115 | ): |
| 116 | environment.pop(name, None) |
| 117 | environment["OPENAI_WHEEL_ROOT"] = str(wheel_root) |
| 118 | environment["PYTHONPATH"] = str(wheel_root) |
| 119 | subprocess.run([sys.executable, "-c", _SMOKE_TEST], cwd=wheel_root, env=environment, check=True) |
| 120 | |
| 121 | |
| 122 | if __name__ == "__main__": |
no test coverage detected