Skip to content

Commit d1596a3

Browse files
authored
Rename canonical workspace name to "@rules_python" (bazel-contrib#212)
* Change official workspace name to @rules_python This includes regenerating the par files to use the new name. Neat trick: Since the par file regeneration depends on the previous par files, I had to bootstrap this change by temporarily editing the WORKSPACE to include: local_repository( name = "io_bazel_rules_python", path = ".", ) * 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 d852e8a commit d1596a3

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Status: This is **ALPHA** software.
44

55
[![Build status](https://badge.buildkite.com/0bcfe58b6f5741aacb09b12485969ba7a1205955a45b53e854.svg)](https://buildkite.com/bazel/python-rules-python-postsubmit)
66

7+
## Recent updates
8+
9+
* 2019-07-26: The canonical name of this repo has been changed from `@io_bazel_rules_python` to just `@rules_python`, in accordance with [convention](https://docs.bazel.build/versions/master/skylark/deploying.html#workspace). Please update your WORKSPACE file and labels that reference this repo accordingly.
10+
711
## Rules
812

913
* [pip_import](docs/python/pip.md#pip_import)
@@ -26,14 +30,14 @@ Add the following to your `WORKSPACE` file to add the external repositories:
2630
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2731

2832
git_repository(
29-
name = "io_bazel_rules_python",
33+
name = "rules_python",
3034
remote = "https://github.com/bazelbuild/rules_python.git",
3135
# NOT VALID! Replace this with a Git commit SHA.
3236
commit = "{HEAD}",
3337
)
3438

3539
# Only needed for PIP support:
36-
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
40+
load("@rules_python//python:pip.bzl", "pip_repositories")
3741

3842
pip_repositories()
3943
```
@@ -42,7 +46,7 @@ Then in your `BUILD` files load the python rules with:
4246

4347
``` python
4448
load(
45-
"@io_bazel_rules_python//python:python.bzl",
49+
"@rules_python//python:python.bzl",
4650
"py_binary", "py_library", "py_test",
4751
)
4852

@@ -60,7 +64,7 @@ are imported into the Bazel dependency graph via a two-phased process in
6064
`WORKSPACE`:
6165

6266
```python
63-
load("@io_bazel_rules_python//python:pip.bzl", "pip_import")
67+
load("@rules_python//python:pip.bzl", "pip_import")
6468

6569
# This rule translates the specified requirements.txt into
6670
# @my_deps//:requirements.bzl, which itself exposes a pip_install method.

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
workspace(name = "io_bazel_rules_python")
15+
workspace(name = "rules_python")
1616

1717
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
1818
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

experimental/examples/wheel/wheel_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class WheelTest(unittest.TestCase):
2121
def test_py_library_wheel(self):
2222
filename = os.path.join(os.environ['TEST_SRCDIR'],
23-
'io_bazel_rules_python', 'experimental',
23+
'rules_python', 'experimental',
2424
'examples', 'wheel',
2525
'example_minimal_library-0.0.1-py3-none-any.whl')
2626
with zipfile.ZipFile(filename) as zf:
@@ -34,7 +34,7 @@ def test_py_library_wheel(self):
3434

3535
def test_py_package_wheel(self):
3636
filename = os.path.join(os.environ['TEST_SRCDIR'],
37-
'io_bazel_rules_python', 'experimental',
37+
'rules_python', 'experimental',
3838
'examples', 'wheel',
3939
'example_minimal_package-0.0.1-py3-none-any.whl')
4040
with zipfile.ZipFile(filename) as zf:
@@ -50,7 +50,7 @@ def test_py_package_wheel(self):
5050

5151
def test_customized_wheel(self):
5252
filename = os.path.join(os.environ['TEST_SRCDIR'],
53-
'io_bazel_rules_python', 'experimental',
53+
'rules_python', 'experimental',
5454
'examples', 'wheel',
5555
'example_customized-0.0.1-py3-none-any.whl')
5656
with zipfile.ZipFile(filename) as zf:
@@ -104,7 +104,7 @@ def test_customized_wheel(self):
104104

105105
def test_custom_package_root_wheel(self):
106106
filename = os.path.join(os.environ['TEST_SRCDIR'],
107-
'io_bazel_rules_python', 'experimental',
107+
'rules_python', 'experimental',
108108
'examples', 'wheel',
109109
'example_custom_package_root-0.0.1-py3-none-any.whl')
110110

@@ -121,7 +121,7 @@ def test_custom_package_root_wheel(self):
121121

122122
def test_custom_package_root_multi_prefix_wheel(self):
123123
filename = os.path.join(os.environ['TEST_SRCDIR'],
124-
'io_bazel_rules_python', 'experimental',
124+
'rules_python', 'experimental',
125125
'examples', 'wheel',
126126
'example_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl')
127127

@@ -138,7 +138,7 @@ def test_custom_package_root_multi_prefix_wheel(self):
138138

139139
def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
140140
filename = os.path.join(os.environ['TEST_SRCDIR'],
141-
'io_bazel_rules_python', 'experimental',
141+
'rules_python', 'experimental',
142142
'examples', 'wheel',
143143
'example_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl')
144144

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+
WORKSPACE file to import this repo with `name = "rules_python"` instead.
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)

rules_python/piptool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def whl_library(wheel):
203203
#
204204
# Generated from {input}
205205
206-
load("@io_bazel_rules_python//python:whl.bzl", "whl_library")
206+
load("@rules_python//python:whl.bzl", "whl_library")
207207
208208
def pip_install():
209209
{whl_libraries}

tools/piptool.par

-126 Bytes
Binary file not shown.

tools/whltool.par

-90 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)