Commit Graph

21 Commits

Author SHA1 Message Date
daicoden 2fc3131829 Add copyrights 2020-07-24 15:54:16 -10:00
Matt Wilson 67f3ebd90e PR Feedback. 2020-04-29 11:13:21 -10:00
Matt Wilson 594e1f6a64 py_proto_library uses workspace and pkg paths
All python imports currently are added to the runfiles under __main__
which is only the default when no workspace name is provided. This
change supports both empty workspace names, and specified workspace
names.

This also supports python libs not anchored at root
2020-04-27 09:04:37 -10:00
Yannic Bonenberger 06ecc87290 [bazel] Add fixes for --incompatible_load_proto_rules_from_bzl 2020-02-05 19:58:30 +01:00
Lidi Zheng c34bef4ca4 Format all Bazel files with buildifier 2019-11-05 14:03:52 -08:00
vam-google 91c0d093bd Fix unnecessary dependency and add new line 2019-10-29 17:03:50 -07:00
vam-google 5d9eeb34fc Address PR feedback. Also add a dummy plugin. 2019-10-29 16:23:57 -07:00
Richard Belleville 695f6daf14
Merge pull request #20586 from djwenren/fix-deps
Move extra dependencies out of WORKSPACE to its own macro.
2019-10-24 12:13:40 -07:00
vam-google dbe62a6e6c Switch to `py2and3_test` rule from py_test 2019-10-16 13:26:59 -07:00
vam-google 564dc771dc Return PyInfo provider with imports from _gen rules and pass that as deps in py_library. This allows hiding _virtual_imports include path from the surface. 2019-10-15 17:47:02 -07:00
vam-google 9e6e57bfba Merge remote-tracking branch 'upstream/master' 2019-10-15 17:34:58 -07:00
Danjie Wenren 93e8830070 Address comments.
- Fix sanit test check_bazel_workspace.py.
- Use the new `grpc_extra_deps` in the Bazel workspace test.
2019-10-14 22:51:10 -07:00
Rafi Kamal 7c85e29076 Add protobuf_deps to python_test_repo WORKSPACE 2019-09-13 14:03:05 -07:00
vam 461c053c37 [bazel][python] Support _virtual_imports input for py_proto_library and py_grpc_library rules
`proto_library` targets are used as deps for `py_proto_library` and `py_grpc_library` rules. The `proto_library` targets can be configured using `import_prefix` and/or `strip_import_prefix` (which essentially move original location of the proto file and, as result, affects import path within proto files themselves and in the generated language-specific stubs).

The biggest question to answer when generating stubs from moved protos is where to put result (this decision affects all downstream rules as well, because the location of file affects its import path).

This PR tries to follow same logic as the native `cc_proto_library` (created and maintained by Bazel team). For example, if we have `firestore.proto` file, which is located under `google/firestore/v1beta1` Bazel package and want to move it under `google/cloud/firestore_v1beta1/proto` (this is axactly what happens in googleapis repository), it can be configured the following way:

```bzl
proto_library(
    name = "firestore_moved_proto",
    srcs = ["firestore.proto"],
    import_prefix = "google/cloud/firestore_v1beta1/proto",
    strip_import_prefix = "google/firestore/v1beta1",
)
```

The rule above will first generate virtual `.proto` files (under new location) and only after that generate a binary descriptor from them.
Specifically it will generate the following "virtual" file under `_virtual_imports` subdirectory of same package:

```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/common.proto
```

When supplied to `cc_proto_library`, like the following:

```bzl
cc_proto_library(
    name = "firestore_moved_cc_proto",
    deps = ["firestore_moved_proto"],
)
```

The rule will generate .cc and .h files like the following:
```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore.pb.h
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore.pb.cc
```

Notice, that each generated `.cc` and `.h` file is prefixed with `_virtual_imports/<name_of_proto_library_target>`.

The python rules try to do same thing, so for the following py_proto_library rule:

```bzl
py_proto_library(
    name = "firestore_moved_py_proto",
    deps = [":firestore_moved_proto"],
)
```

It wil generate the following file:
```
bazel-bin/google/firestore/v1beta1/_virtual_imports/firestore_moved_proto/google/cloud/firestore_v1beta1/proto/firestore_pb2.py
```

I.e in same path as cc_proto_library.

This all woks, but an annoying part is that to use the generated library in some other py_library, in needs to specify the "_virtual_imports/proto_target" path as its "includes" parameter (and I can't make it better than that).

Another option would be to skeep the `_virtual_imports/<name_of_proto_library_target>` the suffix for the generated python stubs, which will make the path look like the following:
```
bazel-bin/google/firestore/v1beta1/google/cloud/firestore_v1beta1/proto/firestore_pb2.py
```

That will make using generated stubs simpler and cleaner (no need to specify imports argument), but it will make it inconsistent with the other rules (like cc_proto_library) and also more susseptible to naming conflicts (if there is already something under the generated path).
2019-09-02 18:00:40 -07:00
Richard Belleville 8ce740cfe0 Switch py_proto_library from using src to deps to conform with google3 2019-08-21 14:24:06 -07:00
Richard Belleville a77404ae6b Add README to bazel test 2019-08-05 16:38:41 -07:00
Richard Belleville 3638167e40 Call grpc_python_deps() from grpc_deps(). 2019-08-05 12:57:50 -07:00
Richard Belleville e89096cdf2 AAAAAAAHHHHHH 2019-08-02 16:04:59 -07:00
Richard Belleville f054bd73f4 Compensate for missing upb dependencies 2019-08-02 14:47:18 -07:00
Richard Belleville 835b3d3293 Copyright. 2019-08-01 17:11:56 -07:00
Richard Belleville 7b2c8c27b0 Separate py_grpc_library and py_proto_library.
By popular demand, we'll now be offering separate py_grpc_library and
py_proto_library targets sharing the same interface as within google3.
This change necessitated some modifications to how we pull in our own
Python-level dependencies and how we make those available to those
pulling in our project via Bazel.

There is now a grpc_python_deps() Bazel workspace rule that pulls in the
appropriate dependencies, which should be called from the client
project's WORKSPACE file. A test has been added to the bazel/test/
directory to verify that this behavior works as intended.

It's worth noting that the protobuf repository's usage of Starlark
bind() caused a great deal of trouble in ensuring that we could also
pull in six.

This change also required a change in the way generated proto code is
imported in the channelz and health-check modules, as well as in their
associated tests. We were importing them two different ways, each
relative. This resulted in two different module objects being imported
into the process, which were incompatible. I am not sure exactly what
caused this behavior to begin, as this should have been possible before
this PR. As a workaround, I am simply trying two different absolute
imports and using the one that works. This should function both inside
and outside of Bazel environments.
2019-08-01 15:16:22 -07:00