Skip to content

Commit b6bd27b

Browse files
authored
tests(pypi): add test for excluding bazel files from wheels (bazel-contrib#3979)
This adds a test to verify that bazel files are excluded from the files matched from an extracted wheel. Followup to bazel-contrib#3960 Work towards bazel-contrib#2948
1 parent fd25d1f commit b6bd27b

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

python/private/pypi/whl_library_targets.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ def whl_library_srcs(
229229
filegroups = {
230230
EXTRACTED_WHEEL_FILES: dict(
231231
include = ["**"],
232-
exclude = (
233-
_BAZEL_REPO_FILE_GLOBS +
232+
# The Bazel repo files are always excluded; only the sdist
233+
# filename is conditional on `sdist_filename`.
234+
exclude = _BAZEL_REPO_FILE_GLOBS + (
234235
[sdist_filename] if sdist_filename else []
235236
),
236237
),

tests/pypi/whl_library_targets/whl_library_targets_tests.bzl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,60 @@ def _test_sdist_excludes_record(env):
277277

278278
_tests.append(_test_sdist_excludes_record)
279279

280+
def _test_exclude_bazel_files(env):
281+
# Regression test: the `extracted_whl_files` glob must always exclude the
282+
# Bazel repo files, even when the wheel is not built from an sdist.
283+
for sdist_filename in [None, "foo.tar.gz"]:
284+
m_glob = mocks.glob()
285+
m_glob.results.append([]) # bin
286+
m_glob.results.append([]) # rewrite-bin
287+
m_glob.results.append([]) # extracted_whl_files
288+
m_glob.results.append([]) # dist_info
289+
m_glob.results.append([]) # data
290+
291+
whl_library_srcs(
292+
name = "foo.whl",
293+
sdist_filename = sdist_filename,
294+
native = struct(
295+
filegroup = lambda **_: None,
296+
glob = m_glob.glob,
297+
),
298+
rules = struct(
299+
venv_rewrite_shebang = lambda **kwargs: None,
300+
),
301+
)
302+
303+
expected_exclude = [
304+
"BUILD",
305+
"BUILD.bazel",
306+
"REPO.bazel",
307+
"WORKSPACE",
308+
"WORKSPACE.bzlmod",
309+
"WORKSPACE.bazel",
310+
]
311+
if sdist_filename:
312+
expected_exclude.append(sdist_filename)
313+
314+
env.expect.that_collection(m_glob.calls).contains_exactly([
315+
mocks.glob_call(["bin/*"], allow_empty = True),
316+
mocks.glob_call(["rewrite-bin/*"], allow_empty = True),
317+
mocks.glob_call(
318+
include = ["**"],
319+
exclude = expected_exclude,
320+
allow_empty = True,
321+
),
322+
mocks.glob_call(
323+
include = ["site-packages/*.dist-info/**"],
324+
allow_empty = True,
325+
),
326+
mocks.glob_call(
327+
include = ["data/**", "bin/**", "include/**"],
328+
allow_empty = True,
329+
),
330+
])
331+
332+
_tests.append(_test_exclude_bazel_files)
333+
280334
def whl_library_targets_test_suite(name):
281335
"""create the test suite.
282336

0 commit comments

Comments
 (0)