Rename canonical workspace name to "@rules_python" (#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.
diff --git a/README.md b/README.md
index 9c44f40..f222f39 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,10 @@
 
 [![Build status](https://badge.buildkite.com/0bcfe58b6f5741aacb09b12485969ba7a1205955a45b53e854.svg)](https://buildkite.com/bazel/python-rules-python-postsubmit)
 
+## Recent updates
+
+* 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.
+
 ## Rules
 
 * [pip_import](docs/python/pip.md#pip_import)
@@ -26,14 +30,14 @@
 load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
 
 git_repository(
-    name = "io_bazel_rules_python",
+    name = "rules_python",
     remote = "https://github.com/bazelbuild/rules_python.git",
     # NOT VALID!  Replace this with a Git commit SHA.
     commit = "{HEAD}",
 )
 
 # Only needed for PIP support:
-load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
+load("@rules_python//python:pip.bzl", "pip_repositories")
 
 pip_repositories()
 ```
@@ -42,7 +46,7 @@
 
 ``` python
 load(
-  "@io_bazel_rules_python//python:python.bzl",
+  "@rules_python//python:python.bzl",
   "py_binary", "py_library", "py_test",
 )
 
@@ -60,7 +64,7 @@
 `WORKSPACE`:
 
 ```python
-load("@io_bazel_rules_python//python:pip.bzl", "pip_import")
+load("@rules_python//python:pip.bzl", "pip_import")
 
 # This rule translates the specified requirements.txt into
 # @my_deps//:requirements.bzl, which itself exposes a pip_install method.
diff --git a/WORKSPACE b/WORKSPACE
index 296055f..abf1a47 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-workspace(name = "io_bazel_rules_python")
+workspace(name = "rules_python")
 
 load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
diff --git a/experimental/examples/wheel/wheel_test.py b/experimental/examples/wheel/wheel_test.py
index d7bb8b6..ea535de 100644
--- a/experimental/examples/wheel/wheel_test.py
+++ b/experimental/examples/wheel/wheel_test.py
@@ -20,7 +20,7 @@
 class WheelTest(unittest.TestCase):
     def test_py_library_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_minimal_library-0.0.1-py3-none-any.whl')
         with zipfile.ZipFile(filename) as zf:
@@ -34,7 +34,7 @@
 
     def test_py_package_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_minimal_package-0.0.1-py3-none-any.whl')
         with zipfile.ZipFile(filename) as zf:
@@ -50,7 +50,7 @@
 
     def test_customized_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_customized-0.0.1-py3-none-any.whl')
         with zipfile.ZipFile(filename) as zf:
@@ -104,7 +104,7 @@
 
     def test_custom_package_root_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_custom_package_root-0.0.1-py3-none-any.whl')
 
@@ -121,7 +121,7 @@
 
     def test_custom_package_root_multi_prefix_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl')
 
@@ -138,7 +138,7 @@
 
     def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
         filename = os.path.join(os.environ['TEST_SRCDIR'],
-                                'io_bazel_rules_python', 'experimental',
+                                'rules_python', 'experimental',
                                 'examples', 'wheel',
                                 'example_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl')
 
diff --git a/python/pip.bzl b/python/pip.bzl
index 9d27794..2449ee7 100644
--- a/python/pip.bzl
+++ b/python/pip.bzl
@@ -97,9 +97,35 @@
 """
 
 def pip_repositories():
-    """Pull in dependencies needed for pulling in pip dependencies.
+    """Pull in dependencies needed to use the pip rules.
 
-    A placeholder method that will eventually pull in any dependencies
-    needed to install pip dependencies.
+    At the moment this is a placeholder, in that it does not actually pull in
+    any dependencies. However, it does do some validation checking.
     """
-    pass
+    # As a side effect of migrating our canonical workspace name from
+    # "@io_bazel_rules_python" to "@rules_python" (#203), users who still
+    # imported us by the old name would get a confusing error about a
+    # repository dependency cycle in their workspace. (The cycle is likely
+    # related to the fact that our repo name is hardcoded into the template
+    # in piptool.py.)
+    #
+    # To produce a more informative error message in this situation, we
+    # fail-fast here if we detect that we're not being imported by the new
+    # name. (I believe we have always had the requirement that we're imported
+    # by the canonical name, because of the aforementioned hardcoding.)
+    #
+    # Users who, against best practice, do not call pip_repositories() in their
+    # workspace will not benefit from this check.
+    if "rules_python" not in native.existing_rules():
+        message = "=" * 79 + """\n\
+It appears that you are trying to import rules_python without using its
+canonical name, "@rules_python". This does not work. Please change your
+WORKSPACE file to import this repo with `name = "rules_python"` instead.
+"""
+        if "io_bazel_rules_python" in native.existing_rules():
+            message += """\n\
+Note that the previous name of "@io_bazel_rules_python" is no longer used.
+See https://github.com/bazelbuild/rules_python/issues/203 for context.
+"""
+        message += "=" * 79
+        fail(message)
diff --git a/rules_python/piptool.py b/rules_python/piptool.py
index f5d504a..5bc4dfd 100644
--- a/rules_python/piptool.py
+++ b/rules_python/piptool.py
@@ -203,7 +203,7 @@
 #
 # Generated from {input}
 
-load("@io_bazel_rules_python//python:whl.bzl", "whl_library")
+load("@rules_python//python:whl.bzl", "whl_library")
 
 def pip_install():
   {whl_libraries}
diff --git a/tools/piptool.par b/tools/piptool.par
index 53df7d8..5503d18 100755
--- a/tools/piptool.par
+++ b/tools/piptool.par
Binary files differ
diff --git a/tools/whltool.par b/tools/whltool.par
index 25f85e7..8db7f14 100755
--- a/tools/whltool.par
+++ b/tools/whltool.par
Binary files differ