Skip to content

Commit ed430af

Browse files
laramielcopybara-github
authored andcommitted
Minor formatting/include cleanups.
PiperOrigin-RevId: 681493832
1 parent f346779 commit ed430af

23 files changed

+123
-139
lines changed

pybind11_protobuf/BUILD

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pybind_library(
1111
"//visibility:public",
1212
],
1313
deps = [
14-
"//net/proto2/public",
14+
"@com_google_protobuf//:protobuf",
1515
],
1616
)
1717

@@ -25,8 +25,8 @@ pybind_library(
2525
":check_unknown_fields",
2626
":enum_type_caster",
2727
":proto_cast_util",
28-
"//net/proto2/public",
2928
"@com_google_absl//absl/strings:string_view",
29+
"@com_google_protobuf//:protobuf",
3030
],
3131
)
3232

@@ -39,8 +39,6 @@ pybind_library(
3939
],
4040
deps = [
4141
":check_unknown_fields",
42-
"//net/proto2/proto:descriptor_cc_proto",
43-
"//net/proto2/public",
4442
"@com_google_absl//absl/container:flat_hash_map",
4543
"@com_google_absl//absl/log",
4644
"@com_google_absl//absl/log:check",
@@ -60,9 +58,9 @@ pybind_library(
6058
],
6159
deps = [
6260
":proto_cast_util",
63-
"//net/proto2/public",
6461
"@com_google_absl//absl/status:statusor",
6562
"@com_google_absl//absl/types:optional",
63+
"@com_google_protobuf//:protobuf",
6664
],
6765
)
6866

@@ -71,13 +69,12 @@ cc_library(
7169
srcs = ["check_unknown_fields.cc"],
7270
hdrs = ["check_unknown_fields.h"],
7371
deps = [
74-
"//net/proto2/public",
75-
"//net/proto2/python/public:proto_api",
7672
"@com_google_absl//absl/container:flat_hash_map",
7773
"@com_google_absl//absl/container:flat_hash_set",
78-
"@com_google_absl//absl/meta:type_traits",
7974
"@com_google_absl//absl/strings",
8075
"@com_google_absl//absl/synchronization",
76+
"@com_google_protobuf//:protobuf",
77+
"@com_google_protobuf//python:proto_api",
8178
],
8279
)
8380

pybind11_protobuf/check_unknown_fields.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
#include <string>
77
#include <vector>
88

9-
#include "net/proto2/public/descriptor.h"
10-
#include "net/proto2/public/message.h"
11-
#include "net/proto2/public/unknown_field_set.h"
129
#include "absl/container/flat_hash_map.h"
1310
#include "absl/container/flat_hash_set.h"
1411
#include "absl/strings/str_cat.h"
1512
#include "absl/strings/str_join.h"
1613
#include "absl/strings/string_view.h"
1714
#include "absl/synchronization/mutex.h"
15+
#include "google/protobuf/descriptor.h"
16+
#include "google/protobuf/message.h"
17+
#include "google/protobuf/unknown_field_set.h"
18+
#include "python/google/protobuf/proto_api.h"
1819

1920
namespace pybind11_protobuf::check_unknown_fields {
2021
namespace {
@@ -103,8 +104,7 @@ bool HasUnknownFields::FindUnknownFieldsRecursive(
103104

104105
// Stop only if the extension is known by Python.
105106
if (py_proto_api->GetDefaultDescriptorPool()->FindExtensionByNumber(
106-
unknown_field_parent_descriptor,
107-
unknown_field_number)) {
107+
unknown_field_parent_descriptor, unknown_field_number)) {
108108
field_fqn_parts.resize(depth);
109109
return true;
110110
}

pybind11_protobuf/check_unknown_fields.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define PYBIND11_PROTOBUF_CHECK_UNKNOWN_FIELDS_H_
33

44
#include <optional>
5+
#include <string>
56

6-
#include "net/proto2/public/message.h"
7-
#include "net/proto2/python/public/proto_api.h"
87
#include "absl/strings/string_view.h"
8+
#include "google/protobuf/message.h"
9+
#include "python/google/protobuf/proto_api.h"
910

1011
namespace pybind11_protobuf::check_unknown_fields {
1112

pybind11_protobuf/enum_type_caster.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
#include <pybind11/pybind11.h>
1212
#include <pybind11/pytypes.h>
1313

14-
#include <string>
1514
#include <type_traits>
1615

17-
#include "net/proto2/public/descriptor.h"
18-
#include "net/proto2/public/generated_enum_reflection.h"
19-
#include "net/proto2/public/generated_enum_util.h"
16+
#include "google/protobuf/generated_enum_util.h"
2017

2118
// pybind11 type_caster specialization which translates Proto::Enum types
2219
// to/from ints. This will have ODR conflicts when users specify wrappers for
2320
// enums using py::enum_<T>.
2421
//
25-
// ::google::protobuf::is_proto_enum and ::google::protobuf::GetEnumDescriptor are require
22+
// ::google::protobuf::is_proto_enum and ::google::protobuf::GetEnumDescriptor are required.
2623
//
27-
// NOTE: The protobuf compiler does not generate ::google::protobuf::is_proto_enum traits
28-
// for enumerations of oneof fields.
24+
// NOTE: The protobuf compiler does not generate ::google::protobuf::is_proto_enum
25+
// traits for enumerations of oneof fields.
2926
//
3027
// Example:
3128
// #include <pybind11/pybind11.h>

pybind11_protobuf/native_proto_caster.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@
1111
// IWYU
1212
#include <Python.h>
1313

14-
#include <functional>
15-
#include <memory>
16-
#include <optional>
17-
#include <string>
1814
#include <type_traits>
19-
#include <utility>
2015

21-
#include "net/proto2/public/message.h"
2216
#include "absl/strings/string_view.h"
17+
#include "google/protobuf/message.h"
2318
#include "pybind11_protobuf/enum_type_caster.h"
2419
#include "pybind11_protobuf/proto_caster_impl.h"
2520

26-
// pybind11::type_caster<> specialization for ::google::protobuf::Message types that
27-
// that converts protocol buffer objects between C++ and python representations.
28-
// This binder supports binaries linked with both native python protos
29-
// and fast cpp python protos.
21+
// pybind11::type_caster<> specialization for ::google::protobuf::Message types
22+
// that that converts protocol buffer objects between C++ and python
23+
// representations. This binder supports binaries linked with both native python
24+
// protos and fast cpp python protos.
3025
//
3126
// When passing protos between python and C++, if possible, an underlying C++
3227
// object may have ownership transferred, or may be copied if both instances

pybind11_protobuf/proto_cast_util.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include <string>
1212
#include <unordered_set>
1313
#include <utility>
14-
#include <vector>
1514

16-
#include "net/proto2/proto/descriptor.pb.h"
1715
#include "absl/container/flat_hash_map.h"
1816
#include "absl/log/check.h"
1917
#include "absl/log/log.h"
@@ -25,6 +23,7 @@
2523
#include "absl/strings/strip.h"
2624
#include "absl/types/optional.h"
2725
#include "google/protobuf/descriptor.h"
26+
#include "google/protobuf/descriptor.pb.h"
2827
#include "google/protobuf/descriptor_database.h"
2928
#include "google/protobuf/dynamic_message.h"
3029

@@ -34,7 +33,6 @@ using ::google::protobuf::Descriptor;
3433
using ::google::protobuf::DescriptorDatabase;
3534
using ::google::protobuf::DescriptorPool;
3635
using ::google::protobuf::DynamicMessageFactory;
37-
using ::google::protobuf::FileDescriptor;
3836
using ::google::protobuf::FileDescriptorProto;
3937
using ::google::protobuf::Message;
4038
using ::google::protobuf::MessageFactory;
@@ -183,11 +181,9 @@ GlobalState::GlobalState() {
183181

184182
// pybind11_protobuf casting needs a dependency on proto internals to work.
185183
try {
186-
ImportCached("google3.net.proto2.python.public.descriptor");
187-
auto descriptor_pool =
188-
ImportCached("google3.net.proto2.python.public.descriptor_pool");
189-
auto message_factory =
190-
ImportCached("google3.net.proto2.python.public.message_factory");
184+
ImportCached("google.protobuf.descriptor");
185+
auto descriptor_pool = ImportCached("google.protobuf.descriptor_pool");
186+
auto message_factory = ImportCached("google.protobuf.message_factory");
191187
global_pool_ = descriptor_pool.attr("Default")();
192188
find_message_type_by_name_ = global_pool_.attr("FindMessageTypeByName");
193189
if (hasattr(message_factory, "GetMessageClass")) {

pybind11_protobuf/proto_cast_util.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
#include <pybind11/pybind11.h>
77
#include <pybind11/pytypes.h>
88

9-
#include <functional>
109
#include <memory>
1110
#include <string>
12-
#include <type_traits>
13-
#include <utility>
1411

15-
#include "net/proto2/public/descriptor.h"
16-
#include "net/proto2/public/message.h"
1712
#include "absl/strings/string_view.h"
1813
#include "absl/types/optional.h"
14+
#include "google/protobuf/descriptor.h"
15+
#include "google/protobuf/message.h"
1916

2017
// PYBIND11_PROTOBUF_ASSUME_FULL_ABI_COMPATIBILITY can be defined by users
2118
// certain about ABI compatibility between all Python extensions in their

pybind11_protobuf/proto_caster_impl.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
#include <pybind11/pybind11.h>
99
#include <pybind11/pytypes.h>
1010

11-
#include <functional>
1211
#include <memory>
1312
#include <optional>
14-
#include <string>
1513
#include <type_traits>
1614
#include <utility>
1715

18-
#include "net/proto2/proto/descriptor.pb.h"
19-
#include "net/proto2/public/descriptor.h"
20-
#include "net/proto2/public/message.h"
16+
#include "google/protobuf/descriptor.h"
17+
#include "google/protobuf/descriptor.pb.h"
18+
#include "google/protobuf/message.h"
2119
#include "pybind11_protobuf/proto_cast_util.h"
2220

2321
// Enables unsafe conversions; currently these are a work in progress.
@@ -74,8 +72,7 @@ struct proto_caster_load_impl {
7472

7573
owned = std::unique_ptr<ProtoType>(new ProtoType());
7674
value = owned.get();
77-
return owned.get()->ParsePartialFromString(
78-
PyBytesAsStringView(serialized_bytes));
75+
return owned->ParsePartialFromString(PyBytesAsStringView(serialized_bytes));
7976
}
8077

8178
// ensure_owned ensures that the owned member contains a copy of the
@@ -126,8 +123,7 @@ struct proto_caster_load_impl<::google::protobuf::Message> {
126123
src, *descriptor_name)
127124
.release()));
128125
value = owned.get();
129-
return owned.get()->ParsePartialFromString(
130-
PyBytesAsStringView(serialized_bytes));
126+
return owned->ParsePartialFromString(PyBytesAsStringView(serialized_bytes));
131127
}
132128

133129
// ensure_owned ensures that the owned member contains a copy of the
@@ -156,7 +152,8 @@ struct fast_cpp_cast_impl {
156152
(policy == pybind11::return_value_policy::reference ||
157153
policy == pybind11::return_value_policy::reference_internal)) {
158154
throw pybind11::type_error(
159-
"Cannot return a const reference to a ::google::protobuf::Message derived "
155+
"Cannot return a const reference to a ::google::protobuf::Message "
156+
"derived "
160157
"type. Consider setting return_value_policy::copy in the "
161158
"pybind11 def().");
162159
}

pybind11_protobuf/proto_utils.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
#include <pybind11/functional.h>
99

10-
#include <cstddef>
10+
#include <cstdint>
11+
#include <cstdlib>
12+
#include <functional>
1113
#include <memory>
1214
#include <stdexcept>
1315
#include <string>
16+
#include <utility>
1417

15-
#include "net/proto2/proto/descriptor.pb.h"
16-
#include "net/proto2/public/descriptor.h"
17-
#include "net/proto2/public/message.h"
18-
#include "net/proto2/public/reflection.h"
1918
#include "absl/strings/str_cat.h"
2019
#include "absl/strings/string_view.h"
20+
#include "google/protobuf/descriptor.h"
21+
#include "google/protobuf/descriptor.pb.h"
22+
#include "google/protobuf/message.h"
23+
#include "google/protobuf/reflection.h"
2124

2225
namespace pybind11 {
2326
namespace google {
@@ -516,7 +519,7 @@ struct FindMapPair {
516519
handle key, bool add_key = true) {
517520
// When using the proto reflection API, maps are represented as repeated
518521
// message fields (messages with 2 elements: 'key' and 'value'). If protocol
519-
// buffers guarrantee a consistent (and useful) ordering of elements,
522+
// buffers guarantee a consistent (and useful) ordering of elements,
520523
// it should be possible to do this search in O(log(n)) time. However, that
521524
// requires more knowledge of protobuf internals than I have, so for now
522525
// assume a random ordering of elements, in which case a O(n) search is

pybind11_protobuf/proto_utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <memory>
1212

13-
#include "net/proto2/public/message.h"
13+
#include "google/protobuf/message.h"
1414

1515
namespace pybind11 {
1616
namespace google {
@@ -19,9 +19,9 @@ namespace google {
1919
// Unlike ProtoSetField, this allows setting message, map and repeated fields.
2020
void ProtoInitFields(::google::protobuf::Message* message, kwargs kwargs_in);
2121

22-
// Wrapper around ::google::protobuf::Message::CopyFrom which can efficiently copy from
23-
// either a wrapped C++ or native python proto. Throws an error if `other`
24-
// is not a proto of the correct type.
22+
// Wrapper around ::google::protobuf::Message::CopyFrom which can efficiently
23+
// copy from either a wrapped C++ or native python proto. Throws an error if
24+
// `other` is not a proto of the correct type.
2525
void ProtoCopyFrom(::google::protobuf::Message* msg, handle other);
2626

2727
// Allocate and return the ProtoType given by the template argument.

0 commit comments

Comments
 (0)