Skip to content

Commit

Permalink
Merge pull request #11 from kscalelabs/python-protos
Browse files Browse the repository at this point in the history
Build and package protos on python install
  • Loading branch information
WT-MM authored Nov 24, 2024
2 parents 934e21c + b55b2dd commit a7f5d29
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ __pycache__/
venv/

# python protobuf
pykos/kos/
!pykos/kos/__init__.py
pykos/kos_protos/
!pykos/kos_protos/__init__.py

# Rust
target/
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include kos/ *.py *.txt py.typed MANIFEST.in py.typed
recursive-include kos_protos/ *.py *.txt py.typed MANIFEST.in py.typed Makefile
7 changes: 6 additions & 1 deletion pykos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ all:
# ------------------------ #

generate-proto:
rm -rf kos_protos
python -m grpc_tools.protoc \
--python_out=. \
--grpc_python_out=. \
--proto_path=../kos_core/proto/ \
--proto_path=../kos_core/proto/googleapis \
../kos_core/proto/kos/*.proto
mkdir -p kos_protos
mv kos/* kos_protos/
rm -rf kos
touch kos_protos/__init__.py
.PHONY: generate-proto


Expand Down Expand Up @@ -62,7 +67,7 @@ push-to-pypi: build-for-pypi
# Static Checks #
# ------------------------ #

py-files := $(shell find . -name '*.py' -not -path './kos/*' -not -path './pykos/kos/*')
py-files := $(shell find . -name '*.py' -not -path './kos_protos/*' -not -path './pykos/kos_protos/*')

format:
@black $(py-files)
Expand Down
Empty file removed pykos/kos/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion pykos/pykos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.1.1"
__version__ = "0.1.2"

from pykos.client import KOS
2 changes: 1 addition & 1 deletion pykos/pykos/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
grpcio
protobuf==5.27.2
protobuf==5.28.2
googleapis-common-protos
1 change: 0 additions & 1 deletion pykos/pykos/services/actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import grpc
from google.longrunning import operations_pb2, operations_pb2_grpc
from google.protobuf.any_pb2 import Any as AnyPb2

from kos import actuator_pb2, actuator_pb2_grpc, common_pb2
from kos.actuator_pb2 import CalibrateActuatorMetadata

Expand Down
1 change: 0 additions & 1 deletion pykos/pykos/services/imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import grpc
from google.protobuf.empty_pb2 import Empty

from kos import imu_pb2, imu_pb2_grpc


Expand Down
1 change: 0 additions & 1 deletion pykos/pykos/services/process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import grpc
from google.protobuf.empty_pb2 import Empty

from kos import process_manager_pb2_grpc
from kos.common_pb2 import Error
from kos.process_manager_pb2 import KClipStartRequest
Expand Down
41 changes: 39 additions & 2 deletions pykos/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,42 @@
#!/usr/bin/env python
"""Setup script for the project."""

import os
import re
import subprocess
from typing import List

from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.egg_info import egg_info


class GenerateProtosMixin:
"""Mixin class to generate protos."""

def generate_protos(self) -> None:
"""Generate proto files if Makefile exists."""
if os.path.exists("Makefile"):
subprocess.check_call(["make", "generate-proto"])


class BuildPyCommand(build_py, GenerateProtosMixin):
"""Custom build command to generate protos before building."""

def run(self) -> None:
"""Run the build command."""
self.generate_protos()
super().run()


class EggInfoCommand(egg_info, GenerateProtosMixin):
"""Custom egg_info command to generate protos before creating egg-info."""

def run(self) -> None:
"""Run the egg_info command."""
self.generate_protos()
super().run()


with open("README.md", "r", encoding="utf-8") as f:
long_description: str = f.read()
Expand Down Expand Up @@ -35,16 +67,21 @@
long_description_content_type="text/markdown",
python_requires=">=3.8",
install_requires=requirements,
tests_require=requirements_dev,
extras_require={"dev": requirements_dev},
packages=["pykos", "kos"],
packages=["pykos", "kos_protos"],
package_data={
"pykos": ["py.typed"],
"kos_protos": ["py.typed"],
},
include_package_data=True,
entry_points={
"console_scripts": [
"pykos=pykos.cli:cli",
],
},
setup_requires=["grpcio-tools"],
cmdclass={
"build_py": BuildPyCommand,
"egg_info": EggInfoCommand,
},
)

0 comments on commit a7f5d29

Please sign in to comment.