Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | """Check the built stable train against the frozen project metadata.""" |
| 2 | import email.parser |
| 3 | import pathlib |
| 4 | import tarfile |
| 5 | import tomllib |
| 6 | import zipfile |
| 7 | |
| 8 | from packaging.requirements import Requirement |
| 9 | from packaging.specifiers import SpecifierSet |
| 10 | from packaging.utils import canonicalize_name |
| 11 | |
| 12 | root = pathlib.Path(__file__).resolve().parents[2] |
| 13 | projects = [root / 'python', *sorted((root / 'python/providers').glob('*/pyproject.toml'))] |
| 14 | projects = [path.parent if path.is_file() else path for path in projects] |
| 15 | distributions = root / 'python/dist' |
| 16 | expected = set() |
| 17 | |
| 18 | |
| 19 | def requirement(value): |
| 20 | parsed = Requirement(value) |
| 21 | return (canonicalize_name(parsed.name), tuple(sorted(parsed.extras)), str(parsed.specifier), str(parsed.marker or '')) |
| 22 | |
| 23 | |
| 24 | for directory in projects: |
| 25 | project = tomllib.loads((directory / 'pyproject.toml').read_text())['project'] |
| 26 | name = canonicalize_name(project['name']) |
| 27 | version = project['version'] |
| 28 | wheels = list(distributions.glob(f'{name.replace("-", "_")}-{version}-*.whl')) |
| 29 | sdists = list(distributions.glob(f'{name.replace("-", "_")}-{version}.tar.gz')) |
| 30 | assert len(wheels) == len(sdists) == 1, f'Expected one wheel and sdist for {name}' |
| 31 | expected.update([wheels[0].name, sdists[0].name]) |
| 32 | with zipfile.ZipFile(wheels[0]) as wheel: |
| 33 | metadata_paths = [path for path in wheel.namelist() if path.endswith('.dist-info/METADATA')] |
| 34 | assert len(metadata_paths) == 1 |
| 35 | metadata = email.parser.BytesParser().parsebytes(wheel.read(metadata_paths[0])) |
| 36 | assert any(path.endswith('/py.typed') for path in wheel.namelist()), f'Missing typed marker: {name}' |
| 37 | with tarfile.open(sdists[0]) as sdist: |
| 38 | package_info = [entry for entry in sdist.getmembers() if entry.name.count('/') == 1 and entry.name.endswith('/PKG-INFO')] |
| 39 | assert len(package_info) == 1 |
| 40 | stream = sdist.extractfile(package_info[0]) |
| 41 | assert stream is not None |
| 42 | sdist_metadata = email.parser.BytesParser().parsebytes(stream.read()) |
| 43 | for built in [metadata, sdist_metadata]: |
| 44 | assert canonicalize_name(built['Name']) == name and built['Version'] == version |
| 45 | assert SpecifierSet(built['Requires-Python'] or '') == SpecifierSet(project.get('requires-python', '')), f'Python requirement changed: {name}' |
| 46 | actual = [requirement(value) for value in built.get_all('Requires-Dist', []) if 'extra ==' not in value] |
| 47 | wanted = [requirement(value) for value in project.get('dependencies', [])] |
| 48 | assert sorted(actual) == sorted(wanted), f'Dependency metadata changed: {name}' |
| 49 | |
| 50 | actual = {path.name for path in distributions.iterdir() if path.name.endswith(('.whl', '.tar.gz'))} |
| 51 | assert actual == expected, f'Distribution inventory mismatch: {actual ^ expected}' |
| 52 | print(f'Validated {len(projects)} projects and {len(expected)} distributions') |