Use rules_pkg to create distributions (#234)

This adds a packaging target to create a Bazel Federation-compliant distribution.
diff --git a/BUILD b/BUILD
index 5ba9cc5..1bf1f64 100644
--- a/BUILD
+++ b/BUILD
@@ -15,4 +15,17 @@
 
 licenses(["notice"])  # Apache 2.0
 
-exports_files(["LICENSE"])
+exports_files(["LICENSE", "version.bzl"])
+
+filegroup(
+    name = "distribution",
+    srcs = [
+        "BUILD",
+        "LICENSE",
+        "internal_deps.bzl",
+        "internal_setup.bzl",
+        "//python:distribution",
+        "//tools:distribution",
+    ],
+    visibility = ["//distro:__pkg__"],
+)
diff --git a/WORKSPACE b/WORKSPACE
index b44f210..6cd3456 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -15,12 +15,11 @@
 workspace(name = "rules_python")
 
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
 http_archive(
     name = "bazel_federation",
-    url = "https://github.com/bazelbuild/bazel-federation/archive/4da9b5f83ffae17613fa025a0701fa9db9350d41.zip",
-    sha256 = "5b1cf980e327a8f30fc81c00c04007c543e17c09ed612fb645753936de790ed7",
-    strip_prefix = "bazel-federation-4da9b5f83ffae17613fa025a0701fa9db9350d41",
-    type = "zip",
+    url = "https://github.com/bazelbuild/bazel-federation/releases/download/0.0.1/bazel_federation-0.0.1.tar.gz",
+    sha256 = "506dfbfd74ade486ac077113f48d16835fdf6e343e1d4741552b450cfc2efb53",
 )
 
 load("@bazel_federation//:repositories.bzl", "rules_python_deps")
@@ -29,6 +28,9 @@
 load("@bazel_federation//setup:rules_python.bzl",  "rules_python_setup")
 rules_python_setup(use_pip=True)
 
+# Everything below this line is used only for developing rules_python. Users
+# should not copy it to their WORKSPACE.
+
 load("//:internal_deps.bzl", "rules_python_internal_deps")
 rules_python_internal_deps()
 
diff --git a/distro/BUILD b/distro/BUILD
new file mode 100644
index 0000000..39041f9
--- /dev/null
+++ b/distro/BUILD
@@ -0,0 +1,32 @@
+package(
+    default_visibility = ["//visibility:private"],
+)
+
+load("@rules_python//:version.bzl", "version")
+load("@rules_pkg//:pkg.bzl", "pkg_tar")
+load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
+
+# Build the artifact to put on the github release page.
+pkg_tar(
+    name = "rules_python-%s" % version,
+    srcs = [
+        "//:distribution",
+    ],
+    extension = "tar.gz",
+    # It is all source code, so make it read-only.
+    mode = "0444",
+    # Make it owned by root so it does not have the uid of the CI robot.
+    owner = "0.0",
+    package_dir = ".",
+    strip_prefix = ".",
+)
+
+print_rel_notes(
+    name = "relnotes",
+    outs = ["relnotes.txt"],
+    deps_method = "py_repositories",
+    repo = "rules_python",
+    setup_file = "python:repositories.bzl",
+    toolchains_method = "rules_python_toolchains",
+    version = version,
+)
diff --git a/internal_deps.bzl b/internal_deps.bzl
index 26ca85d..1873e66 100644
--- a/internal_deps.bzl
+++ b/internal_deps.bzl
@@ -1,4 +1,4 @@
-load("@bazel_federation//:repositories.bzl", "bazel_stardoc")
+load("@bazel_federation//:repositories.bzl", "bazel_stardoc", "rules_pkg")
 load("@bazel_federation//:third_party_repositories.bzl", "futures_2_whl", "futures_3_whl", "google_cloud_language_whl", "grpc_whl", "mock_whl", "subpar")
 load("@rules_python//python:pip.bzl", "pip_import")
 
@@ -18,6 +18,9 @@
     piptool()
     examples()
 
+    # For packaging and distribution
+    rules_pkg()
+
 
 def piptool():
     pip_import(
diff --git a/python/BUILD b/python/BUILD
index 42679ee..cb092f8 100644
--- a/python/BUILD
+++ b/python/BUILD
@@ -28,6 +28,15 @@
 
 licenses(["notice"])  # Apache 2.0
 
+filegroup(
+    name = "distribution",
+    srcs = glob(["**"]) + [
+        "//python/constraints:distribution",
+        "//python/runfiles:distribution",
+    ],
+    visibility = ["//:__pkg__"],
+)
+
 # ========= Core rules =========
 
 exports_files([
diff --git a/python/constraints/BUILD b/python/constraints/BUILD
index b93c215..969c867 100644
--- a/python/constraints/BUILD
+++ b/python/constraints/BUILD
@@ -16,6 +16,12 @@
 
 licenses(["notice"])
 
+filegroup(
+    name = "distribution",
+    srcs = glob(["**"]),
+    visibility = ["//python:__pkg__"],
+)
+
 # A constraint_setting to use for constraints related to the location of the
 # system Python 2 interpreter on a platform.
 alias(
diff --git a/python/runfiles/BUILD b/python/runfiles/BUILD
index 7db3493..da34778 100644
--- a/python/runfiles/BUILD
+++ b/python/runfiles/BUILD
@@ -32,6 +32,12 @@
 
 load("//python:defs.bzl", "py_library")
 
+filegroup(
+    name = "distribution",
+    srcs = glob(["**"]),
+    visibility = ["//python:__pkg__"],
+)
+
 py_library(
     name = "runfiles",
     srcs = ["runfiles.py"],
diff --git a/tools/BUILD b/tools/BUILD
index 780484e..405a9bd 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -17,3 +17,13 @@
 
 # These files are generated and updated by ./update_tools.sh
 exports_files(["piptool.par", "whltool.par"])
+
+filegroup(
+    name = "distribution",
+    srcs = [
+        "BUILD",
+    ] + glob([
+        "*.par",
+    ]),
+    visibility = ["//:__pkg__"],
+)
diff --git a/version.bzl b/version.bzl
new file mode 100644
index 0000000..c1ccdbd
--- /dev/null
+++ b/version.bzl
@@ -0,0 +1,16 @@
+# Copyright 2019 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""The version of rules_python."""
+
+version = "0.0.1"