diff --git a/changelog.d/+built-sdist-import-check.infrastructure.md b/changelog.d/+built-sdist-import-check.infrastructure.md new file mode 100644 index 00000000..ba7469b9 --- /dev/null +++ b/changelog.d/+built-sdist-import-check.infrastructure.md @@ -0,0 +1 @@ +Add a build-time smoke test that installs the freshly built source distribution and imports the public API shims. diff --git a/noxfile.py b/noxfile.py index 4458bf30..fedc60dd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -178,6 +178,7 @@ def cover(session): @nox.session(python=PYTHON_DEFAULT_VERSION) def build(session): """Build the distribution.""" + session.run('rm', '-rf', 'build', 'dist', external=True) session.run('uv', 'build', external=True) # Set outputs for GitHub Actions @@ -190,6 +191,32 @@ def build(session): version = os.environ['GITHUB_REF'].replace('refs/tags/v', '') print(f'version={version}', file=github_output) + sdists = sorted(pathlib.Path('dist').glob('b2sdk-*.tar.gz')) + if len(sdists) != 1: + session.error(f'Expected exactly one source distribution, found {len(sdists)}: {sdists!r}') + + session.install(str(sdists[0])) + session.cd('dist') # avoid importing from the checkout instead of the built package + session.run( + 'python', + '-c', + ( + 'import pathlib; ' + 'from b2sdk import v0, v1, v2, v3; ' + 'repo_root = pathlib.Path.cwd().parent.resolve(); ' + 'source_root = repo_root / "b2sdk"; ' + "module_files = {'v0': pathlib.Path(v0.__file__).resolve(), " + "'v1': pathlib.Path(v1.__file__).resolve(), " + "'v2': pathlib.Path(v2.__file__).resolve(), " + "'v3': pathlib.Path(v3.__file__).resolve()}; " + 'print(module_files); ' + "assert all(not path.is_relative_to(source_root) for path in module_files.values()), " + "f'Imported modules from checkout: {module_files!r}'; " + "assert all('site-packages' in path.parts for path in module_files.values()), " + "f'Imported modules from an unexpected location: {module_files!r}'" + ), + ) + @nox.session(python=PYTHON_DEFAULT_VERSION) def doc(session):