8000 Add a nice error message to help with the workspace name migration · bazel-contrib/rules_python@fb52bf4 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb52bf4

Browse files
committed
Add a nice error message to help with the workspace name migration
This hooks into pip_repositories(), which users are *supposed* to be calling in their WORKSPACE files, to emit a nice fail() message alerting them that they need to update their repo definition. Without this change (and even with it, for users who do not call `pip_repositories()`), users will instead see a confusing cyclic dependency error.
1 parent dffaa17 commit fb52bf4

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

python/pip.bzl

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,35 @@ Args:
9797
"""
9898

9999
def pip_repositories():
100-
"""Pull in dependencies needed for pulling in pip dependencies.
100+
"""Pull in dependencies needed to use the pip rules.
101101
102-
A placeholder method that will eventually pull in any dependencies
103-
needed to install pip dependencies.
102+
At the moment this is a placeholder, in that it does not actually pull in
103+
any dependencies. However, it does do some validation checking.
104104
"""
105-
pass
105+
# As a side effect of migrating our canonical workspace name from
106+
# "@io_bazel_rules_python" to "@rules_python" (#203), users who still
107+
# imported us by the old name would get a confusing error about a
108+
# repository dependency cycle in their workspace. (The cycle is likely
109+
# related to the fact that our repo name is hardcoded into the template
110+
# in piptool.py.)
111+
#
112+
# To produce a more informative error message in this situation, we
113+
# fail-fast here if we detect that we're not being imported by the new
114+
# name. (I believe we have always had the requirement that we're imported
115+
# by the canonical name, because of the aforementioned hardcoding.)
116+
#
117+
# Users who, against best practice, do not call pip_repositories() in their
118+
# workspace will not benefit from this check.
119+
if "rules_python" not in native.existing_rules():
120+
message = "=" * 79 + """\n\
121+
It appears that you are trying to import rules_python without using its
122+
canonical name, "@rules_python". This does not work. Please change your
123+
repository definition to import this repo with `name = "rules_python"`.
124+
"""
125+
if "io_bazel_rules_python" in native.existing_rules():
126+
message += """\n\
127+
Note that the previous name of "@io_bazel_rules_python" is no longer used.
128+
See https://github.com/bazelbuild/rules_python/issues/203 for context.
129+
"""
130+
message += "=" * 79
131+
fail(message)

0 commit comments

Comments
 (0)
0