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!: rename container to cosmossdk.io/depinject #12020

Merged
merged 34 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ebb79fe
chore: rename container to cosmossdk.io/container
facundomedica May 23, 2022
e1ca78e
fix imports
facundomedica May 23, 2022
901f1c1
add replace for container
facundomedica May 23, 2022
3a4cefe
remove replace
facundomedica May 23, 2022
d1fdcee
add replace
facundomedica May 24, 2022
d2a7b8b
fix replace
facundomedica May 24, 2022
7e137c1
fix replace
facundomedica May 24, 2022
55b4bc3
fix replace
facundomedica May 24, 2022
da1ed43
fix replace
facundomedica May 24, 2022
6c9a269
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into facu…
facundomedica May 24, 2022
fdafd58
fix replace
facundomedica May 24, 2022
36d30c3
try to fix replace
facundomedica May 24, 2022
d6c405e
merge main
facundomedica May 26, 2022
bfe719b
rename to depinject
facundomedica May 26, 2022
9cf5e17
rename to depinject
facundomedica May 26, 2022
531fb20
do not use vanity URL for now
facundomedica May 26, 2022
3b6c156
try fix tests
facundomedica May 26, 2022
e60464d
try fix tests
facundomedica May 26, 2022
28158f8
try fix tests
facundomedica May 26, 2022
fa7a15f
build -> inject
facundomedica May 26, 2022
fd7cdc8
build -> inject
facundomedica May 26, 2022
9a22063
merge main
facundomedica May 27, 2022
152dd34
go mod tidy
facundomedica May 27, 2022
a176b9d
fix dep vulnerability
facundomedica May 27, 2022
51ef9b4
fix dep vulnerability
facundomedica May 27, 2022
1ca5e5e
fix Dockerfile for liveness-test
facundomedica May 27, 2022
4f26143
fix codeql error
facundomedica May 27, 2022
5975f3b
try to solve dependency review
facundomedica May 27, 2022
0581cf8
Merge branch 'main' into facu/rename-container
facundomedica May 27, 2022
8f0165a
try to solve dependency review
facundomedica May 27, 2022
31329a1
Merge branch 'facu/rename-container' of https://github.com/cosmos/cos…
facundomedica May 27, 2022
c56cafe
go mod tidy
facundomedica May 27, 2022
e9f2bbe
try to fix tests
facundomedica May 27, 2022
84cb251
another try
facundomedica May 27, 2022
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
43 changes: 0 additions & 43 deletions container/testdata/example.dot

This file was deleted.

40 changes: 0 additions & 40 deletions container/testdata/example_error.dot

This file was deleted.

41 changes: 20 additions & 21 deletions core/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,94 +12,93 @@ import (
"google.golang.org/protobuf/types/known/anypb"
"sigs.k8s.io/yaml"

"github.com/cosmos/cosmos-sdk/container"

appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"github.com/cosmos/cosmos-sdk/depinject"

"cosmossdk.io/core/internal"
)

// LoadJSON loads an app config in JSON format.
func LoadJSON(bz []byte) container.Config {
func LoadJSON(bz []byte) depinject.Config {
config := &appv1alpha1.Config{}
err := protojson.Unmarshal(bz, config)
if err != nil {
return container.Error(err)
return depinject.Error(err)
}

return Compose(config)
}

// LoadYAML loads an app config in YAML format.
func LoadYAML(bz []byte) container.Config {
func LoadYAML(bz []byte) depinject.Config {
j, err := yaml.YAMLToJSON(bz)
if err != nil {
return container.Error(err)
return depinject.Error(err)
}

return LoadJSON(j)
}

// Compose composes a v1alpha1 app config into a container option by resolving
// the required modules and composing their options.
func Compose(appConfig *appv1alpha1.Config) container.Config {
opts := []container.Config{
container.Supply(appConfig),
func Compose(appConfig *appv1alpha1.Config) depinject.Config {
opts := []depinject.Config{
depinject.Supply(appConfig),
}

for _, module := range appConfig.Modules {
if module.Name == "" {
return container.Error(fmt.Errorf("module is missing name"))
return depinject.Error(fmt.Errorf("module is missing name"))
}

if module.Config == nil {
return container.Error(fmt.Errorf("module %q is missing a config object", module.Name))
return depinject.Error(fmt.Errorf("module %q is missing a config object", module.Name))
}

msgType, err := protoregistry.GlobalTypes.FindMessageByURL(module.Config.TypeUrl)
if err != nil {
return container.Error(err)
return depinject.Error(err)
}

modules, err := internal.ModulesByProtoMessageName()
if err != nil {
return container.Error(err)
return depinject.Error(err)
}

init, ok := modules[msgType.Descriptor().FullName()]
if !ok {
modDesc := proto.GetExtension(msgType.Descriptor().Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
if modDesc == nil {
return container.Error(fmt.Errorf("no module registered for type URL %s and that protobuf type does not have the option %s\n\n%s",
return depinject.Error(fmt.Errorf("no module registered for type URL %s and that protobuf type does not have the option %s\n\n%s",
module.Config.TypeUrl, appv1alpha1.E_Module.TypeDescriptor().FullName(), dumpRegisteredModules(modules)))
}

return container.Error(fmt.Errorf("no module registered for type URL %s, did you forget to import %s\n\n%s",
return depinject.Error(fmt.Errorf("no module registered for type URL %s, did you forget to import %s\n\n%s",
module.Config.TypeUrl, modDesc.GoImport, dumpRegisteredModules(modules)))
}

config := init.ConfigProtoMessage.ProtoReflect().Type().New().Interface()
err = anypb.UnmarshalTo(module.Config, config, proto.UnmarshalOptions{})
if err != nil {

return container.Error(err)
return depinject.Error(err)
}

opts = append(opts, container.Provide(container.ProviderDescriptor{
opts = append(opts, depinject.Provide(depinject.ProviderDescriptor{
Inputs: nil,
Outputs: []container.ProviderOutput{{Type: init.ConfigGoType}},
Outputs: []depinject.ProviderOutput{{Type: init.ConfigGoType}},
Fn: func(values []reflect.Value) ([]reflect.Value, error) {
return []reflect.Value{reflect.ValueOf(config)}, nil
},
Location: container.LocationFromCaller(0),
Location: depinject.LocationFromCaller(0),
}))

for _, provider := range init.Providers {
opts = append(opts, container.ProvideInModule(module.Name, provider))
opts = append(opts, depinject.ProvideInModule(module.Name, provider))
}
}

return container.Configs(opts...)
return depinject.Configs(opts...)
}

func dumpRegisteredModules(modules map[protoreflect.FullName]*internal.ModuleInitializer) string {
Expand Down
9 changes: 4 additions & 5 deletions core/appconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import (

"gotest.tools/v3/assert"

"github.com/cosmos/cosmos-sdk/container"

"cosmossdk.io/core/appconfig"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/internal"
"cosmossdk.io/core/internal/testpb"
_ "cosmossdk.io/core/internal/testpb"
"github.com/cosmos/cosmos-sdk/depinject"
)

func expectContainerErrorContains(t *testing.T, option container.Config, contains string) {
func expectContainerErrorContains(t *testing.T, option depinject.Config, contains string) {
t.Helper()
err := container.Build(option)
err := depinject.Build(option)
assert.ErrorContains(t, err, contains)
}

Expand Down Expand Up @@ -70,7 +69,7 @@ modules:
config:
"@type": testpb.TestModuleB
`))
assert.NilError(t, container.Build(opt, &app))
assert.NilError(t, depinject.Build(opt, &app))
buf := &bytes.Buffer{}
app(buf)
const expected = `got store key a
Expand Down
2 changes: 1 addition & 1 deletion core/appmodule/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package appmodule defines the functionality for registering Cosmos SDK app
// modules that are assembled using the github.com/cosmos/cosmos-sdk/container
// modules that are assembled using the github.com/cosmos/cosmos-sdk/depinject v1.0.0-alpha.3
// dependency injection system and the declarative app configuration format
// handled by the appconfig package.
package appmodule
7 changes: 3 additions & 4 deletions core/appmodule/option.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package appmodule

import (
"github.com/cosmos/cosmos-sdk/container"

"cosmossdk.io/core/internal"
"github.com/cosmos/cosmos-sdk/depinject"
)

// Option is a functional option for implementing modules.
Expand All @@ -18,12 +17,12 @@ func (f funcOption) apply(initializer *internal.ModuleInitializer) error {
}

// Provide registers providers with the dependency injection system that will be
// run within the module scope. See github.com/cosmos/cosmos-sdk/container for
// run within the module scope. See github.com/cosmos/cosmos-sdk/depinject v1.0.0-alpha.3 for
// documentation on the dependency injection system.
func Provide(providers ...interface{}) Option {
return funcOption(func(initializer *internal.ModuleInitializer) error {
for _, provider := range providers {
desc, err := container.ExtractProviderDescriptor(provider)
desc, err := depinject.ExtractProviderDescriptor(provider)
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
cosmossdk.io/api v0.1.0-alpha8
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk/container v1.0.0-alpha.4
github.com/cosmos/cosmos-sdk/depinject v1.0.0-alpha.4
google.golang.org/protobuf v1.28.0
gotest.tools/v3 v3.2.0
sigs.k8s.io/yaml v1.3.0
Expand All @@ -26,4 +26,7 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/cosmos/cosmos-sdk/api => ../api
replace (
github.com/cosmos/cosmos-sdk/api => ../api
github.com/cosmos/cosmos-sdk/depinject => ../depinject
)
2 changes: 0 additions & 2 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cosmos/cosmos-proto v1.0.0-alpha7 h1:yqYUOHF2jopwZh4dVQp3xgqwftE5/2hkrwIV6vkUbO0=
github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNsjcvSUBQmniFxDg5daw=
github.com/cosmos/cosmos-sdk/container v1.0.0-alpha.4 h1:f2Kc7uEMLJ45F8nnj+AYPQi4xObMX8ho9IkfEvcUqt4=
github.com/cosmos/cosmos-sdk/container v1.0.0-alpha.4/go.mod h1:ZPOZVw4LfyYwsh8M14JxoBGoLM/FRSXc7wuPUfWgvFA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
5 changes: 2 additions & 3 deletions core/internal/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

"github.com/cosmos/cosmos-sdk/container"

appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"github.com/cosmos/cosmos-sdk/depinject"
)

// ModuleRegistry is the registry of module initializers indexed by their golang
Expand All @@ -21,7 +20,7 @@ type ModuleInitializer struct {
ConfigGoType reflect.Type
ConfigProtoMessage proto.Message
Error error
Providers []container.ProviderDescriptor
Providers []depinject.ProviderDescriptor
}

// ModulesByProtoMessageName should be used to retrieve modules by their protobuf name.
Expand Down
5 changes: 2 additions & 3 deletions core/internal/testpb/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"io"
"sort"

"github.com/cosmos/cosmos-sdk/container"

"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/depinject"
)

func init() {
Expand All @@ -28,7 +27,7 @@ func provideRuntimeState() *runtimeState {
return &runtimeState{}
}

func provideStoreKey(key container.ModuleKey, state *runtimeState) StoreKey {
func provideStoreKey(key depinject.ModuleKey, state *runtimeState) StoreKey {
sk := StoreKey{name: key.Name()}
state.storeKeys = append(state.storeKeys, sk)
return sk
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion container/build.go → depinject/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package container
package depinject

// Build builds the container specified by containerConfig and extracts the
// requested outputs from the container or returns an error. It is the single
Expand Down
2 changes: 1 addition & 1 deletion container/config.go → depinject/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package container
package depinject

import (
"reflect"
Expand Down
4 changes: 2 additions & 2 deletions container/container.go → depinject/container.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package container
package depinject

import (
"bytes"
Expand All @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"

"github.com/cosmos/cosmos-sdk/container/internal/graphviz"
"github.com/cosmos/cosmos-sdk/depinject/internal/graphviz"
)

type container struct {
Expand Down
Loading