Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated proto pb_plugin #347

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.egg-info/
*__pycache__/
*.pyc
.idea/
pb_plugins/generated/
build/
dist/
2 changes: 1 addition & 1 deletion pb_plugins/protoc_gen_mavsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
""" Autogenerator for MAVSDK """


from .autogen import AutoGen
from protoc_gen_mavsdk.autogen import AutoGen
2 changes: 1 addition & 1 deletion pb_plugins/protoc_gen_mavsdk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys
from google.protobuf.compiler import plugin_pb2
from . import AutoGen
from protoc_gen_mavsdk.autogen import AutoGen


def main():
Expand Down
23 changes: 11 additions & 12 deletions pb_plugins/protoc_gen_mavsdk/autogen.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
from os import environ
from google.protobuf.compiler import plugin_pb2
from .autogen_file import File
from .docs import Docs
from .enum import Enum
from .methods import Method
from .struct import Struct
from .utils import (get_template_env,
has_result,
is_server,
name_parser_factory,
type_info_factory)

import protoc_gen_mavsdk.mavsdk_options_pb2
from protoc_gen_mavsdk.autogen_file import File
from protoc_gen_mavsdk.docs import Docs
from protoc_gen_mavsdk.pb_enum import Enum
from protoc_gen_mavsdk.methods import Method
from protoc_gen_mavsdk.pb_struct import Struct
from protoc_gen_mavsdk.utils import (get_template_env,
has_result,
is_server,
name_parser_factory,
type_info_factory)


class AutoGen(object):
""" Autogenerator for the MAVSDK bindings """
Expand Down
2 changes: 1 addition & 1 deletion pb_plugins/protoc_gen_mavsdk/autogen_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from .utils import name_parser_factory
from protoc_gen_mavsdk.utils import name_parser_factory


class File(object):
Expand Down
4 changes: 1 addition & 3 deletions pb_plugins/protoc_gen_mavsdk/docs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-


class Docs():
class Docs:
"""
Docs

Expand Down
111 changes: 54 additions & 57 deletions pb_plugins/protoc_gen_mavsdk/mavsdk_options_pb2.py

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

14 changes: 7 additions & 7 deletions pb_plugins/protoc_gen_mavsdk/methods.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from .utils import (filter_out_result,
is_stream,
name_parser_factory,
no_return,
Param,
remove_subscribe,
type_info_factory)
from protoc_gen_mavsdk.utils import (filter_out_result,
is_stream,
name_parser_factory,
no_return,
Param,
remove_subscribe,
type_info_factory)


class Method(object):
Expand Down
1 change: 0 additions & 1 deletion pb_plugins/protoc_gen_mavsdk/name_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import re

from os import environ

class NameParserFactory:
_initialisms = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from .utils import name_parser_factory
from protoc_gen_mavsdk.utils import name_parser_factory


class Enum(object):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-


from .enum import Enum
from .utils import (is_request,
is_response,
is_struct,
name_parser_factory,
Param,
type_info_factory)
from jinja2.exceptions import TemplateNotFound
from protoc_gen_mavsdk.pb_enum import Enum
from protoc_gen_mavsdk.utils import (is_request,
is_response,
is_struct,
name_parser_factory,
Param,
type_info_factory)


class Struct(object):
Expand Down
4 changes: 2 additions & 2 deletions pb_plugins/protoc_gen_mavsdk/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from jinja2 import Environment, FileSystemLoader
from .name_parser import NameParserFactory
from .type_info import TypeInfoFactory
from protoc_gen_mavsdk.name_parser import NameParserFactory
from protoc_gen_mavsdk.type_info import TypeInfoFactory


name_parser_factory = NameParserFactory()
Expand Down
4 changes: 2 additions & 2 deletions pb_plugins/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
protobuf>=3.13,<=3.20.1
jinja2>=2.11
protobuf>=5.27.1
jinja2>=3.1.4
6 changes: 2 additions & 4 deletions pb_plugins/setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os
import subprocess
import sys

from distutils.command.build import build
from distutils.spawn import find_executable
from setuptools import setup


def parse_requirements(filename):
"""
Helper which parses requirement_?.*.txt files
Expand All @@ -26,6 +23,7 @@ def parse_requirements(filename):
with open(filepath, encoding="utf-8") as f:
return [requires.strip() for requires in f.readlines()]


setup(
name="protoc-gen-mavsdk",
version="1.1.1",
Expand Down
8 changes: 4 additions & 4 deletions pb_plugins/test/test_name_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from protoc_gen_mavsdk.name_parser import (NameParser, NameParserFactory)
from unittest.mock import patch, mock_open

class TestNameParser(unittest.TestCase):

class TestNameParser(unittest.TestCase):
_initialisms_data = """ ["HTTP", "HTTPS", "URL", "ID"] """

def setUp(self):
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_no_initialisms_when_no_initialims_file(self, mock_file):
@patch("builtins.open", new_callable=mock_open, read_data=_initialisms_data)
def test_initalism_is_capitalized_when_camel_case(self, mock_file):
name_parser_factory = NameParserFactory()
name_parser_factory.set_template_path("random/path")
name_parser_factory.set_initialisms_path("random/path")
name = name_parser_factory.create("fileUrl")

self.assertEqual("FileURL", name.upper_camel_case)
Expand All @@ -173,15 +173,15 @@ def test_initalism_is_capitalized_when_camel_case(self, mock_file):
@patch("builtins.open", new_callable=mock_open, read_data=_initialisms_data)
def test_initalism_is_capitalized_when_upper_snake_case(self, mock_file):
name_parser_factory = NameParserFactory()
name_parser_factory.set_template_path("random/path")
name_parser_factory.set_initialisms_path("random/path")
name = name_parser_factory.create("fileUrl")

self.assertEqual("File_URL", name.upper_snake_case)

@patch("builtins.open", new_callable=mock_open, read_data=_initialisms_data)
def test_initalism_is_not_capitalized_when_lower_snake_case(self, mock_file):
name_parser_factory = NameParserFactory()
name_parser_factory.set_template_path("random/path")
name_parser_factory.set_initialisms_path("random/path")
name = name_parser_factory.create("fileUrl")

self.assertEqual("file_url", name.lower_snake_case)
Expand Down
Loading
Loading