Skip to content

Commit 4cca416

Browse files
RSDK-9607: add build and run options for all Python modules; remove run option for Go (viamrobotics#4818)
1 parent 0e93562 commit 4cca416

File tree

4 files changed

+17
-83
lines changed

4 files changed

+17
-83
lines changed

cli/module_generate.go

+12-48
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ func (c *viamClient) generateModuleAction(cCtx *cli.Context, args generateModule
153153
warningf(cCtx.App.ErrWriter, err.Error())
154154
nonFatalError = true
155155
}
156-
157-
s.Title("Generating cloud build requirements...")
158-
if err = generateCloudBuild(cCtx, *newModule, globalArgs); err != nil {
159-
warningf(cCtx.App.ErrWriter, err.Error())
160-
nonFatalError = true
161-
}
162156
}
163157

164158
if globalArgs.Debug {
@@ -743,32 +737,6 @@ func getLatestSDKTag(c *cli.Context, language string, globalArgs globalArgs) (st
743737
return version, nil
744738
}
745739

746-
func generateCloudBuild(c *cli.Context, module modulegen.ModuleInputs, globalArgs globalArgs) error {
747-
debugf(c.App.Writer, globalArgs.Debug, "Setting cloud build functionality to %v", module.EnableCloudBuild)
748-
switch module.Language {
749-
case python:
750-
if module.EnableCloudBuild {
751-
err := os.Remove(filepath.Join(module.ModuleName, "run.sh"))
752-
if err != nil {
753-
return err
754-
}
755-
} else {
756-
err := os.Remove(filepath.Join(module.ModuleName, "build.sh"))
757-
if err != nil {
758-
return err
759-
}
760-
}
761-
case golang:
762-
if module.EnableCloudBuild {
763-
err := os.Remove(filepath.Join(module.ModuleName, "run.sh"))
764-
if err != nil {
765-
return err
766-
}
767-
}
768-
}
769-
return nil
770-
}
771-
772740
func createModuleAndManifest(cCtx *cli.Context, c *viamClient, module modulegen.ModuleInputs, globalArgs globalArgs) error {
773741
var moduleID moduleID
774742
if module.RegisterOnApp {
@@ -846,29 +814,25 @@ func renderManifest(c *cli.Context, moduleID string, module modulegen.ModuleInpu
846814
}
847815
switch module.Language {
848816
case python:
817+
manifest.Build = &manifestBuildInfo{
818+
Setup: "./setup.sh",
819+
Build: "./build.sh",
820+
Path: "dist/archive.tar.gz",
821+
Arch: []string{"linux/amd64", "linux/arm64"},
822+
}
849823
if module.EnableCloudBuild {
850-
manifest.Build = &manifestBuildInfo{
851-
Setup: "./setup.sh",
852-
Build: "./build.sh",
853-
Path: "dist/archive.tar.gz",
854-
Arch: []string{"linux/amd64", "linux/arm64"},
855-
}
856824
manifest.Entrypoint = "dist/main"
857825
} else {
858826
manifest.Entrypoint = "./run.sh"
859827
}
860828
case golang:
861-
if module.EnableCloudBuild {
862-
manifest.Build = &manifestBuildInfo{
863-
Setup: "make setup",
864-
Build: "make module.tar.gz",
865-
Path: "bin/module.tar.gz",
866-
Arch: []string{"linux/amd64", "linux/arm64"},
867-
}
868-
manifest.Entrypoint = fmt.Sprintf("bin/%s", module.ModuleName)
869-
} else {
870-
manifest.Entrypoint = "./run.sh"
829+
manifest.Build = &manifestBuildInfo{
830+
Setup: "make setup",
831+
Build: "make module.tar.gz",
832+
Path: "bin/module.tar.gz",
833+
Arch: []string{"linux/amd64", "linux/arm64"},
871834
}
835+
manifest.Entrypoint = fmt.Sprintf("bin/%s", module.ModuleName)
872836
}
873837

874838
if err := writeManifest(filepath.Join(module.ModuleName, defaultManifestFilename), manifest); err != nil {

cli/module_generate/_templates/go/run.sh

-23
This file was deleted.

cli/module_generate/_templates/python/src/tmpl-main.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import asyncio
22
from viam.module.module import Module
3-
from .models.{{ .ModelSnake }} import {{ .ModelPascal }}
3+
try:
4+
from models.{{ .ModelSnake }} import {{ .ModelPascal }}
5+
except ModuleNotFoundError:
6+
# when running as local module with run.sh
7+
from .models.{{ .ModelSnake }} import {{ .ModelPascal }}
48

59

610
if __name__ == '__main__':

cli/module_generate_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,6 @@ func TestGenerateModuleAction(t *testing.T) {
157157
test.That(t, err, test.ShouldBeNil)
158158
})
159159

160-
t.Run("test generate cloud build", func(t *testing.T) {
161-
setupDirectories(cCtx, testModule.ModuleName, globalArgs)
162-
err := generateCloudBuild(cCtx, testModule, globalArgs)
163-
test.That(t, err, test.ShouldBeNil)
164-
165-
_, err = os.Stat(filepath.Join(modulePath, "run.sh"))
166-
test.That(t, err, test.ShouldNotBeNil)
167-
_, err = os.Stat(filepath.Join(modulePath, "build.sh"))
168-
test.That(t, err, test.ShouldBeNil)
169-
})
170-
171160
t.Run("test create module and manifest", func(t *testing.T) {
172161
cCtx, ac, _, _ := setup(&inject.AppServiceClient{}, nil, &inject.BuildServiceClient{
173162
StartBuildFunc: func(ctx context.Context, in *v1.StartBuildRequest, opts ...grpc.CallOption) (*v1.StartBuildResponse, error) {

0 commit comments

Comments
 (0)