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

Generate 'betterproto' classes for better experience in Python. #21

Closed
wants to merge 2 commits into from
Closed
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 @@ -4,4 +4,5 @@ build/
dist/
python/pkg/drift_protocol.egg-info/
python/pkg/drift_protocol
python/pkg/drift
!python/pkg/drift_protocol/__init__.py.in
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ repos:
name: black
entry: black
language: python
language_version: python3.8
args:
- .
- --check
Empty file added python/pkg/drift/.gitempty
Empty file.
12 changes: 12 additions & 0 deletions python/python_tools/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def generate_proto(self, source: str, create_package=True) -> str:
str(source),
]

print(protoc_command)
if subprocess.call(protoc_command, cwd=PROTO_SPEC_FOLDER) != 0:
sys.exit(-1)

print(f"Generating Better Proto {output_path}...")
protoc_command = [
self.protoc,
"-I.",
f"--python_betterproto_out={self.output_dir}",
str(source),
]

print(protoc_command)
if subprocess.call(protoc_command, cwd=PROTO_SPEC_FOLDER) != 0:
sys.exit(-1)
Expand Down
8 changes: 7 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def update_package_version(path: Path, version: str, protoc_version: str):
with open(path / "__init__.py", "w") as f:
f.write(init_content)

with open(path.parent / "drift" / "__init__.py", "w") as f:
f.write(init_content)


def build_version():
"""Build dynamic version and update version in package"""
Expand Down Expand Up @@ -144,5 +147,8 @@ def packages(self):
package_dir={"": "pkg"},
packages=LazyPackageFinder(finder=partial(find_packages, where="pkg")),
python_requires=">=3.7",
install_requires=[f"protobuf>={PROTOBUF_VERSION}, <=3.20.3"],
install_requires=[
f"protobuf>={PROTOBUF_VERSION}, <=3.20.3",
"betterproto[compiler]>=2.0.0b6",
],
)
18 changes: 18 additions & 0 deletions python/tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pkgutil
import drift_protocol
import drift.proto


def test_version():
Expand All @@ -20,10 +21,27 @@ def test_modules():
assert modules


def test_betterproto_modules():
"""Test tha package has modules"""
package_path = os.path.dirname(drift.proto.__file__)
modules = [name for _, name, _ in pkgutil.iter_modules([package_path])]

assert modules


def test_import():
"""Test if no errors during the import"""
from drift_protocol.common import (
DriftPackage,
)

assert DriftPackage()


def test_betterproto_import():
"""Test if no errors during the import"""
from drift.proto.common import (
DriftPackage,
)

assert DriftPackage() is not None
Loading