diff --git a/.gitignore b/.gitignore index 239dfb6..7ddd7f5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,8 @@ __pycache__/ venv/ # python protobuf -pykos/kos/ -!pykos/kos/__init__.py +pykos/kos_protos/ +!pykos/kos_protos/__init__.py # Rust target/ diff --git a/MANIFEST.in b/MANIFEST.in index 2ede204..b3c6553 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/pykos/Makefile b/pykos/Makefile index b4178b2..f47ff64 100644 --- a/pykos/Makefile +++ b/pykos/Makefile @@ -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 @@ -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) diff --git a/pykos/kos/__init__.py b/pykos/kos/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pykos/pykos/requirements.txt b/pykos/pykos/requirements.txt index f3771d1..affb6fb 100644 --- a/pykos/pykos/requirements.txt +++ b/pykos/pykos/requirements.txt @@ -1,3 +1,3 @@ grpcio -protobuf==5.27.2 +protobuf==5.28.2 googleapis-common-protos diff --git a/pykos/setup.py b/pykos/setup.py index e43bf66..23729f1 100644 --- a/pykos/setup.py +++ b/pykos/setup.py @@ -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() @@ -35,11 +67,11 @@ 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={ @@ -47,4 +79,9 @@ "pykos=pykos.cli:cli", ], }, + setup_requires=["grpcio-tools"], + cmdclass={ + 'build_py': BuildPyCommand, + 'egg_info': EggInfoCommand, + }, )