Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto marian/whl_fix
  • Loading branch information
mdvorsky committed Aug 1, 2020
2 parents f50d95d + 8c9ed92 commit ba26361
Show file tree
Hide file tree
Showing 27 changed files with 249 additions and 212 deletions.
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# For bazel-in-bazel testing
# Trick bazel into treating BUILD files under examples/* and e2e/* as being regular files
# This lets us glob() up all the files inside the examples to make them inputs to tests
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, run this command:
# sed -i.bak "/^[^#].*--deleted_packages/s#=.*#=$(find examples/*/* \( -name BUILD -or -name BUILD.bazel \) | xargs -n 1 dirname | paste -sd, -)#" .bazelrc && rm .bazelrc.bak
build --deleted_packages=examples/pip/boto,examples/pip/extras,examples/pip/helloworld
query --deleted_packages=examples/pip/boto,examples/pip/extras,examples/pip/helloworld
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Please check if your PR fulfills the following requirements:

- [ ] Does not include precompiled binaries, eg. `.par` files. See [CONTRIBUTING.md](/CONTRIBUTING.md) for info
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)

Expand Down
35 changes: 6 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,7 @@ contribute](CONTRIBUTING.md) page for information on our development workflow.
## Getting started

To import rules_python in your project, you first need to add it to your
`WORKSPACE` file. If you are using the [Bazel
Federation](https://github.com/bazelbuild/bazel-federation), you just need to
[import the Federation](https://github.com/bazelbuild/bazel-federation#example-workspace)
and call the rules_python setup methods:

```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_federation",
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")

rules_python_deps()
load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")
rules_python_setup(use_pip=True)
```

Note the `use_pip` argument: rules_python may be imported either with or
without support for the packaging rules.

If you are not using the Federation, you can simply import rules_python
directly and call its initialization methods as follows:
`WORKSPACE` file:

```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand All @@ -85,9 +60,11 @@ http_archive(
strip_prefix = "rules_python-0.0.2",
sha256 = "b5668cde8bb6e3515057ef465a35ad712214962f0b3a314e551204266c7be90c",
)
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
# Only needed if using the packaging rules.
```

If you want to use the pip packaging rules, also add:

```python
load("@rules_python//python:pip.bzl", "pip_repositories")
pip_repositories()
```
Expand Down
64 changes: 2 additions & 62 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,9 @@

workspace(name = "rules_python")

###################################
# Test data for WHL tool testing. #
###################################
load("//python:pip.bzl", "pip_repositories")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_file(
name = "apispec_2_0_1_whl",
downloaded_file_path = "apispec-2.0.1-py2.py3-none-any.whl",
sha256 = "427293594699c77753b8fdc6d78d8dfe267c394df5186c236d57f6ef1af95027",
# From https://pypi.python.org/pypi/apispec
urls = [("https://pypi.python.org/packages/ea/c3/" +
"1f60ae577a1f92a60bd254d3d8b7747f8ba02e5d5638bde79ea17ae45208/" +
"apispec-2.0.1-py2.py3-none-any.whl")],
)

http_file(
name = "gunicorn_19_9_0_whl",
downloaded_file_path = "gunicorn-19.9.0-py2.py3-none-any.whl",
sha256 = "aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471",
# From https://pypi.python.org/pypi/gunicorn
urls = [("https://pypi.python.org/packages/8c/da/" +
"b8dd8deb741bff556db53902d4706774c8e1e67265f69528c14c003644e6/" +
"gunicorn-19.9.0-py2.py3-none-any.whl")],
)

http_file(
name = "pyOpenSSL_19_0_0_whl",
downloaded_file_path = "pyOpenSSL-19.0.0-py2.py3-none-any.whl",
sha256 = "c727930ad54b10fc157015014b666f2d8b41f70c0d03e83ab67624fd3dd5d1e6",
# From https://pypi.python.org/pypi/pyOpenSSL
urls = [("https://pypi.python.org/packages/01/c8/" +
"ceb170d81bd3941cbeb9940fc6cc2ef2ca4288d0ca8929ea4db5905d904d/" +
"pyOpenSSL-19.0.0-py2.py3-none-any.whl")],
)

http_file(
name = "google_cloud_spanner_1_9_0_whl",
downloaded_file_path = "google_cloud_spanner-1.9.0-py2.py3-none-any.whl",
sha256 = "963d0afe48bef9f8c7fef3982aa69ea46c12703c1379f66f52f5d7ced47a0b42",
# From https://pypi.python.org/pypi/google-cloud-spanner
urls = [("https://pypi.python.org/packages/b1/df/" +
"96686bc6abafacb579334f8c61be2f025f1be161d266893d17b47afd7685/" +
"google_cloud_spanner-1.9.0-py2.py3-none-any.whl")],
)

# Load our production dependencies using the federation, except that instead of
# calling rules_python() (which would define the @rules_python repo), we just
# call rules_python_deps().

http_archive(
name = "bazel_federation",
sha256 = "506dfbfd74ade486ac077113f48d16835fdf6e343e1d4741552b450cfc2efb53",
url = "https://github.com/bazelbuild/bazel-federation/releases/download/0.0.1/bazel_federation-0.0.1.tar.gz",
)

load("@bazel_federation//:repositories.bzl", "rules_python_deps")

rules_python_deps()

load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")

rules_python_setup(use_pip = True)
pip_repositories()

# Everything below this line is used only for developing rules_python. Users
# should not copy it to their WORKSPACE.
Expand Down
5 changes: 5 additions & 0 deletions examples/pip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# pip example

This shows how you can point Bazel at your requirements.txt file to get dependencies automatically installed.

It also shows how a monorepo might have multiple python packages which each have a separate requirements.txt file.
41 changes: 41 additions & 0 deletions examples/pip/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
workspace(name = "pip_example")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.2/rules_python-0.0.2.tar.gz",
strip_prefix = "rules_python-0.0.2",
sha256 = "b5668cde8bb6e3515057ef465a35ad712214962f0b3a314e551204266c7be90c",
)

load("@rules_python//python:pip.bzl", "pip_import", "pip_repositories")

pip_repositories()

pip_import(
name = "helloworld_deps",
requirements = "//helloworld:requirements.txt",
)

load("@helloworld_deps//:requirements.bzl", _helloworld_install = "pip_install")

_helloworld_install()

pip_import(
name = "boto_deps",
requirements = "//boto:requirements.txt",
)

load("@boto_deps//:requirements.bzl", _boto_install = "pip_install")

_boto_install()

pip_import(
name = "extras_deps",
requirements = "//extras:requirements.txt",
)

load("@extras_deps//:requirements.bzl", _extras_install = "pip_install")

_extras_install()
4 changes: 2 additions & 2 deletions examples/boto/BUILD → examples/pip/boto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@examples_boto//:requirements.bzl", "requirement")
load("//python:defs.bzl", "py_test")
load("@boto_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_test")

package(default_visibility = ["//visibility:public"])

Expand Down
5 changes: 5 additions & 0 deletions examples/boto/boto_test.py → examples/pip/boto/boto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
# limitations under the License.

import boto3
import pip
import unittest


class BotoTest(unittest.TestCase):

def test_version(self):
# Just the minimal assertion that the boto3 import worked
self.assertEqual(boto3.__version__, '1.4.7')
# Regression test that the pip version is the one requested
# see https://github.com/bazelbuild/rules_python/pull/1#discussion_r138349892
self.assertEqual(pip.__version__, '9.0.3')


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ boto3==1.4.7
# Release 0.15 appears to have a broken wheel.
# See https://github.com/bazelbuild/rules_python/issues/205.
docutils!=0.15.post1
pip==9.0.3
4 changes: 2 additions & 2 deletions examples/extras/BUILD → examples/pip/extras/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@examples_extras//:requirements.bzl", "requirement")
load("//python:defs.bzl", "py_test")
load("@extras_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_test")

package(default_visibility = ["//visibility:public"])

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/helloworld/BUILD → examples/pip/helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@examples_helloworld//:requirements.bzl", "requirement")
load("//python:defs.bzl", "py_library", "py_test")
load("@helloworld_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_library", "py_test")

package(default_visibility = ["//visibility:public"])

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions examples/version/BUILD

This file was deleted.

1 change: 0 additions & 1 deletion examples/version/requirements.txt

This file was deleted.

26 changes: 0 additions & 26 deletions examples/version/version_test.py

This file was deleted.

2 changes: 1 addition & 1 deletion experimental/examples/wheel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ py_library(
"//experimental/examples/wheel/lib:module_with_data",
# Example dependency which is not packaged in the wheel
# due to "packages" filter on py_package rule.
"//examples/helloworld",
"//tests/load_from_macro:foo",
],
)

Expand Down
Loading

0 comments on commit ba26361

Please sign in to comment.