betterproto2-compiler 0.5.0__tar.gz → 0.6.0__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.
- betterproto2_compiler-0.6.0/.gitignore +21 -0
- betterproto2_compiler-0.6.0/PKG-INFO +15 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/pyproject.toml +41 -43
- betterproto2_compiler-0.6.0/pytest.ini +5 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/known_types/any.py +1 -1
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/lib/google/protobuf/__init__.py +1 -1
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/lib/google/protobuf/compiler/__init__.py +1 -1
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/compiler.py +14 -4
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/main.py +1 -2
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/models.py +35 -2
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/templates/header.py.j2 +3 -9
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/templates/service_stub.py.j2 +1 -1
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/templates/template.py.j2 +3 -3
- betterproto2_compiler-0.6.0/tests/__init__.py +0 -0
- betterproto2_compiler-0.6.0/tests/generate.py +143 -0
- betterproto2_compiler-0.6.0/tests/inputs/any/any.proto +8 -0
- betterproto2_compiler-0.6.0/tests/inputs/bool/bool.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/bytes/bytes.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/casing/casing.proto +20 -0
- betterproto2_compiler-0.6.0/tests/inputs/casing_inner_class/casing_inner_class.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/deprecated/deprecated.proto +21 -0
- betterproto2_compiler-0.6.0/tests/inputs/documentation/documentation.proto +62 -0
- betterproto2_compiler-0.6.0/tests/inputs/double/double.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/empty_repeated/empty_repeated.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/empty_service/empty_service.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/encoding_decoding/encoding_decoding.proto +15 -0
- betterproto2_compiler-0.6.0/tests/inputs/entry/entry.proto +20 -0
- betterproto2_compiler-0.6.0/tests/inputs/enum/enum.proto +25 -0
- betterproto2_compiler-0.6.0/tests/inputs/example/example.proto +911 -0
- betterproto2_compiler-0.6.0/tests/inputs/example_service/example_service.proto +20 -0
- betterproto2_compiler-0.6.0/tests/inputs/features/features.proto +107 -0
- betterproto2_compiler-0.6.0/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto +13 -0
- betterproto2_compiler-0.6.0/tests/inputs/fixed/fixed.proto +10 -0
- betterproto2_compiler-0.6.0/tests/inputs/float/float.proto +14 -0
- betterproto2_compiler-0.6.0/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto +22 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes/googletypes.proto +16 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_request/googletypes_request.proto +29 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_response/googletypes_response.proto +23 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto +26 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto +13 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto +18 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_struct/googletypes_struct.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/googletypes_value/googletypes_value.proto +15 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_capitalized_package/capitalized.proto +8 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_capitalized_package/test.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_package_from_package/child.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_package_from_package/package_message.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_package_from_root/child.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_scoping_rules/child.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_scoping_rules/import_child_scoping_rules.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_child_scoping_rules/package.proto +13 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_circular_dependency/import_circular_dependency.proto +30 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_circular_dependency/other.proto +8 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_circular_dependency/root.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_cousin_package/cousin.proto +6 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_cousin_package/test.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_cousin_package_same_name/cousin.proto +6 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_cousin_package_same_name/test.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_nested_child_package_from_root/child.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_nested_child_package_from_root/import_nested_child_package_from_root.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_packages_same_name/import_packages_same_name.proto +13 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_packages_same_name/posts_v1.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_packages_same_name/users_v1.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto +12 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_parent_package_from_child/parent_package_message.proto +6 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_root_package_from_child/child.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_root_package_from_child/root.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_root_sibling/import_root_sibling.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_root_sibling/sibling.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_service_input_message/child_package_request_message.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_service_input_message/import_service_input_message.proto +25 -0
- betterproto2_compiler-0.6.0/tests/inputs/import_service_input_message/request_message.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/int32/int32.proto +10 -0
- betterproto2_compiler-0.6.0/tests/inputs/invalid_field/invalid_field.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/manual_validation/manual_validation.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/map/map.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/mapmessage/mapmessage.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/message_wrapping/message_wrapping.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto +40 -0
- betterproto2_compiler-0.6.0/tests/inputs/namespace_keywords/namespace_keywords.proto +46 -0
- betterproto2_compiler-0.6.0/tests/inputs/nested/nested.proto +26 -0
- betterproto2_compiler-0.6.0/tests/inputs/nested2/nested2.proto +21 -0
- betterproto2_compiler-0.6.0/tests/inputs/nested2/package.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/nestedtwice/nestedtwice.proto +40 -0
- betterproto2_compiler-0.6.0/tests/inputs/oneof/oneof.proto +23 -0
- betterproto2_compiler-0.6.0/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto +30 -0
- betterproto2_compiler-0.6.0/tests/inputs/oneof_empty/oneof_empty.proto +17 -0
- betterproto2_compiler-0.6.0/tests/inputs/oneof_enum/oneof_enum.proto +20 -0
- betterproto2_compiler-0.6.0/tests/inputs/pickling/pickling.proto +43 -0
- betterproto2_compiler-0.6.0/tests/inputs/proto3_field_presence/proto3_field_presence.proto +26 -0
- betterproto2_compiler-0.6.0/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto +22 -0
- betterproto2_compiler-0.6.0/tests/inputs/recursivemessage/recursivemessage.proto +15 -0
- betterproto2_compiler-0.6.0/tests/inputs/ref/ref.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/ref/repeatedmessage.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/regression_387/regression_387.proto +12 -0
- betterproto2_compiler-0.6.0/tests/inputs/regression_414/regression_414.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/repeated/repeated.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto +12 -0
- betterproto2_compiler-0.6.0/tests/inputs/repeatedmessage/repeatedmessage.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/repeatedpacked/repeatedpacked.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/rpc_empty_input_message/rpc_empty_input_message.proto +13 -0
- betterproto2_compiler-0.6.0/tests/inputs/service/service.proto +35 -0
- betterproto2_compiler-0.6.0/tests/inputs/service_separate_packages/messages.proto +31 -0
- betterproto2_compiler-0.6.0/tests/inputs/service_separate_packages/service.proto +12 -0
- betterproto2_compiler-0.6.0/tests/inputs/service_uppercase/service.proto +16 -0
- betterproto2_compiler-0.6.0/tests/inputs/signed/signed.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/simple_service/simple_service.proto +21 -0
- betterproto2_compiler-0.6.0/tests/inputs/stream_stream/stream_stream.proto +7 -0
- betterproto2_compiler-0.6.0/tests/inputs/timestamp_dict_encode/timestamp_dict_encode.proto +9 -0
- betterproto2_compiler-0.6.0/tests/inputs/unwrap/unwrap.proto +11 -0
- betterproto2_compiler-0.6.0/tests/inputs/validation/validation.proto +20 -0
- betterproto2_compiler-0.6.0/tests/test_casing.py +32 -0
- betterproto2_compiler-0.6.0/tests/test_module_validation.py +105 -0
- betterproto2_compiler-0.6.0/tests/util.py +47 -0
- betterproto2_compiler-0.6.0/uv.lock +1246 -0
- betterproto2_compiler-0.5.0/LICENSE.md +0 -22
- betterproto2_compiler-0.5.0/PKG-INFO +0 -36
- betterproto2_compiler-0.5.0/README.md +0 -11
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/casing.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/compile/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/compile/importing.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/compile/naming.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/known_types/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/known_types/duration.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/known_types/google_values.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/known_types/timestamp.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/lib/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/lib/google/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/lib/message_pool.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/__init__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/__main__.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/module_validation.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/parser.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/plugin/plugin.bat +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/py.typed +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/settings.py +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/templates/service_stub_async.py.j2 +0 -0
- {betterproto2_compiler-0.5.0 → betterproto2_compiler-0.6.0}/src/betterproto2_compiler/templates/service_stub_sync.py.j2 +0 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
.coverage
|
2
|
+
.DS_Store
|
3
|
+
.env
|
4
|
+
.vscode/settings.json
|
5
|
+
.mypy_cache
|
6
|
+
.pytest_cache
|
7
|
+
.python-version
|
8
|
+
build/
|
9
|
+
tests/output_*
|
10
|
+
**/__pycache__
|
11
|
+
dist
|
12
|
+
**/*.egg-info
|
13
|
+
output
|
14
|
+
.idea
|
15
|
+
.DS_Store
|
16
|
+
.tox
|
17
|
+
.venv
|
18
|
+
.asv
|
19
|
+
venv
|
20
|
+
.devcontainer
|
21
|
+
.ruff_cache
|
@@ -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,54 +1,63 @@
|
|
1
1
|
[project]
|
2
2
|
name = "betterproto2_compiler"
|
3
|
-
version = "0.
|
3
|
+
version = "0.6.0"
|
4
4
|
description = "Compiler for betterproto2"
|
5
5
|
authors = [
|
6
6
|
{ name = "Adrien Vannson", email = "adrien.vannson@protonmail.com" },
|
7
7
|
{ name = "Daniel G. Taylor", email = "danielgtaylor@gmail.com" },
|
8
8
|
]
|
9
|
-
readme = "README.md"
|
10
|
-
keywords = ["protobuf", "gRPC", "compiler"]
|
11
9
|
license = "MIT"
|
10
|
+
keywords = [
|
11
|
+
"protobuf",
|
12
|
+
"gRPC",
|
13
|
+
"compiler",
|
14
|
+
]
|
12
15
|
requires-python = ">=3.10,<4.0"
|
13
|
-
|
16
|
+
dependencies = [
|
17
|
+
# TODO use the version from the current repo?
|
18
|
+
"betterproto2[grpclib]>=0.6.0,<0.7",
|
19
|
+
"ruff~=0.9.3",
|
20
|
+
"jinja2>=3.0.3",
|
21
|
+
"typing-extensions>=4.7.1,<5",
|
22
|
+
"strenum>=0.4.15,<0.5 ; python_version == '3.10'",
|
23
|
+
]
|
14
24
|
|
15
25
|
[project.urls]
|
16
|
-
Documentation = "https://betterproto.github.io/python-betterproto2
|
17
|
-
Repository = "https://github.com/betterproto/python-betterproto2
|
26
|
+
Documentation = "https://betterproto.github.io/python-betterproto2/"
|
27
|
+
Repository = "https://github.com/betterproto/python-betterproto2"
|
18
28
|
|
19
29
|
[project.scripts]
|
20
30
|
protoc-gen-python_betterproto2 = "betterproto2_compiler.plugin:main"
|
21
31
|
|
22
|
-
[
|
23
|
-
|
24
|
-
|
32
|
+
[dependency-groups]
|
33
|
+
dev = [
|
34
|
+
"pre-commit>=2.17.0,<3",
|
35
|
+
"grpcio-tools>=1.54.2,<2",
|
36
|
+
"poethepoet>=0.32.2,<0.33",
|
37
|
+
"pyright>=1.1.391,<2",
|
38
|
+
"ipykernel>=6.29.5,<7",
|
25
39
|
]
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
betterproto2 = { version = "^0.5.0", extras = ["grpclib"] }
|
30
|
-
# betterproto2 = { git="https://github.com/betterproto/python-betterproto2" }
|
31
|
-
# betterproto2 = { path = "../python-betterproto2", extras = ["grpclib"] }
|
32
|
-
# The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml
|
33
|
-
ruff = "~0.9.3"
|
34
|
-
jinja2 = ">=3.0.3"
|
35
|
-
typing-extensions = "^4.7.1"
|
36
|
-
strenum = [
|
37
|
-
{version = "^0.4.15", python = "=3.10"},
|
40
|
+
test = [
|
41
|
+
"pytest>=8.3.4,<9",
|
42
|
+
"protobuf>=5.29.3,<6",
|
38
43
|
]
|
39
44
|
|
40
|
-
[tool.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
[tool.uv]
|
46
|
+
package = true
|
47
|
+
default-groups = "all"
|
48
|
+
|
49
|
+
# [tool.hatch.build.targets.sdist]
|
50
|
+
# include = ["src/betterproto2_compiler"]
|
51
|
+
|
52
|
+
# [tool.hatch.build.targets.wheel]
|
53
|
+
# include = ["src/betterproto2_compiler"]
|
54
|
+
|
55
|
+
# [tool.hatch.build.targets.wheel.sources]
|
56
|
+
# "src/betterproto2_compiler" = "betterproto2_compiler"
|
48
57
|
|
49
|
-
[
|
50
|
-
|
51
|
-
|
58
|
+
[build-system]
|
59
|
+
requires = ["hatchling"]
|
60
|
+
build-backend = "hatchling.build"
|
52
61
|
|
53
62
|
[tool.ruff]
|
54
63
|
extend-exclude = ["tests/output_*", "src/betterproto2_compiler/lib"]
|
@@ -71,12 +80,9 @@ select = [
|
|
71
80
|
"I",
|
72
81
|
]
|
73
82
|
|
74
|
-
|
75
83
|
[tool.ruff.lint.isort]
|
76
84
|
combine-as-imports = true
|
77
85
|
|
78
|
-
# Dev workflow tasks
|
79
|
-
|
80
86
|
[tool.poe.tasks.test]
|
81
87
|
cmd = "pytest"
|
82
88
|
help = "Run tests"
|
@@ -146,14 +152,6 @@ help = "Check that the source code is formatted"
|
|
146
152
|
cmd = "ruff check src tests"
|
147
153
|
help = "Check the code with the Ruff linter"
|
148
154
|
|
149
|
-
[tool.poe.tasks.serve-docs]
|
150
|
-
cmd = "mkdocs serve"
|
151
|
-
help = "Serve the documentation locally"
|
152
|
-
|
153
|
-
[build-system]
|
154
|
-
requires = ["poetry-core>=2.0.0,<3"]
|
155
|
-
build-backend = "poetry.core.masonry.api"
|
156
|
-
|
157
155
|
# python -m grpc.tools.protoc \
|
158
156
|
# --python_betterproto2_out=src/lib2 \
|
159
157
|
# google/protobuf/any.proto \
|
@@ -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) }}
|
File without changes
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import asyncio
|
3
|
+
import os
|
4
|
+
import shutil
|
5
|
+
import sys
|
6
|
+
from pathlib import Path
|
7
|
+
|
8
|
+
from tests.util import (
|
9
|
+
get_directories,
|
10
|
+
inputs_path,
|
11
|
+
output_path_betterproto,
|
12
|
+
output_path_betterproto_pydantic,
|
13
|
+
output_path_reference,
|
14
|
+
protoc,
|
15
|
+
)
|
16
|
+
|
17
|
+
# Force pure-python implementation instead of C++, otherwise imports
|
18
|
+
# break things because we can't properly reset the symbol database.
|
19
|
+
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
20
|
+
|
21
|
+
|
22
|
+
def clear_directory(dir_path: Path):
|
23
|
+
for file_or_directory in dir_path.glob("*"):
|
24
|
+
if file_or_directory.is_dir():
|
25
|
+
shutil.rmtree(file_or_directory)
|
26
|
+
else:
|
27
|
+
file_or_directory.unlink()
|
28
|
+
|
29
|
+
|
30
|
+
async def generate(verbose: bool):
|
31
|
+
test_case_names = set(get_directories(inputs_path)) - {"__pycache__"}
|
32
|
+
|
33
|
+
generation_tasks = []
|
34
|
+
for test_case_name in sorted(test_case_names):
|
35
|
+
test_case_input_path = inputs_path.joinpath(test_case_name).resolve()
|
36
|
+
generation_tasks.append(generate_test_case_output(test_case_input_path, test_case_name, verbose))
|
37
|
+
|
38
|
+
failed_test_cases = []
|
39
|
+
# Wait for all subprocs and match any failures to names to report
|
40
|
+
for test_case_name, result in zip(sorted(test_case_names), await asyncio.gather(*generation_tasks)):
|
41
|
+
if result != 0:
|
42
|
+
failed_test_cases.append(test_case_name)
|
43
|
+
|
44
|
+
if len(failed_test_cases) > 0:
|
45
|
+
sys.stderr.write("\n\033[31;1;4mFailed to generate the following test cases:\033[0m\n")
|
46
|
+
for failed_test_case in failed_test_cases:
|
47
|
+
sys.stderr.write(f"- {failed_test_case}\n")
|
48
|
+
|
49
|
+
sys.exit(1)
|
50
|
+
|
51
|
+
|
52
|
+
async def generate_test_case_output(test_case_input_path: Path, test_case_name: str, verbose: bool) -> int:
|
53
|
+
"""
|
54
|
+
Returns the max of the subprocess return values
|
55
|
+
"""
|
56
|
+
|
57
|
+
test_case_output_path_reference = output_path_reference.joinpath(test_case_name)
|
58
|
+
test_case_output_path_betterproto = output_path_betterproto
|
59
|
+
test_case_output_path_betterproto_pyd = output_path_betterproto_pydantic
|
60
|
+
|
61
|
+
os.makedirs(test_case_output_path_reference, exist_ok=True)
|
62
|
+
os.makedirs(test_case_output_path_betterproto, exist_ok=True)
|
63
|
+
os.makedirs(test_case_output_path_betterproto_pyd, exist_ok=True)
|
64
|
+
|
65
|
+
clear_directory(test_case_output_path_reference)
|
66
|
+
clear_directory(test_case_output_path_betterproto)
|
67
|
+
clear_directory(test_case_output_path_betterproto_pyd)
|
68
|
+
|
69
|
+
(
|
70
|
+
(ref_out, ref_err, ref_code),
|
71
|
+
(plg_out, plg_err, plg_code),
|
72
|
+
(plg_out_pyd, plg_err_pyd, plg_code_pyd),
|
73
|
+
) = await asyncio.gather(
|
74
|
+
protoc(test_case_input_path, test_case_output_path_reference, True),
|
75
|
+
protoc(test_case_input_path, test_case_output_path_betterproto, False),
|
76
|
+
protoc(test_case_input_path, test_case_output_path_betterproto_pyd, False, True),
|
77
|
+
)
|
78
|
+
|
79
|
+
if ref_code == 0:
|
80
|
+
print(f"\033[31;1;4mGenerated reference output for {test_case_name!r}\033[0m")
|
81
|
+
else:
|
82
|
+
print(f"\033[31;1;4mFailed to generate reference output for {test_case_name!r}\033[0m")
|
83
|
+
print(ref_err.decode())
|
84
|
+
|
85
|
+
if verbose:
|
86
|
+
if ref_out:
|
87
|
+
print("Reference stdout:")
|
88
|
+
sys.stdout.buffer.write(ref_out)
|
89
|
+
sys.stdout.buffer.flush()
|
90
|
+
|
91
|
+
if ref_err:
|
92
|
+
print("Reference stderr:")
|
93
|
+
sys.stderr.buffer.write(ref_err)
|
94
|
+
sys.stderr.buffer.flush()
|
95
|
+
|
96
|
+
if plg_code == 0:
|
97
|
+
print(f"\033[31;1;4mGenerated plugin output for {test_case_name!r}\033[0m")
|
98
|
+
else:
|
99
|
+
print(f"\033[31;1;4mFailed to generate plugin output for {test_case_name!r}\033[0m")
|
100
|
+
print(plg_err.decode())
|
101
|
+
|
102
|
+
if verbose:
|
103
|
+
if plg_out:
|
104
|
+
print("Plugin stdout:")
|
105
|
+
sys.stdout.buffer.write(plg_out)
|
106
|
+
sys.stdout.buffer.flush()
|
107
|
+
|
108
|
+
if plg_err:
|
109
|
+
print("Plugin stderr:")
|
110
|
+
sys.stderr.buffer.write(plg_err)
|
111
|
+
sys.stderr.buffer.flush()
|
112
|
+
|
113
|
+
if plg_code_pyd == 0:
|
114
|
+
print(f"\033[31;1;4mGenerated plugin (pydantic compatible) output for {test_case_name!r}\033[0m")
|
115
|
+
else:
|
116
|
+
print(f"\033[31;1;4mFailed to generate plugin (pydantic compatible) output for {test_case_name!r}\033[0m")
|
117
|
+
print(plg_err_pyd.decode())
|
118
|
+
|
119
|
+
if verbose:
|
120
|
+
if plg_out_pyd:
|
121
|
+
print("Plugin stdout:")
|
122
|
+
sys.stdout.buffer.write(plg_out_pyd)
|
123
|
+
sys.stdout.buffer.flush()
|
124
|
+
|
125
|
+
if plg_err_pyd:
|
126
|
+
print("Plugin stderr:")
|
127
|
+
sys.stderr.buffer.write(plg_err_pyd)
|
128
|
+
sys.stderr.buffer.flush()
|
129
|
+
|
130
|
+
return max(ref_code, plg_code, plg_code_pyd)
|
131
|
+
|
132
|
+
|
133
|
+
def main():
|
134
|
+
if sys.argv[1:2] == ["-v"]:
|
135
|
+
verbose = True
|
136
|
+
else:
|
137
|
+
verbose = False
|
138
|
+
|
139
|
+
asyncio.run(generate(verbose))
|
140
|
+
|
141
|
+
|
142
|
+
if __name__ == "__main__":
|
143
|
+
main()
|
@@ -0,0 +1,20 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package casing;
|
4
|
+
|
5
|
+
enum my_enum {
|
6
|
+
ZERO = 0;
|
7
|
+
ONE = 1;
|
8
|
+
TWO = 2;
|
9
|
+
}
|
10
|
+
|
11
|
+
message Test {
|
12
|
+
int32 camelCase = 1;
|
13
|
+
my_enum snake_case = 2;
|
14
|
+
snake_case_message snake_case_message = 3;
|
15
|
+
int32 UPPERCASE = 4;
|
16
|
+
}
|
17
|
+
|
18
|
+
message snake_case_message {
|
19
|
+
|
20
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
|
3
|
+
package deprecated;
|
4
|
+
|
5
|
+
// Some documentation about the Test message.
|
6
|
+
message Test {
|
7
|
+
Message message = 1 [deprecated=true];
|
8
|
+
int32 value = 2;
|
9
|
+
}
|
10
|
+
|
11
|
+
message Message {
|
12
|
+
option deprecated = true;
|
13
|
+
string value = 1;
|
14
|
+
}
|
15
|
+
|
16
|
+
message Empty {}
|
17
|
+
|
18
|
+
service TestService {
|
19
|
+
rpc func(Empty) returns (Empty);
|
20
|
+
rpc deprecated_func(Empty) returns (Empty) { option deprecated = true; };
|
21
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
syntax = "proto3";
|
2
|
+
package documentation;
|
3
|
+
|
4
|
+
// Documentation of message 1
|
5
|
+
// other line 1
|
6
|
+
|
7
|
+
// Documentation of message 2
|
8
|
+
// other line 2
|
9
|
+
message Test { // Documentation of message 3
|
10
|
+
// Documentation of field 1
|
11
|
+
// other line 1
|
12
|
+
|
13
|
+
// Documentation of field 2
|
14
|
+
// other line 2
|
15
|
+
uint32 x = 1; // Documentation of field 3
|
16
|
+
|
17
|
+
// Documentation of oneof 1
|
18
|
+
// other line 1
|
19
|
+
|
20
|
+
// Documentation of oneof 2
|
21
|
+
// other line 2
|
22
|
+
oneof oneof_example { // Documentation of oneof 3
|
23
|
+
// Documentation of oneof field 1
|
24
|
+
// other line 1
|
25
|
+
|
26
|
+
// Documentation of oneof field 2
|
27
|
+
// other line 2
|
28
|
+
int32 a = 2; // Documentation of oneof field 3
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Documentation of enum 1
|
33
|
+
// other line 1
|
34
|
+
|
35
|
+
// Documentation of enum 2
|
36
|
+
// other line 2
|
37
|
+
enum Enum { // Documentation of enum 3
|
38
|
+
// Documentation of variant 1
|
39
|
+
// other line 1
|
40
|
+
|
41
|
+
// Documentation of variant 2
|
42
|
+
// other line 2
|
43
|
+
Enum_Variant = 0; // Documentation of variant 3
|
44
|
+
}
|
45
|
+
|
46
|
+
// Documentation of service 1
|
47
|
+
// other line 1
|
48
|
+
|
49
|
+
// Documentation of service 2
|
50
|
+
// other line 2
|
51
|
+
service Service { // Documentation of service 3
|
52
|
+
// Documentation of method 1
|
53
|
+
// other line 1
|
54
|
+
|
55
|
+
// Documentation of method 2
|
56
|
+
// other line 2
|
57
|
+
rpc get(Test) returns (Test); // Documentation of method 3
|
58
|
+
}
|
59
|
+
|
60
|
+
// A comment with backslashes \ and triple quotes """
|
61
|
+
// Simple quotes are not escaped "
|
62
|
+
message ComplexDocumentation {}
|