MCPcopy
hub / github.com/openai/openai-python / main

Function main

scripts/utils/validate-bedrock-wheel.py:74–119  ·  scripts/utils/validate-bedrock-wheel.py::main
()

Source from the content-addressed store, hash-verified

72
73
74def main() -> None:
75 wheels = list(Path(class="st">"dist").glob(class="st">"*.whl"))
76 if len(wheels) != 1:
77 raise RuntimeError(fclass="st">"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(class="st">".dist-info/METADATA")]
84 if len(metadata_names) != 1:
85 raise RuntimeError(fclass="st">"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(class="st">"Requires-Dist", [])
91 botocore_requirements = [requirement for requirement in requirements if requirement.startswith(class="st">"botocore")]
92 if len(botocore_requirements) != 2:
93 raise RuntimeError(fclass="st">"Expected two Python-version-specific botocore requirements: {botocore_requirements}")
94 if any(class="st">"[crt]" in requirement for requirement in botocore_requirements):
95 raise RuntimeError(
96 fclass="st">"The Bedrock extra must not install the unused botocore CRT extra: {botocore_requirements}"
97 )
98 if not all(class="st">"extra == &class="cm">#x27;bedrock'" in requirement for requirement in botocore_requirements):
99 raise RuntimeError(fclass="st">"Botocore requirements must belong to the Bedrock extra: {botocore_requirements}")
100
101 environment = os.environ.copy()
102 for name in (
103 class="st">"AWS_ACCESS_KEY_ID",
104 class="st">"AWS_SECRET_ACCESS_KEY",
105 class="st">"AWS_SESSION_TOKEN",
106 class="st">"AWS_PROFILE",
107 class="st">"AWS_REGION",
108 class="st">"AWS_DEFAULT_REGION",
109 class="st">"AWS_BEARER_TOKEN_BEDROCK",
110 class="st">"AWS_BEDROCK_BASE_URL",
111 class="st">"OPENAI_API_KEY",
112 class="st">"OPENAI_ORG_ID",
113 class="st">"OPENAI_PROJECT_ID",
114 class="st">"OPENAI_CUSTOM_HEADERS",
115 ):
116 environment.pop(name, None)
117 environment[class="st">"OPENAI_WHEEL_ROOT"] = str(wheel_root)
118 environment[class="st">"PYTHONPATH"] = str(wheel_root)
119 subprocess.run([sys.executable, class="st">"-c", _SMOKE_TEST], cwd=wheel_root, env=environment, check=True)
120
121
122if __name__ == class="st">"__main__":

Callers 1

Calls 3

readMethod · 0.45
copyMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected