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

Refactor package structure to move generated code to language-specific folders #6

Merged
merged 3 commits into from
Nov 30, 2020

Conversation

kuujo
Copy link
Contributor

@kuujo kuujo commented Nov 30, 2020

This PR refactors the package structure used for Protobuf files and for each language.

The code for each language -- including Protobuf -- is moved to its own folder, e.g. /proto, /go, /python, etc. Different languages have different packaging systems and conventions, and this allows the code layout to follow the conventions for each specific language. For example, Protobuf allows .proto files for multiple packages to be in the same directory, while Go requires that all .go files in a folder have the same package name. Like Protobuf and Go, Python has a packaging system. But whereas all types within a Go package share the same namespace, Python namespaces types within a file (module) by the module name rather than the package name. This leads to a different convention for packaging in Python than in Go. In Python, for example, even though the e2sub services span multiple Protobuf packages, all of the e2sub services can be members of the same Python package without creating naming collisions, and indeed that would be more consistent with conventional Python project structures.

By separating the packages and code for each language into its own folder, we can layout the generated code for each language according to the language's conventions. Additionally, language-specific dependency management can be located in language-specific folders. For instance, the Go module root for the onos-api is now in the /go folder rather than in the onos-api root. Similarly, the /python folder can include a requirements.txt for instance.

Finally, I restructured the package structure used in the /proto folder itself such that the folder hierarchy matches the package names. The protoc plugins for some languages will work better this way. And I cleaned up the compile-protos.sh script to generate documentation separately from the bindings for each language.

@@ -107,8 +105,8 @@ message ListSubscriptionTasksResponse {
// WatchSubscriptionTasksRequest is a request to receive a stream of all SubscriptionTask changes.
message WatchSubscriptionTasksRequest {
bool noreplay = 1;
string subscription_id = 2 [(gogoproto.customname) = "SubscriptionID", (gogoproto.casttype) = "github.com/onosproject/onos-e2sub/api/e2/subscription/v1beta1.ID"];
string endpoint_id = 3 [(gogoproto.customname) = "EndpointID", (gogoproto.casttype) = "github.com/onosproject/onos-e2sub/api/e2/endpoint/v1beta1.ID"];
string subscription_id = 2 [(gogoproto.customname) = "SubscriptionID", (gogoproto.casttype) = "github.com/onosproject/onos-api/go/onos/e2sub/subscription.ID"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. I was wondering why I was getting references to e2sub

@kuujo kuujo merged commit 9a58a95 into onosproject:master Nov 30, 2020
@kuujo kuujo deleted the language-agnostic branch November 30, 2020 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants