betterproto2-compiler 0.7.0__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- betterproto2_compiler/known_types/google_values.py +18 -18
- betterproto2_compiler/plugin/models.py +34 -3
- betterproto2_compiler/templates/service_stub_sync.py.j2 +4 -6
- betterproto2_compiler/templates/template.py.j2 +10 -0
- {betterproto2_compiler-0.7.0.dist-info → betterproto2_compiler-0.7.1.dist-info}/METADATA +1 -1
- {betterproto2_compiler-0.7.0.dist-info → betterproto2_compiler-0.7.1.dist-info}/RECORD +8 -8
- {betterproto2_compiler-0.7.0.dist-info → betterproto2_compiler-0.7.1.dist-info}/WHEEL +0 -0
- {betterproto2_compiler-0.7.0.dist-info → betterproto2_compiler-0.7.1.dist-info}/entry_points.txt +0 -0
@@ -24,10 +24,10 @@ class BoolValue(VanillaBoolValue):
|
|
24
24
|
return self.value
|
25
25
|
|
26
26
|
@classmethod
|
27
|
-
def from_dict(cls, value):
|
27
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
28
28
|
if isinstance(value, bool):
|
29
29
|
return BoolValue(value=value)
|
30
|
-
return super().from_dict(value)
|
30
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
31
31
|
|
32
32
|
def to_dict(
|
33
33
|
self,
|
@@ -48,10 +48,10 @@ class Int32Value(VanillaInt32Value):
|
|
48
48
|
return self.value
|
49
49
|
|
50
50
|
@classmethod
|
51
|
-
def from_dict(cls, value):
|
51
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
52
52
|
if isinstance(value, int):
|
53
53
|
return Int32Value(value=value)
|
54
|
-
return super().from_dict(value)
|
54
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
55
55
|
|
56
56
|
def to_dict(
|
57
57
|
self,
|
@@ -72,10 +72,10 @@ class Int64Value(VanillaInt64Value):
|
|
72
72
|
return self.value
|
73
73
|
|
74
74
|
@classmethod
|
75
|
-
def from_dict(cls, value):
|
75
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
76
76
|
if isinstance(value, int):
|
77
77
|
return Int64Value(value=value)
|
78
|
-
return super().from_dict(value)
|
78
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
79
79
|
|
80
80
|
def to_dict(
|
81
81
|
self,
|
@@ -96,10 +96,10 @@ class UInt32Value(VanillaUInt32Value):
|
|
96
96
|
return self.value
|
97
97
|
|
98
98
|
@classmethod
|
99
|
-
def from_dict(cls, value):
|
99
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
100
100
|
if isinstance(value, int):
|
101
101
|
return UInt32Value(value=value)
|
102
|
-
return super().from_dict(value)
|
102
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
103
103
|
|
104
104
|
def to_dict(
|
105
105
|
self,
|
@@ -120,10 +120,10 @@ class UInt64Value(VanillaUInt64Value):
|
|
120
120
|
return self.value
|
121
121
|
|
122
122
|
@classmethod
|
123
|
-
def from_dict(cls, value):
|
123
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
124
124
|
if isinstance(value, int):
|
125
125
|
return UInt64Value(value=value)
|
126
|
-
return super().from_dict(value)
|
126
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
127
127
|
|
128
128
|
def to_dict(
|
129
129
|
self,
|
@@ -144,10 +144,10 @@ class FloatValue(VanillaFloatValue):
|
|
144
144
|
return self.value
|
145
145
|
|
146
146
|
@classmethod
|
147
|
-
def from_dict(cls, value):
|
147
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
148
148
|
if isinstance(value, float):
|
149
149
|
return FloatValue(value=value)
|
150
|
-
return super().from_dict(value)
|
150
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
151
151
|
|
152
152
|
def to_dict(
|
153
153
|
self,
|
@@ -168,10 +168,10 @@ class DoubleValue(VanillaDoubleValue):
|
|
168
168
|
return self.value
|
169
169
|
|
170
170
|
@classmethod
|
171
|
-
def from_dict(cls, value):
|
171
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
172
172
|
if isinstance(value, float):
|
173
173
|
return DoubleValue(value=value)
|
174
|
-
return super().from_dict(value)
|
174
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
175
175
|
|
176
176
|
def to_dict(
|
177
177
|
self,
|
@@ -192,10 +192,10 @@ class StringValue(VanillaStringValue):
|
|
192
192
|
return self.value
|
193
193
|
|
194
194
|
@classmethod
|
195
|
-
def from_dict(cls, value):
|
195
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
196
196
|
if isinstance(value, str):
|
197
197
|
return StringValue(value=value)
|
198
|
-
return super().from_dict(value)
|
198
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
199
199
|
|
200
200
|
def to_dict(
|
201
201
|
self,
|
@@ -216,10 +216,10 @@ class BytesValue(VanillaBytesValue):
|
|
216
216
|
return self.value
|
217
217
|
|
218
218
|
@classmethod
|
219
|
-
def from_dict(cls, value):
|
219
|
+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
|
220
220
|
if isinstance(value, bytes):
|
221
221
|
return BytesValue(value=value)
|
222
|
-
return super().from_dict(value)
|
222
|
+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
|
223
223
|
|
224
224
|
def to_dict(
|
225
225
|
self,
|
@@ -34,10 +34,10 @@ from dataclasses import (
|
|
34
34
|
|
35
35
|
from betterproto2 import unwrap
|
36
36
|
|
37
|
+
from betterproto2_compiler import casing
|
37
38
|
from betterproto2_compiler.compile.importing import get_type_reference, parse_source_type_name
|
38
39
|
from betterproto2_compiler.compile.naming import (
|
39
40
|
pythonize_class_name,
|
40
|
-
pythonize_enum_member_name,
|
41
41
|
pythonize_field_name,
|
42
42
|
pythonize_method_name,
|
43
43
|
)
|
@@ -610,20 +610,47 @@ class EnumDefinitionCompiler(ProtoContentBase):
|
|
610
610
|
"""Representation of an Enum entry."""
|
611
611
|
|
612
612
|
name: str
|
613
|
+
proto_name: str
|
613
614
|
value: int
|
614
615
|
comment: str
|
615
616
|
|
616
617
|
def __post_init__(self) -> None:
|
617
|
-
# Get entries/allowed values for this Enum
|
618
618
|
self.entries = [
|
619
619
|
self.EnumEntry(
|
620
|
-
name=
|
620
|
+
name=entry_proto_value.name,
|
621
|
+
proto_name=entry_proto_value.name,
|
621
622
|
value=entry_proto_value.number,
|
622
623
|
comment=get_comment(proto_file=self.source_file, path=self.path + [2, entry_number]),
|
623
624
|
)
|
624
625
|
for entry_number, entry_proto_value in enumerate(self.proto_obj.value)
|
625
626
|
]
|
626
627
|
|
628
|
+
if not self.entries:
|
629
|
+
return
|
630
|
+
|
631
|
+
# Remove enum prefixes
|
632
|
+
enum_name: str = self.proto_obj.name
|
633
|
+
|
634
|
+
enum_name_reduced = enum_name.replace("_", "").lower()
|
635
|
+
|
636
|
+
first_entry = self.entries[0].name
|
637
|
+
|
638
|
+
# Find the potential common prefix
|
639
|
+
enum_prefix = ""
|
640
|
+
for i in range(len(first_entry)):
|
641
|
+
if first_entry[: i + 1].replace("_", "").lower() == enum_name_reduced:
|
642
|
+
enum_prefix = f"{first_entry[: i + 1]}_"
|
643
|
+
break
|
644
|
+
|
645
|
+
should_rename = enum_prefix and all(entry.name.startswith(enum_prefix) for entry in self.entries)
|
646
|
+
|
647
|
+
if should_rename:
|
648
|
+
for entry in self.entries:
|
649
|
+
entry.name = entry.name[len(enum_prefix) :]
|
650
|
+
|
651
|
+
for entry in self.entries:
|
652
|
+
entry.name = casing.sanitize_name(entry.name)
|
653
|
+
|
627
654
|
@property
|
628
655
|
def proto_name(self) -> str:
|
629
656
|
return self.proto_obj.name
|
@@ -647,6 +674,10 @@ class EnumDefinitionCompiler(ProtoContentBase):
|
|
647
674
|
"""
|
648
675
|
return self.output_file.get_descriptor_name(self.source_file)
|
649
676
|
|
677
|
+
@property
|
678
|
+
def has_renamed_entries(self) -> bool:
|
679
|
+
return any(entry.proto_name != entry.name for entry in self.entries)
|
680
|
+
|
650
681
|
|
651
682
|
@dataclass(kw_only=True)
|
652
683
|
class ServiceCompiler(ProtoContentBase):
|
@@ -29,24 +29,22 @@
|
|
29
29
|
{% block method_body %}
|
30
30
|
{% if method.server_streaming %}
|
31
31
|
{% if method.client_streaming %}
|
32
|
-
|
32
|
+
yield from self._channel.stream_stream(
|
33
33
|
"{{ method.route }}",
|
34
34
|
{{ method.py_input_message_type }}.SerializeToString,
|
35
35
|
{{ method.py_output_message_type }}.FromString,
|
36
|
-
)(iter(messages))
|
37
|
-
yield response
|
36
|
+
)(iter(messages))
|
38
37
|
{% else %}
|
39
38
|
{% if method.is_input_msg_empty %}
|
40
39
|
if message is None:
|
41
40
|
message = {{ method.py_input_message_type }}()
|
42
41
|
|
43
42
|
{% endif %}
|
44
|
-
|
43
|
+
yield from self._channel.unary_stream(
|
45
44
|
"{{ method.route }}",
|
46
45
|
{{ method.py_input_message_type }}.SerializeToString,
|
47
46
|
{{ method.py_output_message_type }}.FromString,
|
48
|
-
)(message)
|
49
|
-
yield response
|
47
|
+
)(message)
|
50
48
|
|
51
49
|
{% endif %}
|
52
50
|
{% else %}
|
@@ -31,6 +31,16 @@ class {{ enum.py_name | add_to_all }}(betterproto2.Enum):
|
|
31
31
|
return core_schema.int_schema(ge=0)
|
32
32
|
{% endif %}
|
33
33
|
|
34
|
+
{% if enum.has_renamed_entries %}
|
35
|
+
betterproto_proto_names = {
|
36
|
+
{% for entry in enum.entries %}
|
37
|
+
{% if entry.proto_name != entry.name %}
|
38
|
+
{{ entry.value }}: "{{ entry.proto_name }}",
|
39
|
+
{% endif %}
|
40
|
+
{% endfor %}
|
41
|
+
}
|
42
|
+
{% endif %}
|
43
|
+
|
34
44
|
{% endfor %}
|
35
45
|
{% for _, message in output_file.messages|dictsort(by="key") %}
|
36
46
|
{% if output_file.settings.pydantic_dataclasses %}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: betterproto2_compiler
|
3
|
-
Version: 0.7.
|
3
|
+
Version: 0.7.1
|
4
4
|
Summary: Compiler for betterproto2
|
5
5
|
Project-URL: Documentation, https://betterproto.github.io/python-betterproto2/
|
6
6
|
Project-URL: Repository, https://github.com/betterproto/python-betterproto2
|
@@ -8,7 +8,7 @@ betterproto2_compiler/compile/naming.py,sha256=zf0VOmNojzyv33upOGelGxjZTEDE8JULE
|
|
8
8
|
betterproto2_compiler/known_types/__init__.py,sha256=nrWckuv4hGhL8-tW7V5TD5qXs1Sa5vC7zMusGnz7jsE,3485
|
9
9
|
betterproto2_compiler/known_types/any.py,sha256=E3OoAoUU9xrGHmYEvF0YnrwQdTUuY4h54XbKU0eGxQ8,1897
|
10
10
|
betterproto2_compiler/known_types/duration.py,sha256=M-qsFeiHsw5Z_AoSata1ZUjfkhooP9WhrmecNfuP16k,2312
|
11
|
-
betterproto2_compiler/known_types/google_values.py,sha256=
|
11
|
+
betterproto2_compiler/known_types/google_values.py,sha256=F5MmKIj70dNBdnusKB9ejDal5E2D_ZTOdpMt53H6ciU,7453
|
12
12
|
betterproto2_compiler/known_types/timestamp.py,sha256=y1sNWG2Q0FWv6nIte1UTifFVCsryp7T8foXZqp4qhQQ,3409
|
13
13
|
betterproto2_compiler/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
betterproto2_compiler/lib/message_pool.py,sha256=4-cRhhiM6bmfpUJZ8qxc8LEyqHBHpLCcotjbyZxl7JM,71
|
@@ -19,16 +19,16 @@ betterproto2_compiler/plugin/__init__.py,sha256=L3pW0b4CvkM5x53x_sYt1kYiSFPO0_va
|
|
19
19
|
betterproto2_compiler/plugin/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
|
20
20
|
betterproto2_compiler/plugin/compiler.py,sha256=9jZcNlwxWLUQlZyCLKG33P2xCoJgqaIQHIgcZM40JGY,2730
|
21
21
|
betterproto2_compiler/plugin/main.py,sha256=b1jDEdG1Iau-4cPq89uSjU0SHwC278SxqwiuFwIF8fA,1288
|
22
|
-
betterproto2_compiler/plugin/models.py,sha256=
|
22
|
+
betterproto2_compiler/plugin/models.py,sha256=7iMpcTUlhl3s3xGtfdvVE6AlsiOqlQi3txebT8RW0Cw,26165
|
23
23
|
betterproto2_compiler/plugin/module_validation.py,sha256=JnP8dSN83eJJVDP_UPJsHzq7E7Md3lah0PnKXDbFW5Q,4808
|
24
24
|
betterproto2_compiler/plugin/parser.py,sha256=GHVZGpC_lxvQRGgDaJTCS4ab9sUST7XAef2wj2UKqOg,10966
|
25
25
|
betterproto2_compiler/plugin/plugin.bat,sha256=lfLT1WguAXqyerLLsRL6BfHA0RqUE6QG79v-1BYVSpI,48
|
26
26
|
betterproto2_compiler/templates/header.py.j2,sha256=4C88YH5jtEzlBcUP054rk6lK5pQ1n5_TCzlH_3VrztY,1754
|
27
27
|
betterproto2_compiler/templates/service_stub.py.j2,sha256=2fhbty6uw57EyxOskGcNlZjIjGELMKWY--pvq5ZEjFw,967
|
28
28
|
betterproto2_compiler/templates/service_stub_async.py.j2,sha256=JNOAa8FPhzYS5D0zi0DPESVEwAjkdFsVQZ008Qi4JmE,2968
|
29
|
-
betterproto2_compiler/templates/service_stub_sync.py.j2,sha256=
|
30
|
-
betterproto2_compiler/templates/template.py.j2,sha256=
|
31
|
-
betterproto2_compiler-0.7.
|
32
|
-
betterproto2_compiler-0.7.
|
33
|
-
betterproto2_compiler-0.7.
|
34
|
-
betterproto2_compiler-0.7.
|
29
|
+
betterproto2_compiler/templates/service_stub_sync.py.j2,sha256=ru0Gw4u3vQ3QYpHQVCxQ7aXFGmNkNxHyW8_KijcB9Ao,2576
|
30
|
+
betterproto2_compiler/templates/template.py.j2,sha256=D3Z38RnAwd1Xr2VHGqABXTKWe7pRSBQlIQFZoBjf59c,6847
|
31
|
+
betterproto2_compiler-0.7.1.dist-info/METADATA,sha256=KjBSTiA0snZZaVtLhV_6WTBmW6H3HAFBph-bSUsIsrw,658
|
32
|
+
betterproto2_compiler-0.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
33
|
+
betterproto2_compiler-0.7.1.dist-info/entry_points.txt,sha256=MXDaz7YfiaWx8KiSzArjUPLt6eTlMRbqzE4jCjXozuI,85
|
34
|
+
betterproto2_compiler-0.7.1.dist-info/RECORD,,
|
File without changes
|
{betterproto2_compiler-0.7.0.dist-info → betterproto2_compiler-0.7.1.dist-info}/entry_points.txt
RENAMED
File without changes
|