betterproto2-compiler 0.2.1__tar.gz → 0.2.2__tar.gz

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.
Files changed (31) hide show
  1. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/PKG-INFO +1 -1
  2. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/pyproject.toml +1 -1
  3. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/casing.py +12 -30
  4. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/compile/importing.py +7 -2
  5. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/models.py +0 -11
  6. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/templates/template.py.j2 +12 -12
  7. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/LICENSE.md +0 -0
  8. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/README.md +0 -0
  9. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/__init__.py +0 -0
  10. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/compile/__init__.py +0 -0
  11. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/compile/naming.py +0 -0
  12. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/known_types/__init__.py +0 -0
  13. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/known_types/any.py +0 -0
  14. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/known_types/duration.py +0 -0
  15. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/known_types/timestamp.py +0 -0
  16. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/lib/__init__.py +0 -0
  17. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/lib/google/__init__.py +0 -0
  18. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/lib/google/protobuf/__init__.py +0 -0
  19. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/lib/google/protobuf/compiler/__init__.py +0 -0
  20. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/lib/message_pool.py +0 -0
  21. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/__init__.py +0 -0
  22. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/__main__.py +0 -0
  23. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/compiler.py +0 -0
  24. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/main.py +0 -0
  25. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/module_validation.py +0 -0
  26. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/parser.py +0 -0
  27. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/plugin.bat +0 -0
  28. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/plugin/typing_compiler.py +0 -0
  29. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/py.typed +0 -0
  30. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/settings.py +0 -0
  31. {betterproto2_compiler-0.2.1 → betterproto2_compiler-0.2.2}/src/betterproto2_compiler/templates/header.py.j2 +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: betterproto2_compiler
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Compiler for betterproto2
5
5
  License: MIT
6
6
  Keywords: protobuf,gRPC,compiler
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "betterproto2_compiler"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "Compiler for betterproto2"
5
5
  authors = ["Adrien Vannson <adrien.vannson@protonmail.com>", "Daniel G. Taylor <danielgtaylor@gmail.com>"]
6
6
  readme = "README.md"
@@ -21,43 +21,25 @@ def safe_snake_case(value: str) -> str:
21
21
  return value
22
22
 
23
23
 
24
- def snake_case(value: str, strict: bool = True) -> str:
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
- Parameters
29
- -----------
30
- value: :class:`str`
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
- Returns
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
- def substitute_word(symbols: str, word: str, is_start: bool) -> str:
42
- if not word:
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
- return ("_" * delimiter_count) + word.lower()
39
+ # Add an underscore before digits
40
+ name = re.sub(r"(?<=[a-zA-Z])([0-9])", r"_\1", name)
54
41
 
55
- snake = re.sub(
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(string_import)
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
- , {{ method.py_input_message_param }}:
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
- , {{ method.py_input_message_param }}_iterator: "{{ 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)) }}"
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
- {{ method.py_input_message_param }}_iterator,
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 {{ method.py_input_message_param }} is None:
142
- {{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
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
- {{ method.py_input_message_param }},
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
- {{ method.py_input_message_param }}_iterator,
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 {{ method.py_input_message_param }} is None:
170
- {{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
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
- {{ method.py_input_message_param }},
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
- , {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"
202
+ , message: "{{ method.py_input_message_type }}"
203
203
  {%- else -%}
204
204
  {# Client streaming: need a request iterator instead #}
205
- , {{ method.py_input_message_param }}_iterator: {{ output_file.settings.typing_compiler.async_iterator(method.py_input_message_type) }}
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 %}