Skip to content

Commit

Permalink
Version 5.2.0 - Protobuf Struct Update
Browse files Browse the repository at this point in the history
### Added

- Support for the `google.protobuf.Struct` message
  • Loading branch information
CCP-Zeulix committed Sep 23, 2024
1 parent 92dd3b0 commit 83dab4a
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.2.0] - 2024-09-23

### Added

- Support for the `google.protobuf.Struct` message


## [5.1.2] - 2024-07-02

### Fixed
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

Builds Neobuf Packages from Protobuf files using Protoplasm! :D

## Super Important Info

Neobuilder releases are NOT guaranteed to be backwards compatible with older
versions of Protoplasm and trying to run Neobuilder built code in a Protoplasm
release who's major and/or minor versions lag behind will more often than not
just break.

A difference in the patch version should most often be fine, as should using a
Protoplasm release that's one or more minor versions ahead of the Neobuilder
used to build code.

## Versioning

The versioning of Neobuilder and Protoplasm (major and minor versions) go hand
in hand; i.e. when Protoplasm's major of minor versions bump, a new NeoBuilder
should also be released with the same major and minor version, even if there's
no actual code change needed in NeoBuilder to support whatever changed in
Protoplasm.

Note that in order to simplify and ease this synchronous development, release
and versioning, the NeoBuilder package for the latest Protoplasm should
generally NOT be dependent on any new features added to that package, so that
the NeoBuilder package can be built and released FIRST and it can build code for
its corresponding Protoplasm version, withing having that latest version
actually installed.

This is done in order to not create a circular dependency on features between
the two but instead have NeoBuilder only depend on the previous version of
Protoplasm, especially for its pre-release unit-tests, and instead allow
Protoplasm to fully depend on the latest NeoBuilder for its unit-tests.

## Useful info

Installing this package creates a command line executable called `neobuild` (or
Expand Down
2 changes: 1 addition & 1 deletion _sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#)
n = NeoBuilder(
package='sandbox',
protopath=r'D:\Code\github\ccpgames\neobuilder\tests\res\proto',
protopath=r'D:\Code\github\ccpgames\neobuilder\tests\res2\proto',
build_root='./_sandbox/build/',
verbose=True,
)
Expand Down
6 changes: 5 additions & 1 deletion neobuilder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__version__ = '5.1.2'
__version__ = '5.2.0-rc.1'

__author__ = 'Thordur Matthiasson <[email protected]>'
__license__ = 'MIT License'
__copyright__ = 'Copyright 2019-2024 - CCP Games ehf'
3 changes: 3 additions & 0 deletions neobuilder/descwrap/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FieldKind(enum.IntFlag):
SPECIAL_DURATION = 0x0800
SPECIAL_ANY = 0x1000
SPECIAL_EMPTY = 0x2000
SPECIAL_STRUCT = 0x4000

SPECIAL_KEYWORD = 0x10000000

Expand Down Expand Up @@ -124,6 +125,8 @@ def _check_field_kind(self):
self.kind |= FieldKind.SPECIAL_ANY
elif self.value_msg.full_name == 'google.protobuf.Empty':
self.kind |= FieldKind.SPECIAL_EMPTY
elif self.value_msg.full_name == 'google.protobuf.Struct':
self.kind |= FieldKind.SPECIAL_STRUCT
else:
self.kind |= FieldKind.DATA_MESSAGE
elif self.value_field.type == ProtoType.ENUM: # Enum
Expand Down
17 changes: 14 additions & 3 deletions neobuilder/generators/symbols/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ def render_arg_py(self, used_in_file: json_format.descriptor.FileDescriptor = No
return f'{self.py_name()}: {self.get_type_hint(used_in_file)} = None'

def get_field_options(self):
if self.is_map():
if self.is_struct():
return f"default_factory=dict, metadata={{{self.get_metadata()}}}"
elif self.is_map():
return f"default_factory=dict, metadata={{{self.get_metadata()}}}"
elif self.is_list():
return f"default_factory=list, metadata={{{self.get_metadata()}}}"
Expand Down Expand Up @@ -277,7 +279,9 @@ def get_py_type_name(self, used_in_file: json_format.descriptor.FileDescriptor =
return self.field_descriptor.py_type.name

def get_type_hint(self, used_in_file: json_format.descriptor.FileDescriptor = None) -> str:
if self.is_map():
if self.is_struct():
return f'Dict[str, Any]'
elif self.is_map():
return f'Dict[{self.field_descriptor.key_py_type.name}, {self.get_py_type_name(used_in_file)}]'
elif self.is_list():
return f'List[{self.get_py_type_name(used_in_file)}]'
Expand All @@ -300,7 +304,9 @@ def get_metadata(self):
elif self.is_list():
buf.append("'is_list': True")

if self.is_message():
if self.is_struct():
buf.append("'is_struct': True")
elif self.is_message():
buf.append("'is_obj': True")
elif self.is_enum():
buf.append("'is_enum': True")
Expand All @@ -325,6 +331,8 @@ def get_dictator_name(self):
return 'EnumDictator'
if self.is_long():
return 'LongDictator'
if self.is_struct():
return 'StructDictator'
return 'BaseDictator'

def is_long(self):
Expand All @@ -333,6 +341,9 @@ def is_long(self):
def is_timestamp(self):
return bool(self.field_descriptor.kind & FieldKind.SPECIAL_TIMESTAMP)

def is_struct(self):
return bool(self.field_descriptor.kind & FieldKind.SPECIAL_STRUCT)

def is_duration(self):
return bool(self.field_descriptor.kind & FieldKind.SPECIAL_DURATION)

Expand Down
2 changes: 2 additions & 0 deletions tests/res/expected/sandbox/__everything__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import sandbox.test.delta_pb2
import sandbox.test.enums_dc
import sandbox.test.enums_pb2
import sandbox.test.googlestruct_dc
import sandbox.test.googlestruct_pb2
import sandbox.test.illnamedfields_dc
import sandbox.test.illnamedfields_pb2
import sandbox.test.illnamedservice_api
Expand Down
26 changes: 26 additions & 0 deletions tests/res/expected/sandbox/test/googlestruct_dc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# md5: 7b314132a19d0dc0845666a4261161ed
# Auto-Generated file - DO NOT EDIT!
# Source module: sandbox.test.googlestruct_pb2
# Generated at: 2024-09-19T12:21:16.292717
from __future__ import annotations
__all__ = [
'StructMessage',
]
import dataclasses
import datetime
import enum
from typing import *
from protoplasm.casting import dictators
from protoplasm import plasm

from sandbox.test import googlestruct_pb2 as pb2

import logging
log = logging.getLogger(__name__)


@dataclasses.dataclass
class StructMessage(plasm.DataclassBase):
__proto_cls__ = pb2.StructMessage
my_struct: Dict[str, Any] = dataclasses.field(default_factory=dict, metadata={'dictator': dictators.StructDictator, 'is_struct': True})

27 changes: 27 additions & 0 deletions tests/res/expected/sandbox/test/googlestruct_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/res/proto/sandbox/test/googlestruct.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package sandbox.test;

import "google/protobuf/struct.proto";


message StructMessage {
google.protobuf.Struct my_struct = 1;
}
10 changes: 10 additions & 0 deletions tests/res2/proto/sandbox/test/googlestruct.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package sandbox.test;

import "google/protobuf/struct.proto";


message StructMessage {
google.protobuf.Struct my_struct = 1;
}
2 changes: 1 addition & 1 deletion tests/test_neobuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
BUILD_ROOT = os.path.join(HERE, 'res', 'build')
EXPECTED_ROOT = os.path.join(HERE, 'res', 'expected')

EXPECTED_NUMBER_OF_FILES_CHECKED = 38
EXPECTED_NUMBER_OF_FILES_CHECKED = 39

from neobuilder import __version__ as neobuilder_version
from protoplasm import __version__ as protoplasm_version
Expand Down

0 comments on commit 83dab4a

Please sign in to comment.