Skip to content

Commit c81db3c

Browse files
committed
refactor(pypi): improve missing package error messages
Improve the error messages thrown when a PyPI package is not available to include action-oriented tips. Update the integration test expected assertions accordingly.
1 parent a4bbe93 commit c81db3c

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

python/private/pypi/missing_package.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ load("//python/private:reexports.bzl", "BuiltinPyInfo")
66
def _missing_package_error_impl(ctx):
77
out = ctx.actions.declare_file(ctx.label.name + ".error")
88

9+
if ctx.attr.hub_name:
10+
hub_clause = ' when building under PyPI hub "{hub}". Try adding it to the requirements of this hub (e.g. requirements_lock or requirements_by_platform in pip.parse)'.format(
11+
hub = ctx.attr.hub_name,
12+
)
13+
else:
14+
hub_clause = ' because no default PyPI hub was configured. Try designating a default hub via pip.default(default_hub = "...") or select a hub using --@rules_python//python/config_settings:venv'
15+
916
# Register an action that fails when Bazel attempts to stage/build this file
1017
ctx.actions.run_shell(
1118
outputs = [out],
1219
command = "echo 'ERROR: PyPI package \"{pkg}\" is not available{hub_clause}.' >&2 && exit 1".format(
1320
pkg = ctx.attr.package_name,
14-
hub_clause = (' when building under PyPI hub "%s"' % ctx.attr.hub_name) if ctx.attr.hub_name else " because no PyPI hub or default hub is requested",
21+
hub_clause = hub_clause,
1522
),
1623
)
1724

tests/integration/unified_pypi_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_disjoint_package_cquery_succeeds_but_build_fails(self):
3030
)
3131
self.assert_result_matches(
3232
result,
33-
'ERROR: PyPI package "six" is not available when building under PyPI hub "pypi_a".',
33+
'ERROR: PyPI package "six" is not available when building under PyPI hub "pypi_a"\\. Try adding it to the requirements of this hub',
3434
)
3535

3636
def test_sibling_extra_alias_cquery_succeeds_but_build_fails(self):
@@ -43,7 +43,7 @@ def test_sibling_extra_alias_cquery_succeeds_but_build_fails(self):
4343
)
4444
self.assert_result_matches(
4545
result,
46-
'ERROR: PyPI package "colorama:my_colorama" is not available when building under PyPI hub "pypi_b".',
46+
'ERROR: PyPI package "colorama:my_colorama" is not available when building under PyPI hub "pypi_b"\\. Try adding it to the requirements of this hub',
4747
)
4848

4949
@contextlib.contextmanager
@@ -83,7 +83,7 @@ def test_unimplemented_declared_dep_fails_build(self):
8383
self.assertNotEqual(result.exit_code, 0)
8484
self.assert_result_matches(
8585
result,
86-
'ERROR: PyPI package "declared_only_pkg" is not available when building under PyPI hub "pypi_b".',
86+
'ERROR: PyPI package "declared_only_pkg" is not available when building under PyPI hub "pypi_b"\\. Try adding it to the requirements of this hub',
8787
)
8888

8989
def test_unimplemented_declared_dep_alias_fails_build(self):
@@ -92,7 +92,7 @@ def test_unimplemented_declared_dep_alias_fails_build(self):
9292
self.assertNotEqual(result.exit_code, 0)
9393
self.assert_result_matches(
9494
result,
95-
'ERROR: PyPI package "declared_only_pkg:declared-only-alias" is not available when building under PyPI hub "pypi_b".',
95+
'ERROR: PyPI package "declared_only_pkg:declared-only-alias" is not available when building under PyPI hub "pypi_b"\\. Try adding it to the requirements of this hub',
9696
)
9797

9898

0 commit comments

Comments
 (0)