Complete worked example
python
import json
from pathlib import Path
import subprocess
import sys
import venv
def inspect_example(rows, minimum):
project = Path('project').resolve()
subprocess.run([sys.executable, '-m', 'build', '--no-isolation', '--wheel', '--outdir', 'dist'],
cwd=project, capture_output=True, text=True, check=True)
wheel = next((project / 'dist').glob('*.whl'))
environment = Path('installed').resolve()
venv.EnvBuilder(with_pip=True).create(environment)
python = environment / ('Scripts/python.exe' if sys.platform == 'win32' else 'bin/python')
subprocess.run([str(python), '-I', '-m', 'pip', 'install', '--no-index', '--no-deps', str(wheel)],
capture_output=True, text=True, check=True)
outside = Path('outside').resolve()
outside.mkdir()
command = [str(python), '-I', '-m', 'pye_owned', '--minimum', str(minimum)]
run = subprocess.run(command, cwd=outside, input=json.dumps(rows),
capture_output=True, text=True, check=True)
return json.loads(run.stdout)- Reasoning
- The fixture package contains reusable selection logic, a CLI module, a __main__ delegate and a defaults resource. The displayed project files show those separate responsibilities. The driver sends rows as JSON on standard input and passes the inclusive minimum as an explicit command-line option.