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

Align proto package paths and python generated package paths. #13

Merged
merged 7 commits into from
Jan 30, 2025
Merged
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
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
__pycache__/
.venv/
*.py[cod]
*$py.class
.ipynb_checkpoints
keysight_chakra/tests/*.html
keysight_chakra/tests/*.yml
tests/*.html
tests/*.yml
.yml
build
dist
.pytest_cache
*.egg-info
keysight_chakra/generated
keysight_chakra/tests/generated_artifacts
keysight_chakra/infra/*pb2*
keysight_chakra/mlcommons/*pb2*
tests/generated_artifacts
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ./keysight_chakra/protos/*.proto
include ./keysight_chakra/generated/*.pyi
include ./keysight_chakra/infra/*
include ./keysight_chakra/mlcommons/*
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
MLCOMMONS_PACKAGE_DIR := ./keysight_chakra/mlcommons
INFRA_PACKAGE_DIR := ./keysight_chakra/infra

help:
@awk -F ':|##' '/^[^\t].+:.*##/ { printf "\033[36mmake %-28s\033[0m -%s\n", $$1, $$NF }' $(MAKEFILE_LIST) | sort

env: ## install env requirements
echo "installing python packages..." && \
pip install -r requirements.txt

.PHONY: clean
clean:
rm -rf build/* || true
rm -rf dist/* || true
rm -rf $(MLCOMMONS_PACKAGE_DIR)/*pb2* || true
rm -rf $(INFRA_PACKAGE_DIR)/*pb2* || true

.PHONY: build
GENERATED_DIR := ./keysight_chakra/generated
build: ## compile all .proto files and generate artifacts
curl -L -o ./keysight_chakra/protos/et_def.proto https://raw.githubusercontent.com/mlcommons/chakra/main/schema/protobuf/et_def.proto
rm -rf $(GENERATED_DIR) || true
mkdir -p $(GENERATED_DIR)
curl -L -o $(MLCOMMONS_PACKAGE_DIR)/et_def.proto https://raw.githubusercontent.com/mlcommons/chakra/main/schema/protobuf/et_def.proto
sed -i 's/ChakraProtoMsg/keysight_chakra.mlcommons/g' $(MLCOMMONS_PACKAGE_DIR)/et_def.proto
rm -rf $(MLCOMMONS_PACKAGE_DIR)/*pb2* || true
rm -rf $(INFRA_PACKAGE_DIR)/*pb2* || true
python3 -m grpc_tools.protoc \
--proto_path=./keysight_chakra/protos \
--python_out=$(GENERATED_DIR) \
--pyi_out=$(GENERATED_DIR) \
--grpc_python_out=$(GENERATED_DIR) \
et_def.proto infra.proto annotate.proto service.proto
--proto_path=./ \
--python_out=./ \
--pyi_out=./ \
--grpc_python_out=./ \
$(INFRA_PACKAGE_DIR)/infra.proto \
$(INFRA_PACKAGE_DIR)/annotate.proto \
$(INFRA_PACKAGE_DIR)/service.proto \
$(MLCOMMONS_PACKAGE_DIR)/et_def.proto
python3 -m pip uninstall -y keysight-chakra
python3 setup.py bdist_wheel
python3 -m pip install --no-cache .

.PHONY: test
test: build ## run sanity tests on the distribution
python3 -m pytest -s keysight_chakra/tests
python3 -m pytest -s tests


2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.2.0
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

syntax = "proto3";

package annotate;
package keysight_chakra.infra;

import "google/protobuf/any.proto";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";

package infra;
package keysight_chakra.infra;

import "google/protobuf/any.proto";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

syntax = "proto3";

package service;
package keysight_chakra.infra;

import "infra.proto";
import "annotate.proto";
import "keysight_chakra/infra/infra.proto";
import "keysight_chakra/infra/annotate.proto";

message ValidationRequest {
infra.Infrastructure infrastructure = 1;
repeated annotate.Annotation annotations = 2;
Infrastructure infrastructure = 1;
repeated Annotation annotations = 2;
}

message ValidationError {
Expand Down Expand Up @@ -48,4 +48,4 @@ message ValidationResponse {
service InfraService {
// Validate rpc validates both infra and annotation messages
rpc Validate(ValidationRequest) returns (ValidationResponse);
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package ChakraProtoMsg;
package keysight_chakra.mlcommons;

message AttributeProto {
string name = 1;
Expand Down
6 changes: 3 additions & 3 deletions keysight_chakra/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from typing import Annotated
from google.protobuf.message import Message
from generated.service_pb2 import ValidationRequest, ValidationError, ValidationResponse
from generated.infra_pb2 import Device
from generated.annotate_pb2 import Annotation
from keysight_chakra.infra.service_pb2 import ValidationRequest, ValidationError, ValidationResponse
from keysight_chakra.infra.infra_pb2 import Device
from keysight_chakra.infra.annotate_pb2 import Annotation


class Validation:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# "install_destination_package_path": "source_dir_path"
package_dir_map = {
f"{package_base}": "./keysight_chakra",
f"{package_base}/generated": "./keysight_chakra/generated",
f"{package_base}/tests": "./keysight_chakra/tests",
f"{package_base}/infra": "./keysight_chakra/infra",
f"{package_base}/mlcommons": "./keysight_chakra/mlcommons",
}

requires = [
Expand Down
8 changes: 1 addition & 7 deletions keysight_chakra/tests/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import sys
import os

for directory_piece in ["..", "generated", "tests"]:
sys.path.append(os.path.join(os.path.dirname(__file__), directory_piece))

import pytest
from keysight_chakra.generated.infra_pb2 import Device, Component, Link, Bandwidth, Npu, Nic
from keysight_chakra.infra.infra_pb2 import Device, Component, Link, Bandwidth, Npu, Nic
from keysight_chakra.validation import Validation


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from google.protobuf.json_format import MessageToJson, Parse
from google.protobuf.any_pb2 import Any
from google.protobuf.wrappers_pb2 import StringValue
from keysight_chakra.generated.annotate_pb2 import Annotation, Target, Data
from keysight_chakra.infra.annotate_pb2 import Annotation, Target, Data


class AnyString:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from keysight_chakra.generated.service_pb2 import ValidationRequest
from keysight_chakra.generated.infra_pb2 import (
from keysight_chakra.infra.service_pb2 import ValidationRequest
from keysight_chakra.infra.infra_pb2 import (
Infrastructure,
Inventory,
Device,
Expand Down