Skip to content

Commit d2c6fc0

Browse files
authored
Merge pull request #337 from Backblaze/ci-test-import
Add import testing on the source package after it's built
2 parents 128dbab + 2fabc9d commit d2c6fc0

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a build-time smoke test that installs the freshly built source distribution and imports the public API shims.

noxfile.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def cover(session):
178178
@nox.session(python=PYTHON_DEFAULT_VERSION)
179179
def build(session):
180180
"""Build the distribution."""
181+
session.run('rm', '-rf', 'build', 'dist', external=True)
181182
session.run('uv', 'build', external=True)
182183

183184
# Set outputs for GitHub Actions
@@ -190,6 +191,32 @@ def build(session):
190191
version = os.environ['GITHUB_REF'].replace('refs/tags/v', '')
191192
print(f'version={version}', file=github_output)
192193

194+
sdists = sorted(pathlib.Path('dist').glob('b2sdk-*.tar.gz'))
195+
if len(sdists) != 1:
196+
session.error(f'Expected exactly one source distribution, found {len(sdists)}: {sdists!r}')
197+
198+
session.install(str(sdists[0]))
199+
session.cd('dist') # avoid importing from the checkout instead of the built package
200+
session.run(
201+
'python',
202+
'-c',
203+
(
204+
'import pathlib; '
205+
'from b2sdk import v0, v1, v2, v3; '
206+
'repo_root = pathlib.Path.cwd().parent.resolve(); '
207+
'source_root = repo_root / "b2sdk"; '
208+
"module_files = {'v0': pathlib.Path(v0.__file__).resolve(), "
209+
"'v1': pathlib.Path(v1.__file__).resolve(), "
210+
"'v2': pathlib.Path(v2.__file__).resolve(), "
211+
"'v3': pathlib.Path(v3.__file__).resolve()}; "
212+
'print(module_files); '
213+
"assert all(not path.is_relative_to(source_root) for path in module_files.values()), "
214+
"f'Imported modules from checkout: {module_files!r}'; "
215+
"assert all('site-packages' in path.parts for path in module_files.values()), "
216+
"f'Imported modules from an unexpected location: {module_files!r}'"
217+
),
218+
)
219+
193220

194221
@nox.session(python=PYTHON_DEFAULT_VERSION)
195222
def doc(session):

0 commit comments

Comments
 (0)