betterproto2-compiler 0.5.0__py3-none-any.whl → 0.6.0__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/any.py +1 -1
- betterproto2_compiler/lib/google/protobuf/__init__.py +1 -1
- betterproto2_compiler/lib/google/protobuf/compiler/__init__.py +1 -1
- betterproto2_compiler/plugin/compiler.py +14 -4
- betterproto2_compiler/plugin/main.py +1 -2
- betterproto2_compiler/plugin/models.py +35 -2
- betterproto2_compiler/templates/header.py.j2 +3 -9
- betterproto2_compiler/templates/service_stub.py.j2 +1 -1
- betterproto2_compiler/templates/template.py.j2 +3 -3
- betterproto2_compiler-0.6.0.dist-info/METADATA +15 -0
- {betterproto2_compiler-0.5.0.dist-info → betterproto2_compiler-0.6.0.dist-info}/RECORD +16 -17
- {betterproto2_compiler-0.5.0.dist-info → betterproto2_compiler-0.6.0.dist-info}/WHEEL +1 -1
- betterproto2_compiler-0.6.0.dist-info/entry_points.txt +2 -0
- betterproto2_compiler-0.5.0.dist-info/LICENSE.md +0 -22
- betterproto2_compiler-0.5.0.dist-info/METADATA +0 -36
- betterproto2_compiler-0.5.0.dist-info/entry_points.txt +0 -3
@@ -37,7 +37,7 @@ class Any(VanillaAny):
|
|
37
37
|
except KeyError:
|
38
38
|
raise TypeError(f"Can't unpack unregistered type: {self.type_url}")
|
39
39
|
|
40
|
-
return message_type
|
40
|
+
return message_type.parse(self.value)
|
41
41
|
|
42
42
|
def to_dict(self, **kwargs) -> dict[str, typing.Any]:
|
43
43
|
# TODO allow passing a message pool to `to_dict`
|
@@ -33,17 +33,27 @@ def outputfile_compiler(output_file: OutputTemplate) -> str:
|
|
33
33
|
loader=jinja2.FileSystemLoader(templates_folder),
|
34
34
|
undefined=jinja2.StrictUndefined,
|
35
35
|
)
|
36
|
-
|
36
|
+
|
37
|
+
# List of the symbols that should appear in the `__all__` variable of the file
|
38
|
+
all: list[str] = []
|
39
|
+
|
40
|
+
def add_to_all(name: str) -> str:
|
41
|
+
all.append(name)
|
42
|
+
return name
|
43
|
+
|
44
|
+
env.filters["add_to_all"] = add_to_all
|
45
|
+
|
37
46
|
body_template = env.get_template("template.py.j2")
|
38
47
|
header_template = env.get_template("header.py.j2")
|
39
48
|
|
49
|
+
# Load the body first do know the symbols defined in the file
|
40
50
|
code = body_template.render(output_file=output_file)
|
41
|
-
code = header_template.render(output_file=output_file, version=version) + "\n" + code
|
51
|
+
code = header_template.render(output_file=output_file, version=version, all=all) + "\n" + code
|
42
52
|
|
43
53
|
try:
|
44
|
-
# Sort imports, delete unused ones
|
54
|
+
# Sort imports, delete unused ones, sort __all__
|
45
55
|
code = subprocess.check_output(
|
46
|
-
["ruff", "check", "--select", "I,F401,
|
56
|
+
["ruff", "check", "--select", "I,F401,TC005,RUF022", "--fix", "--silent", "-"],
|
47
57
|
input=code,
|
48
58
|
encoding="utf-8",
|
49
59
|
)
|
@@ -353,8 +353,7 @@ class FieldCompiler(ProtoContentBase):
|
|
353
353
|
|
354
354
|
@property
|
355
355
|
def field_type(self) -> FieldType:
|
356
|
-
|
357
|
-
return FieldType(self.proto_obj.type)
|
356
|
+
return self.proto_obj.type
|
358
357
|
|
359
358
|
@property
|
360
359
|
def packed(self) -> bool:
|
@@ -411,12 +410,46 @@ class FieldCompiler(ProtoContentBase):
|
|
411
410
|
def unwrapped_py_type(self) -> str:
|
412
411
|
return self._py_type(wrap=False)
|
413
412
|
|
413
|
+
@property
|
414
|
+
def annotations(self) -> list[str]:
|
415
|
+
"""List of the Pydantic annotation to add to the field."""
|
416
|
+
assert self.output_file.settings.pydantic_dataclasses
|
417
|
+
|
418
|
+
annotations = []
|
419
|
+
|
420
|
+
if self.proto_obj.type in (FieldType.TYPE_INT32, FieldType.TYPE_SFIXED32, FieldType.TYPE_SINT32):
|
421
|
+
annotations.append("pydantic.Field(ge=-2**31, le=2**31 - 1)")
|
422
|
+
|
423
|
+
elif self.proto_obj.type in (FieldType.TYPE_UINT32, FieldType.TYPE_FIXED32):
|
424
|
+
annotations.append("pydantic.Field(ge=0, le=2**32 - 1)")
|
425
|
+
|
426
|
+
elif self.proto_obj.type in (FieldType.TYPE_INT64, FieldType.TYPE_SFIXED64, FieldType.TYPE_SINT64):
|
427
|
+
annotations.append("pydantic.Field(ge=-2**63, le=2**63 - 1)")
|
428
|
+
|
429
|
+
elif self.proto_obj.type in (FieldType.TYPE_UINT64, FieldType.TYPE_FIXED64):
|
430
|
+
annotations.append("pydantic.Field(ge=0, le=2**64 - 1)")
|
431
|
+
|
432
|
+
elif self.proto_obj.type == FieldType.TYPE_FLOAT:
|
433
|
+
annotations.append("pydantic.AfterValidator(betterproto2.validators.validate_float32)")
|
434
|
+
|
435
|
+
elif self.proto_obj.type == FieldType.TYPE_STRING:
|
436
|
+
annotations.append("pydantic.AfterValidator(betterproto2.validators.validate_string)")
|
437
|
+
|
438
|
+
return annotations
|
439
|
+
|
414
440
|
@property
|
415
441
|
def annotation(self) -> str:
|
416
442
|
py_type = self.py_type
|
417
443
|
|
418
444
|
if self.use_builtins:
|
419
445
|
py_type = f"builtins.{py_type}"
|
446
|
+
|
447
|
+
# Add the pydantic annotation if needed
|
448
|
+
if self.output_file.settings.pydantic_dataclasses:
|
449
|
+
annotations = self.annotations
|
450
|
+
if annotations:
|
451
|
+
py_type = f"typing.Annotated[{py_type}, {', '.join(annotations)}]"
|
452
|
+
|
420
453
|
if self.repeated:
|
421
454
|
return f"list[{py_type}]"
|
422
455
|
if self.optional:
|
@@ -6,15 +6,8 @@
|
|
6
6
|
# This file has been @generated
|
7
7
|
|
8
8
|
__all__ = (
|
9
|
-
{
|
10
|
-
|
11
|
-
{%- endfor -%}
|
12
|
-
{% for _, message in output_file.messages|dictsort(by="key") %}
|
13
|
-
"{{ message.py_name }}",
|
14
|
-
{%- endfor -%}
|
15
|
-
{% for _, service in output_file.services|dictsort(by="key") %}
|
16
|
-
"{{ service.py_name }}Stub",
|
17
|
-
"{{ service.py_name }}Base",
|
9
|
+
{%- for name in all -%}
|
10
|
+
"{{ name }}",
|
18
11
|
{%- endfor -%}
|
19
12
|
)
|
20
13
|
|
@@ -28,6 +21,7 @@ import typing
|
|
28
21
|
from typing import TYPE_CHECKING
|
29
22
|
|
30
23
|
{% if output_file.settings.pydantic_dataclasses %}
|
24
|
+
import pydantic
|
31
25
|
from pydantic.dataclasses import dataclass
|
32
26
|
from pydantic import model_validator
|
33
27
|
{%- else -%}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class {% block class_name %}{% endblock %}({% block inherit_from %}{% endblock %}):
|
1
|
+
class {% filter add_to_all %}{% block class_name %}{% endblock %}{% endfilter %}({% block inherit_from %}{% endblock %}):
|
2
2
|
{% block service_docstring scoped %}
|
3
3
|
{% if service.comment %}
|
4
4
|
"""
|
@@ -1,5 +1,5 @@
|
|
1
1
|
{% for _, enum in output_file.enums|dictsort(by="key") %}
|
2
|
-
class {{ enum.py_name }}(betterproto2.Enum):
|
2
|
+
class {{ enum.py_name | add_to_all }}(betterproto2.Enum):
|
3
3
|
{% if enum.comment %}
|
4
4
|
"""
|
5
5
|
{{ enum.comment | indent(4) }}
|
@@ -31,7 +31,7 @@ class {{ enum.py_name }}(betterproto2.Enum):
|
|
31
31
|
{% else %}
|
32
32
|
@dataclass(eq=False, repr=False)
|
33
33
|
{% endif %}
|
34
|
-
class {{ message.py_name }}(betterproto2.Message):
|
34
|
+
class {{ message.py_name | add_to_all }}(betterproto2.Message):
|
35
35
|
{% if message.comment or message.oneofs %}
|
36
36
|
"""
|
37
37
|
{{ message.comment | indent(4) }}
|
@@ -104,7 +104,7 @@ default_message_pool.register_message("{{ output_file.package }}", "{{ message.p
|
|
104
104
|
|
105
105
|
{% if output_file.settings.server_generation == "async" %}
|
106
106
|
{% for _, service in output_file.services|dictsort(by="key") %}
|
107
|
-
class {{ service.py_name }}
|
107
|
+
class {{ (service.py_name + "Base") | add_to_all }}(ServiceBase):
|
108
108
|
{% if service.comment %}
|
109
109
|
"""
|
110
110
|
{{ service.comment | indent(4) }}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: betterproto2_compiler
|
3
|
+
Version: 0.6.0
|
4
|
+
Summary: Compiler for betterproto2
|
5
|
+
Project-URL: Documentation, https://betterproto.github.io/python-betterproto2/
|
6
|
+
Project-URL: Repository, https://github.com/betterproto/python-betterproto2
|
7
|
+
Author-email: Adrien Vannson <adrien.vannson@protonmail.com>, "Daniel G. Taylor" <danielgtaylor@gmail.com>
|
8
|
+
License-Expression: MIT
|
9
|
+
Keywords: compiler,gRPC,protobuf
|
10
|
+
Requires-Python: <4.0,>=3.10
|
11
|
+
Requires-Dist: betterproto2[grpclib]<0.7,>=0.6.0
|
12
|
+
Requires-Dist: jinja2>=3.0.3
|
13
|
+
Requires-Dist: ruff~=0.9.3
|
14
|
+
Requires-Dist: strenum<0.5,>=0.4.15; python_version == '3.10'
|
15
|
+
Requires-Dist: typing-extensions<5,>=4.7.1
|
@@ -1,35 +1,34 @@
|
|
1
1
|
betterproto2_compiler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
betterproto2_compiler/casing.py,sha256=HSXLXAOqZzEnu-tC1SZjpW0LIjzdPqUNJEwy1BHzfgg,3056
|
3
|
+
betterproto2_compiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
betterproto2_compiler/settings.py,sha256=ggLU8qYTTACwdNN94cSznQchu-fJSJxZz041FXRwq7Y,1976
|
3
5
|
betterproto2_compiler/compile/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
6
|
betterproto2_compiler/compile/importing.py,sha256=cJZ1BqjSHaDwXlfseH7f73pMnBZTiqLyOQfQfyganVM,6256
|
5
7
|
betterproto2_compiler/compile/naming.py,sha256=zf0VOmNojzyv33upOGelGxjZTEDE8JULEEED5_3inHg,562
|
6
8
|
betterproto2_compiler/known_types/__init__.py,sha256=nrWckuv4hGhL8-tW7V5TD5qXs1Sa5vC7zMusGnz7jsE,3485
|
7
|
-
betterproto2_compiler/known_types/any.py,sha256=
|
9
|
+
betterproto2_compiler/known_types/any.py,sha256=E3OoAoUU9xrGHmYEvF0YnrwQdTUuY4h54XbKU0eGxQ8,1897
|
8
10
|
betterproto2_compiler/known_types/duration.py,sha256=M-qsFeiHsw5Z_AoSata1ZUjfkhooP9WhrmecNfuP16k,2312
|
9
11
|
betterproto2_compiler/known_types/google_values.py,sha256=7JoPXVs6cVg_ihIWlWIDElSSuW0BymRnPHerz1bFuH4,6688
|
10
12
|
betterproto2_compiler/known_types/timestamp.py,sha256=y1sNWG2Q0FWv6nIte1UTifFVCsryp7T8foXZqp4qhQQ,3409
|
11
13
|
betterproto2_compiler/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
betterproto2_compiler/lib/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
betterproto2_compiler/lib/google/protobuf/__init__.py,sha256=yC7k_A1XA9-CPzhIaJfWJSIBpqyaLx7IVVuvXrqD-iQ,102114
|
14
|
-
betterproto2_compiler/lib/google/protobuf/compiler/__init__.py,sha256=IriT5naeEkcxA-R2EpzOGBMLVGgVO6CXqvrR8HVaR28,9600
|
15
14
|
betterproto2_compiler/lib/message_pool.py,sha256=4-cRhhiM6bmfpUJZ8qxc8LEyqHBHpLCcotjbyZxl7JM,71
|
15
|
+
betterproto2_compiler/lib/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
+
betterproto2_compiler/lib/google/protobuf/__init__.py,sha256=UWGp10_l07eCd2AW1qVVJHrfWf7DiQHQqWoBLOxbDfI,102114
|
17
|
+
betterproto2_compiler/lib/google/protobuf/compiler/__init__.py,sha256=NSY2v-qU_CIqGHtXv02fXs1D6K_bPWJtr5Gf9byPFpA,9600
|
16
18
|
betterproto2_compiler/plugin/__init__.py,sha256=L3pW0b4CvkM5x53x_sYt1kYiSFPO0_vaeH6EQPq9FAM,43
|
17
19
|
betterproto2_compiler/plugin/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
|
18
|
-
betterproto2_compiler/plugin/compiler.py,sha256=
|
19
|
-
betterproto2_compiler/plugin/main.py,sha256=
|
20
|
-
betterproto2_compiler/plugin/models.py,sha256=
|
20
|
+
betterproto2_compiler/plugin/compiler.py,sha256=9jZcNlwxWLUQlZyCLKG33P2xCoJgqaIQHIgcZM40JGY,2730
|
21
|
+
betterproto2_compiler/plugin/main.py,sha256=b1jDEdG1Iau-4cPq89uSjU0SHwC278SxqwiuFwIF8fA,1288
|
22
|
+
betterproto2_compiler/plugin/models.py,sha256=2JZWVgzemhgoyZdeArLEh7fBdxBLpqQOvUXlx8cRD1c,23638
|
21
23
|
betterproto2_compiler/plugin/module_validation.py,sha256=JnP8dSN83eJJVDP_UPJsHzq7E7Md3lah0PnKXDbFW5Q,4808
|
22
24
|
betterproto2_compiler/plugin/parser.py,sha256=XJd7n78E6Gnv04L1faGyTCOV3v0sv1eD5-AenNhPDMQ,10197
|
23
25
|
betterproto2_compiler/plugin/plugin.bat,sha256=lfLT1WguAXqyerLLsRL6BfHA0RqUE6QG79v-1BYVSpI,48
|
24
|
-
betterproto2_compiler/py.
|
25
|
-
betterproto2_compiler/
|
26
|
-
betterproto2_compiler/templates/header.py.j2,sha256=nTUJ-BioeTTCrEr2ZbxPPUl6iBqHOxXr_NAVOGa8jYg,1622
|
27
|
-
betterproto2_compiler/templates/service_stub.py.j2,sha256=r0AefgNbDCh-iDgFNV7aNx8fNe5kQY-8TNew-T_tUXc,929
|
26
|
+
betterproto2_compiler/templates/header.py.j2,sha256=9W34FKHVKItXQzIpiWQQbjBLP1PzGdJOdnef1IlJGa4,1311
|
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
29
|
betterproto2_compiler/templates/service_stub_sync.py.j2,sha256=V7HJIQJEgivX8VEBt7Ju6cXG5FeeCY9QyYMy1kicElM,2642
|
30
|
-
betterproto2_compiler/templates/template.py.j2,sha256=
|
31
|
-
betterproto2_compiler-0.
|
32
|
-
betterproto2_compiler-0.
|
33
|
-
betterproto2_compiler-0.
|
34
|
-
betterproto2_compiler-0.
|
35
|
-
betterproto2_compiler-0.5.0.dist-info/RECORD,,
|
30
|
+
betterproto2_compiler/templates/template.py.j2,sha256=0Cwq8b3cW6mnMjo6vGO03fz4SoGM7GXvVh6TzGB4Nk4,5461
|
31
|
+
betterproto2_compiler-0.6.0.dist-info/METADATA,sha256=DSjcX8CLq6uxzwDY_DQYH6jnhgJc42CN-tSyuhn51sY,658
|
32
|
+
betterproto2_compiler-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
33
|
+
betterproto2_compiler-0.6.0.dist-info/entry_points.txt,sha256=MXDaz7YfiaWx8KiSzArjUPLt6eTlMRbqzE4jCjXozuI,85
|
34
|
+
betterproto2_compiler-0.6.0.dist-info/RECORD,,
|
@@ -1,22 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2023 Daniel G. Taylor
|
4
|
-
Copyright (c) 2024 The betterproto contributors
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
8
|
-
in the Software without restriction, including without limitation the rights
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
11
|
-
furnished to do so, subject to the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
14
|
-
copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
-
SOFTWARE.
|
@@ -1,36 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.3
|
2
|
-
Name: betterproto2_compiler
|
3
|
-
Version: 0.5.0
|
4
|
-
Summary: Compiler for betterproto2
|
5
|
-
License: MIT
|
6
|
-
Keywords: protobuf,gRPC,compiler
|
7
|
-
Author: Adrien Vannson
|
8
|
-
Author-email: adrien.vannson@protonmail.com
|
9
|
-
Requires-Python: >=3.10,<4.0
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
16
|
-
Requires-Dist: betterproto2[grpclib] (>=0.5.0,<0.6.0)
|
17
|
-
Requires-Dist: jinja2 (>=3.0.3)
|
18
|
-
Requires-Dist: ruff (>=0.9.3,<0.10.0)
|
19
|
-
Requires-Dist: strenum (>=0.4.15,<0.5.0) ; python_version == "3.10"
|
20
|
-
Requires-Dist: typing-extensions (>=4.7.1,<5.0.0)
|
21
|
-
Project-URL: Documentation, https://betterproto.github.io/python-betterproto2-compiler/
|
22
|
-
Project-URL: Repository, https://github.com/betterproto/python-betterproto2-compiler
|
23
|
-
Description-Content-Type: text/markdown
|
24
|
-
|
25
|
-
# Betterproto2 compiler
|
26
|
-
|
27
|
-

|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
## License
|
32
|
-
|
33
|
-
Copyright © 2019 Daniel G. Taylor
|
34
|
-
|
35
|
-
Copyright © 2024 The betterproto contributors
|
36
|
-
|