Complete worked example
python
from email.parser import BytesParser
from pathlib import Path
import subprocess
import sys
import tarfile
from zipfile import ZipFile
def inspect_example(version):
project = Path('project')
config = project / 'pyproject.toml'
config.write_text(config.read_text().replace('version = "1.0.0"', f'version = "{version}"'))
subprocess.run([sys.executable, '-m', 'build', '--no-isolation', '--sdist', '--wheel',
'--outdir', 'dist'], cwd=project, capture_output=True, text=True, check=True)
wheel = next((project / 'dist').glob('*.whl'))
source = next((project / 'dist').glob('*.tar.gz'))
with ZipFile(wheel) as bundle:
names = bundle.namelist()
metadata = BytesParser().parsebytes(bundle.read(next(n for n in names if n.endswith('/METADATA'))))
with tarfile.open(source) as archive:
source_names = archive.getnames()
return {'version': metadata['Version'], 'resource': 'pye_owned/defaults.json' in names,
'sourceConfig': any(n.endswith('/pyproject.toml') for n in source_names),
'wheelConfig': 'pyproject.toml' in names}- Reasoning
- Each case receives a fresh owned project directory. The driver changes its declared version, builds with the already installed pinned backend and opens the generated artifacts. It reads Version from the wheel's METADATA rather than inferring the release from a source constant.