betterproto2-compiler 0.2.1__py3-none-any.whl → 0.2.2__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/casing.py +12 -30
- betterproto2_compiler/compile/importing.py +7 -2
- betterproto2_compiler/plugin/models.py +0 -11
- betterproto2_compiler/templates/template.py.j2 +12 -12
- {betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/METADATA +1 -1
- {betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/RECORD +9 -9
- {betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/LICENSE.md +0 -0
- {betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/WHEEL +0 -0
- {betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/entry_points.txt +0 -0
betterproto2_compiler/casing.py
CHANGED
@@ -21,43 +21,25 @@ def safe_snake_case(value: str) -> str:
|
|
21
21
|
return value
|
22
22
|
|
23
23
|
|
24
|
-
def snake_case(
|
24
|
+
def snake_case(name: str) -> str:
|
25
25
|
"""
|
26
26
|
Join words with an underscore into lowercase and remove symbols.
|
27
|
+
"""
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
The value to convert.
|
32
|
-
strict: :class:`bool`
|
33
|
-
Whether or not to force single underscores.
|
29
|
+
# If there are already underscores in the name, don't break it
|
30
|
+
if "_" in name or not any([c.isupper() for c in name]):
|
31
|
+
return name
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
:class:`str`
|
38
|
-
The value in snake_case.
|
39
|
-
"""
|
33
|
+
# Add an underscore before capital letters
|
34
|
+
name = re.sub(r"(?<=[a-z0-9])([A-Z])", r"_\1", name)
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
return ""
|
44
|
-
if strict:
|
45
|
-
delimiter_count = 0 if is_start else 1 # Single underscore if strict.
|
46
|
-
elif is_start:
|
47
|
-
delimiter_count = len(symbols)
|
48
|
-
elif word.isupper() or word.islower():
|
49
|
-
delimiter_count = max(1, len(symbols)) # Preserve all delimiters if not strict.
|
50
|
-
else:
|
51
|
-
delimiter_count = len(symbols) + 1 # Extra underscore for leading capital.
|
36
|
+
# Add an underscore before capital letters following an acronym
|
37
|
+
name = re.sub(r"(?<=[A-Z])([A-Z])(?=[a-z])", r"_\1", name)
|
52
38
|
|
53
|
-
|
39
|
+
# Add an underscore before digits
|
40
|
+
name = re.sub(r"(?<=[a-zA-Z])([0-9])", r"_\1", name)
|
54
41
|
|
55
|
-
|
56
|
-
f"(^)?({SYMBOLS})({WORD_UPPER}|{WORD})",
|
57
|
-
lambda groups: substitute_word(groups[2], groups[3], groups[1] is not None),
|
58
|
-
value,
|
59
|
-
)
|
60
|
-
return snake
|
42
|
+
return name.lower()
|
61
43
|
|
62
44
|
|
63
45
|
def pascal_case(value: str, strict: bool = True) -> str:
|
@@ -114,7 +114,7 @@ def reference_absolute(imports: set[str], py_package: list[str], py_type: str) -
|
|
114
114
|
Returns a reference to a python type located in the root, i.e. sys.path.
|
115
115
|
"""
|
116
116
|
string_import = ".".join(py_package)
|
117
|
-
string_alias = safe_snake_case(
|
117
|
+
string_alias = "__".join([safe_snake_case(name) for name in py_package])
|
118
118
|
imports.add(f"import {string_import} as {string_alias}")
|
119
119
|
return f"{string_alias}.{py_type}"
|
120
120
|
|
@@ -175,6 +175,11 @@ def reference_cousin(current_package: list[str], imports: set[str], py_package:
|
|
175
175
|
string_from = f".{'.' * distance_up}" + ".".join(py_package[len(shared_ancestry) : -1])
|
176
176
|
string_import = py_package[-1]
|
177
177
|
# Add trailing __ to avoid name mangling (python.org/dev/peps/pep-0008/#id34)
|
178
|
-
string_alias = f"{'_' * distance_up}" + safe_snake_case(".".join(py_package[len(shared_ancestry) :])) + "__"
|
178
|
+
# string_alias = f"{'_' * distance_up}" + safe_snake_case(".".join(py_package[len(shared_ancestry) :])) + "__"
|
179
|
+
string_alias = (
|
180
|
+
f"{'_' * distance_up}"
|
181
|
+
+ "__".join([safe_snake_case(name) for name in py_package[len(shared_ancestry) :]])
|
182
|
+
+ "__"
|
183
|
+
)
|
179
184
|
imports.add(f"from {string_from} import {string_import} as {string_alias}")
|
180
185
|
return f"{string_alias}.{py_type}"
|
@@ -600,17 +600,6 @@ class ServiceMethodCompiler(ProtoContentBase):
|
|
600
600
|
|
601
601
|
return not bool(msg.fields)
|
602
602
|
|
603
|
-
@property
|
604
|
-
def py_input_message_param(self) -> str:
|
605
|
-
"""Param name corresponding to py_input_message_type.
|
606
|
-
|
607
|
-
Returns
|
608
|
-
-------
|
609
|
-
str
|
610
|
-
Param name corresponding to py_input_message_type.
|
611
|
-
"""
|
612
|
-
return pythonize_field_name(self.py_input_message_type)
|
613
|
-
|
614
603
|
@property
|
615
604
|
def py_output_message_type(self) -> str:
|
616
605
|
"""String representation of the Python type corresponding to the
|
@@ -98,7 +98,7 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
98
98
|
{% for method in service.methods %}
|
99
99
|
async def {{ method.py_name }}(self
|
100
100
|
{%- if not method.client_streaming -%}
|
101
|
-
,
|
101
|
+
, message:
|
102
102
|
{%- if method.is_input_msg_empty -%}
|
103
103
|
"{{ output_file.settings.typing_compiler.optional(method.py_input_message_type) }}" = None
|
104
104
|
{%- else -%}
|
@@ -106,7 +106,7 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
106
106
|
{%- endif -%}
|
107
107
|
{%- else -%}
|
108
108
|
{# Client streaming: need a request iterator instead #}
|
109
|
-
,
|
109
|
+
, messages: "{{ output_file.settings.typing_compiler.union(output_file.settings.typing_compiler.async_iterable(method.py_input_message_type), output_file.settings.typing_compiler.iterable(method.py_input_message_type)) }}"
|
110
110
|
{%- endif -%}
|
111
111
|
,
|
112
112
|
*
|
@@ -128,7 +128,7 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
128
128
|
{% if method.client_streaming %}
|
129
129
|
async for response in self._stream_stream(
|
130
130
|
"{{ method.route }}",
|
131
|
-
|
131
|
+
messages,
|
132
132
|
{{ method.py_input_message_type }},
|
133
133
|
{{ method.py_output_message_type }},
|
134
134
|
timeout=timeout,
|
@@ -138,13 +138,13 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
138
138
|
yield response
|
139
139
|
{% else %}{# i.e. not client streaming #}
|
140
140
|
{% if method.is_input_msg_empty %}
|
141
|
-
if
|
142
|
-
|
141
|
+
if message is None:
|
142
|
+
message = {{ method.py_input_message_type }}()
|
143
143
|
|
144
144
|
{% endif %}
|
145
145
|
async for response in self._unary_stream(
|
146
146
|
"{{ method.route }}",
|
147
|
-
|
147
|
+
message,
|
148
148
|
{{ method.py_output_message_type }},
|
149
149
|
timeout=timeout,
|
150
150
|
deadline=deadline,
|
@@ -157,7 +157,7 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
157
157
|
{% if method.client_streaming %}
|
158
158
|
return await self._stream_unary(
|
159
159
|
"{{ method.route }}",
|
160
|
-
|
160
|
+
messages,
|
161
161
|
{{ method.py_input_message_type }},
|
162
162
|
{{ method.py_output_message_type }},
|
163
163
|
timeout=timeout,
|
@@ -166,13 +166,13 @@ class {{ service.py_name }}Stub(betterproto2.ServiceStub):
|
|
166
166
|
)
|
167
167
|
{% else %}{# i.e. not client streaming #}
|
168
168
|
{% if method.is_input_msg_empty %}
|
169
|
-
if
|
170
|
-
|
169
|
+
if message is None:
|
170
|
+
message = {{ method.py_input_message_type }}()
|
171
171
|
|
172
172
|
{% endif %}
|
173
173
|
return await self._unary_unary(
|
174
174
|
"{{ method.route }}",
|
175
|
-
|
175
|
+
message,
|
176
176
|
{{ method.py_output_message_type }},
|
177
177
|
timeout=timeout,
|
178
178
|
deadline=deadline,
|
@@ -199,10 +199,10 @@ class {{ service.py_name }}Base(ServiceBase):
|
|
199
199
|
{% for method in service.methods %}
|
200
200
|
async def {{ method.py_name }}(self
|
201
201
|
{%- if not method.client_streaming -%}
|
202
|
-
,
|
202
|
+
, message: "{{ method.py_input_message_type }}"
|
203
203
|
{%- else -%}
|
204
204
|
{# Client streaming: need a request iterator instead #}
|
205
|
-
,
|
205
|
+
, messages: {{ output_file.settings.typing_compiler.async_iterator(method.py_input_message_type) }}
|
206
206
|
{%- endif -%}
|
207
207
|
) -> {% if method.server_streaming %}{{ output_file.settings.typing_compiler.async_iterator(method.py_output_message_type) }}{% else %}"{{ method.py_output_message_type }}"{% endif %}:
|
208
208
|
{% if method.comment %}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
betterproto2_compiler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
betterproto2_compiler/casing.py,sha256=
|
2
|
+
betterproto2_compiler/casing.py,sha256=HSXLXAOqZzEnu-tC1SZjpW0LIjzdPqUNJEwy1BHzfgg,3056
|
3
3
|
betterproto2_compiler/compile/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
betterproto2_compiler/compile/importing.py,sha256=
|
4
|
+
betterproto2_compiler/compile/importing.py,sha256=4jPXNBbA3jRDQf5n7GHkC1yvR1cozFoFLKRvu5GIzMk,7152
|
5
5
|
betterproto2_compiler/compile/naming.py,sha256=zf0VOmNojzyv33upOGelGxjZTEDE8JULEEED5_3inHg,562
|
6
6
|
betterproto2_compiler/known_types/__init__.py,sha256=Exqo-3ubDuik0TZDTw5ZPqf-dVb2uPJTZxMG7X58E6U,780
|
7
7
|
betterproto2_compiler/known_types/any.py,sha256=QnfSKTXzazZwmsxaFu8_SYNmLww1D2mFdmi29_8Nzb4,1432
|
@@ -16,7 +16,7 @@ betterproto2_compiler/plugin/__init__.py,sha256=L3pW0b4CvkM5x53x_sYt1kYiSFPO0_va
|
|
16
16
|
betterproto2_compiler/plugin/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
|
17
17
|
betterproto2_compiler/plugin/compiler.py,sha256=3sPbCtdzjAGftVvoGe5dvxE8uTzJ78hABA-_f-1rEUo,2471
|
18
18
|
betterproto2_compiler/plugin/main.py,sha256=gI2fSWc9U-fn6MOlkLg7iResr2YsXbdOge6SzNWxBAo,1302
|
19
|
-
betterproto2_compiler/plugin/models.py,sha256=
|
19
|
+
betterproto2_compiler/plugin/models.py,sha256=Kfda57yUyicTVs61HWzFZd7WT6BgntJ19VagFM56mSk,21449
|
20
20
|
betterproto2_compiler/plugin/module_validation.py,sha256=JnP8dSN83eJJVDP_UPJsHzq7E7Md3lah0PnKXDbFW5Q,4808
|
21
21
|
betterproto2_compiler/plugin/parser.py,sha256=9PT8ArcGwnCviIYo1j_dsfPcdroaSVWC0OfLNzI66hU,10410
|
22
22
|
betterproto2_compiler/plugin/plugin.bat,sha256=lfLT1WguAXqyerLLsRL6BfHA0RqUE6QG79v-1BYVSpI,48
|
@@ -24,9 +24,9 @@ betterproto2_compiler/plugin/typing_compiler.py,sha256=IK6m4ggHXK7HL98Ed_WjvQ_ye
|
|
24
24
|
betterproto2_compiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
25
|
betterproto2_compiler/settings.py,sha256=d7XTRMywahR9PcOgaycPXLkHgJMSYDffuSO874yyrh0,182
|
26
26
|
betterproto2_compiler/templates/header.py.j2,sha256=wYBR4yer77dTGM9e1RijuID-mI4GHrmk66OjdVvmBxc,1734
|
27
|
-
betterproto2_compiler/templates/template.py.j2,sha256=
|
28
|
-
betterproto2_compiler-0.2.
|
29
|
-
betterproto2_compiler-0.2.
|
30
|
-
betterproto2_compiler-0.2.
|
31
|
-
betterproto2_compiler-0.2.
|
32
|
-
betterproto2_compiler-0.2.
|
27
|
+
betterproto2_compiler/templates/template.py.j2,sha256=J3eWLM_zBiRQcu7AaLc6LMg54yiifQUpb0l0FdRyNAk,8870
|
28
|
+
betterproto2_compiler-0.2.2.dist-info/LICENSE.md,sha256=Pgl2pReU-2yw2miGeQ55UFlyzqAZ_EpYVyZ2nWjwRv4,1121
|
29
|
+
betterproto2_compiler-0.2.2.dist-info/METADATA,sha256=mfl_LYJm49_hnWbg6Dr98uvgM0Vcvxe0Dx-_Qhy9PKE,1099
|
30
|
+
betterproto2_compiler-0.2.2.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
31
|
+
betterproto2_compiler-0.2.2.dist-info/entry_points.txt,sha256=re3Qg8lLljbVobeeKH2f1FVQZ114wfZkGv3zCZTD8Ok,84
|
32
|
+
betterproto2_compiler-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{betterproto2_compiler-0.2.1.dist-info → betterproto2_compiler-0.2.2.dist-info}/entry_points.txt
RENAMED
File without changes
|