status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
β | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
unknown | language
stringclasses 5
values | commit_datetime
unknown | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | if i%10 != 0 {
continue
}
eg.Go(func() error {
_, err := modGen.
With(daggerCall(fmt.Sprintf("potato%d", i))).
Sync(ctx)
return err
})
}
require.NoError(t, eg.Wait())
})
t.Run("python sdk", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
mainSrc := `from dagger import function
`
for i := 0; i < funcCount; i++ {
mainSrc += fmt.Sprintf(`
@function
def potato_%d() -> str:
return "potato #%d"
`, i, i)
}
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("./src/main.py", dagger.ContainerWithNewFileOpts{
Contents: mainSrc, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | }).
With(daggerExec("init", "--source=.", "--name=potatoSack", "--sdk=python"))
var eg errgroup.Group
for i := 0; i < funcCount; i++ {
i := i
if i%10 != 0 {
continue
}
eg.Go(func() error {
_, err := modGen.
With(daggerCall(fmt.Sprintf("potato%d", i))).
Sync(ctx)
return err
})
}
require.NoError(t, eg.Wait())
})
t.Run("typescript sdk", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
mainSrc := `
import { object, func } from "@dagger.io/dagger"
@object()
class PotatoSack {
`
for i := 0; i < funcCount; i++ {
mainSrc += fmt.Sprintf(`
@func()
potato_%d(): string { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | return "potato #%d"
}
`, i, i)
}
mainSrc += "\n}"
modGen := c.
Container().
From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(sdkSource("typescript", mainSrc)).
With(daggerExec("init", "--name=potatoSack", "--sdk=typescript"))
var eg errgroup.Group
for i := 0; i < funcCount; i++ {
i := i
if i%10 != 0 {
continue
}
eg.Go(func() error {
_, err := modGen.
With(daggerCall(fmt.Sprintf("potato%d", i))).
Sync(ctx)
return err
})
}
require.NoError(t, eg.Wait())
})
}
func TestModuleLotsOfDeps(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := goGitBase(t, c).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work")
modCount := 0
getModMainSrc := func(name string, depNames []string) string {
t.Helper()
mainSrc := fmt.Sprintf(`package main
import "context"
type %s struct {}
func (m *%s) Fn(ctx context.Context) (string, error) {
s := "%s"
var depS string
_ = depS
var err error
_ = err
`, strcase.ToCamel(name), strcase.ToCamel(name), name) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | for _, depName := range depNames {
mainSrc += fmt.Sprintf(`
depS, err = dag.%s().Fn(ctx)
if err != nil {
return "", err
}
s += depS
`, strcase.ToCamel(depName))
}
mainSrc += "return s, nil\n}\n"
fmted, err := format.Source([]byte(mainSrc))
require.NoError(t, err)
return string(fmted)
}
var rootCfg modules.ModuleConfig
addModulesWithDeps := func(newMods int, depNames []string) []string {
t.Helper()
var newModNames []string
for i := 0; i < newMods; i++ {
name := fmt.Sprintf("mod%d", modCount)
modCount++
newModNames = append(newModNames, name)
modGen = modGen.
WithWorkdir("/work/"+name).
WithNewFile("./main.go", dagger.ContainerWithNewFileOpts{
Contents: getModMainSrc(name, depNames),
})
var depCfgs []*modules.ModuleConfigDependency |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | for _, depName := range depNames {
depCfgs = append(depCfgs, &modules.ModuleConfigDependency{
Name: depName,
Source: filepath.Join("..", depName),
})
}
modGen = modGen.With(configFile(".", &modules.ModuleConfig{
Name: name,
SDK: "go",
Dependencies: depCfgs,
}))
}
return newModNames
}
curDeps := addModulesWithDeps(1, nil)
for i := 0; i < 6; i++ {
curDeps = addModulesWithDeps(len(curDeps)+1, curDeps)
}
addModulesWithDeps(1, curDeps)
modGen = modGen.With(configFile("..", &rootCfg))
_, err := modGen.With(daggerCall("fn")).Sync(ctx)
require.NoError(t, err)
}
func TestModuleNamespacing(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
moduleSrcPath, err := filepath.Abs("./testdata/modules/go/namespacing")
require.NoError(t, err)
ctr := c.Container().From(alpineImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithMountedDirectory("/work", c.Host().Directory(moduleSrcPath)).
WithWorkdir("/work")
out, err := ctr.
With(daggerQuery(`{test{fn(s:"yo")}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"test":{"fn":["*dagger.Sub1Obj made 1:yo", "*dagger.Sub2Obj made 2:yo"]}}`, out)
}
func TestModuleLoops(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
_, err := goGitBase(t, c).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
With(daggerExec("init", "--name=depA", "--sdk=go", "depA")).
With(daggerExec("init", "--name=depB", "--sdk=go", "depB")).
With(daggerExec("init", "--name=depC", "--sdk=go", "depC")).
With(daggerExec("install", "-m=depC", "./depB")).
With(daggerExec("install", "-m=depB", "./depA")).
With(daggerExec("install", "-m=depA", "./depC")).
Sync(ctx)
require.ErrorContains(t, err, `local module at "/work/depA" has a circular dependency`)
}
var badIDArgGoSrc string
var badIDArgPySrc string
var badIDArgTSSrc string
var badIDFieldGoSrc string
var badIDFieldTSSrc string
var badIDFnGoSrc string
var badIDFnPySrc string
var badIDFnTSSrc string
func TestModuleReservedWords(t *testing.T) {
t.Parallel()
type testCase struct {
sdk string
source string
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Run("id", func(t *testing.T) {
t.Parallel()
t.Run("arg", func(t *testing.T) {
t.Parallel()
for _, tc := range []testCase{
{
sdk: "go",
source: badIDArgGoSrc,
},
{
sdk: "python",
source: badIDArgPySrc,
},
{
sdk: "typescript",
source: badIDArgTSSrc,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
_, err := modInit(ctx, t, c, tc.sdk, tc.source).
With(daggerQuery(`{test{fn(id:"no")}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define argument with reserved name \"id\"")
})
}
})
t.Run("field", func(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
for _, tc := range []testCase{
{
sdk: "go",
source: badIDFieldGoSrc,
},
{
sdk: "typescript",
source: badIDFieldTSSrc,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source)).
With(daggerQuery(`{test{fn{id}}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define field with reserved name \"id\"")
})
}
})
t.Run("fn", func(t *testing.T) {
t.Parallel()
for _, tc := range []testCase{
{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | sdk: "go",
source: badIDFnGoSrc,
},
{
sdk: "python",
source: badIDFnPySrc,
},
{
sdk: "typescript",
source: badIDFnTSSrc,
},
} {
tc := tc
t.Run(tc.sdk, func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--name=test", "--sdk="+tc.sdk)).
With(sdkSource(tc.sdk, tc.source)).
With(daggerQuery(`{test{id}}`)).
Sync(ctx)
require.ErrorContains(t, err, "cannot define function with reserved name \"id\"")
})
}
})
})
}
func TestModuleExecError(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(alpineImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=playground", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `
package main
import (
"context"
"errors"
)
type Playground struct{}
func (p *Playground) DoThing(ctx context.Context) error {
_, err := dag.Container().From("` + alpineImage + `").WithExec([]string{"sh", "-c", "exit 5"}).Sync(ctx)
var e *ExecError
if errors.As(err, &e) {
if e.ExitCode == 5 {
return nil
}
}
panic("yikes")
}
`})
_, err := modGen.
With(daggerQuery(`{playground{doThing}}`)).
Stdout(ctx)
require.NoError(t, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | }
func TestModuleCurrentModuleAPI(t *testing.T) {
t.Parallel()
t.Run("name", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=WaCkY", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "context"
type WaCkY struct {}
func (m *WaCkY) Fn(ctx context.Context) (string, error) {
return dag.CurrentModule().Name(ctx)
}
`,
}).
With(daggerCall("fn")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "WaCkY", strings.TrimSpace(out))
})
t.Run("source", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work"). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("/work/subdir/coolfile.txt", dagger.ContainerWithNewFileOpts{
Contents: "nice",
}).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "context"
type Test struct {}
func (m *Test) Fn(ctx context.Context) *File {
return dag.CurrentModule().Source().File("subdir/coolfile.txt")
}
`,
}).
With(daggerCall("fn", "contents")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "nice", strings.TrimSpace(out))
})
t.Run("workdir", func(t *testing.T) {
t.Parallel()
t.Run("dir", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import ( |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | "context"
"os"
)
type Test struct {}
func (m *Test) Fn(ctx context.Context) (*Directory, error) {
if err := os.MkdirAll("subdir/moresubdir", 0755); err != nil {
return nil, err
}
if err := os.WriteFile("subdir/moresubdir/coolfile.txt", []byte("nice"), 0644); err != nil {
return nil, err
}
return dag.CurrentModule().Workdir("subdir/moresubdir"), nil
}
`,
}).
With(daggerCall("fn", "file", "--path=coolfile.txt", "contents")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "nice", strings.TrimSpace(out))
})
t.Run("file", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import ( |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | "context"
"os"
)
type Test struct {}
func (m *Test) Fn(ctx context.Context) (*File, error) {
if err := os.MkdirAll("subdir/moresubdir", 0755); err != nil {
return nil, err
}
if err := os.WriteFile("subdir/moresubdir/coolfile.txt", []byte("nice"), 0644); err != nil {
return nil, err
}
return dag.CurrentModule().WorkdirFile("subdir/moresubdir/coolfile.txt"), nil
}
`,
}).
With(daggerCall("fn", "contents")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "nice", strings.TrimSpace(out))
})
t.Run("error on escape", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import ( |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | "context"
"os"
)
func New() (*Test, error) {
if err := os.WriteFile("/rootfile.txt", []byte("notnice"), 0644); err != nil {
return nil, err
}
if err := os.MkdirAll("/foo", 0755); err != nil {
return nil, err
}
if err := os.WriteFile("/foo/foofile.txt", []byte("notnice"), 0644); err != nil {
return nil, err
}
return &Test{}, nil
}
type Test struct {}
func (m *Test) EscapeFile(ctx context.Context) *File {
return dag.CurrentModule().WorkdirFile("../rootfile.txt")
}
func (m *Test) EscapeFileAbs(ctx context.Context) *File {
return dag.CurrentModule().WorkdirFile("/rootfile.txt")
}
func (m *Test) EscapeDir(ctx context.Context) *Directory {
return dag.CurrentModule().Workdir("../foo")
}
func (m *Test) EscapeDirAbs(ctx context.Context) *Directory {
return dag.CurrentModule().Workdir("/foo")
}
`,
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | _, err := ctr.
With(daggerCall("escape-file", "contents")).
Stdout(ctx)
require.ErrorContains(t, err, `workdir path "../rootfile.txt" escapes workdir`)
_, err = ctr.
With(daggerCall("escape-file-abs", "contents")).
Stdout(ctx)
require.ErrorContains(t, err, `workdir path "/rootfile.txt" escapes workdir`)
_, err = ctr.
With(daggerCall("escape-dir", "entries")).
Stdout(ctx)
require.ErrorContains(t, err, `workdir path "../foo" escapes workdir`)
_, err = ctr.
With(daggerCall("escape-dir-abs", "entries")).
Stdout(ctx)
require.ErrorContains(t, err, `workdir path "/foo" escapes workdir`)
})
})
}
func TestModuleCustomSDK(t *testing.T) {
t.Parallel()
t.Run("local", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work/coolsdk").
With(daggerExec("init", "--source=.", "--name=cool-sdk", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | type CoolSdk struct {}
func (m *CoolSdk) ModuleRuntime(modSource *ModuleSource, introspectionJson string) *Container {
return modSource.WithSDK("go").AsModule().Runtime().WithEnvVariable("COOL", "true")
}
func (m *CoolSdk) Codegen(modSource *ModuleSource, introspectionJson string) *GeneratedCode {
return dag.GeneratedCode(modSource.WithSDK("go").AsModule().GeneratedContextDirectory())
}
func (m *CoolSdk) RequiredPaths() []string {
return []string{
"**/go.mod",
"**/go.sum",
"**/go.work",
"**/go.work.sum",
"**/vendor/",
"**/*.go",
}
}
`,
}).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=coolsdk")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "os"
type Test struct {}
func (m *Test) Fn() string {
return os.Getenv("COOL")
}
`,
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | out, err := ctr.
With(daggerCall("fn")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "true", strings.TrimSpace(out))
})
t.Run("git", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk="+testGitModuleRef("cool-sdk"))).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import "os"
type Test struct {}
func (m *Test) Fn() string {
return os.Getenv("COOL")
}
`,
})
out, err := ctr.
With(daggerCall("fn")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "true", strings.TrimSpace(out))
})
}
func TestModuleHostError(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Parallel()
c, ctx := connect(t)
_, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
)
type Test struct {}
func (m *Test) Fn(ctx context.Context) *Directory {
return dag.Host().Directory(".")
}
`,
}).
With(daggerCall("fn")).
Sync(ctx)
require.ErrorContains(t, err, "dag.Host undefined")
}
func daggerExec(args ...string) dagger.WithContainerFunc { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | return func(c *dagger.Container) *dagger.Container {
return c.WithExec(append([]string{"dagger", "--debug"}, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerQuery(query string, args ...any) dagger.WithContainerFunc {
return daggerQueryAt("", query, args...)
}
func daggerQueryAt(modPath string, query string, args ...any) dagger.WithContainerFunc {
query = fmt.Sprintf(query, args...)
return func(c *dagger.Container) *dagger.Container {
execArgs := []string{"dagger", "--debug", "query"}
if modPath != "" {
execArgs = append(execArgs, "-m", modPath)
}
return c.WithExec(execArgs, dagger.ContainerWithExecOpts{
Stdin: query,
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerCall(args ...string) dagger.WithContainerFunc {
return daggerCallAt("", args...)
}
func daggerCallAt(modPath string, args ...string) dagger.WithContainerFunc { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | return func(c *dagger.Container) *dagger.Container {
execArgs := []string{"dagger", "--debug", "call"}
if modPath != "" {
execArgs = append(execArgs, "-m", modPath)
}
return c.WithExec(append(execArgs, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func daggerFunctions(args ...string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
return c.WithExec(append([]string{"dagger", "--debug", "functions"}, args...), dagger.ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
})
}
}
func configFile(dirPath string, cfg *modules.ModuleConfig) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
cfgPath := filepath.Join(dirPath, "dagger.json")
cfgBytes, err := json.Marshal(cfg)
if err != nil {
panic(err)
}
return c.WithNewFile(cfgPath, dagger.ContainerWithNewFileOpts{
Contents: string(cfgBytes),
})
}
}
func hostDaggerCommand(ctx context.Context, t testing.TB, workdir string, args ...string) *exec.Cmd { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Helper()
cmd := exec.CommandContext(ctx, daggerCliPath(t), args...)
cmd.Dir = workdir
return cmd
}
func hostDaggerExec(ctx context.Context, t testing.TB, workdir string, args ...string) ([]byte, error) {
t.Helper()
cmd := hostDaggerCommand(ctx, t, workdir, args...)
output, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("%s: %w", string(output), err)
}
return output, err
}
func sdkSource(sdk, contents string) dagger.WithContainerFunc {
return func(c *dagger.Container) *dagger.Container {
sourcePath := sdkSourceFile(sdk)
if sourcePath == "" {
return c
}
return c.WithNewFile(sourcePath, dagger.ContainerWithNewFileOpts{
Contents: heredoc.Doc(contents),
})
}
}
func sdkSourceFile(sdk string) string { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | switch sdk {
case "go":
return "dagger/main.go"
case "python":
return "dagger/src/main.py"
case "typescript":
return "dagger/src/index.ts"
default:
return ""
}
}
func sdkCodegenFile(t *testing.T, sdk string) string {
t.Helper()
switch sdk {
case "go":
return "dagger/dagger/dagger.gen.go"
case "python":
return "dagger/sdk/src/dagger/client/gen.py"
case "typescript":
return "dagger/sdk/api/client.gen.ts"
default:
return ""
}
}
func modInit(ctx context.Context, t *testing.T, c *dagger.Client, sdk, contents string) *dagger.Container { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Helper()
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--name=test", "--sdk="+sdk)).
With(sdkSource(sdk, contents))
return modGen
}
func currentSchema(ctx context.Context, t *testing.T, ctr *dagger.Container) *introspection.Schema {
t.Helper()
out, err := ctr.With(daggerQuery(introspection.Query)).Stdout(ctx)
require.NoError(t, err)
var schemaResp introspection.Response
err = json.Unmarshal([]byte(out), &schemaResp)
require.NoError(t, err)
return schemaResp.Schema
}
var moduleIntrospection = daggerQuery(`
query { host { directory(path: ".") { asModule { initialize {
description |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | objects {
asObject {
name
description
constructor {
description
args {
name
description
defaultValue
}
}
functions {
name
description
args {
name
description
defaultValue
}
}
fields {
name
description
}
}
}
} } } } }
`)
func inspectModule(ctx context.Context, t *testing.T, ctr *dagger.Container) gjson.Result { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Helper()
out, err := ctr.With(moduleIntrospection).Stdout(ctx)
require.NoError(t, err)
result := gjson.Get(out, "host.directory.asModule.initialize")
t.Logf("module introspection:\n%v", result.Raw)
return result
}
func inspectModuleObjects(ctx context.Context, t *testing.T, ctr *dagger.Container) gjson.Result {
t.Helper()
return inspectModule(ctx, t, ctr).Get("objects.#.asObject")
}
func goGitBase(t *testing.T, c *dagger.Client) *dagger.Container {
t.Helper()
return c.Container().From(golangImage).
WithExec([]string{"apk", "add", "git"}).
WithExec([]string{"git", "config", "--global", "user.email", "[email protected]"}).
WithExec([]string{"git", "config", "--global", "user.name", "Dagger Tests"}).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithExec([]string{"git", "init"})
}
func logGen(ctx context.Context, t *testing.T, modSrc *dagger.Directory) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/integration/module_test.go | t.Helper()
generated, err := modSrc.File("dagger.gen.go").Contents(ctx)
require.NoError(t, err)
t.Cleanup(func() {
t.Name()
fileName := filepath.Join(
os.TempDir(),
t.Name(),
fmt.Sprintf("dagger.gen.%d.go", time.Now().Unix()),
)
if err := os.MkdirAll(filepath.Dir(fileName), 0o755); err != nil {
t.Logf("failed to create temp dir for generated code: %v", err)
return
}
if err := os.WriteFile(fileName, []byte(generated), 0644); err != nil {
t.Logf("failed to write generated code to %s: %v", fileName, err)
} else {
t.Logf("wrote generated code to %s", fileName)
}
})
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | package schema
import (
"bytes"
"context"
"encoding/json"
"fmt"
"path/filepath"
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/core/modules"
"github.com/dagger/dagger/dagql"
"github.com/dagger/dagger/engine"
"golang.org/x/sync/errgroup"
)
type moduleSchema struct {
dag *dagql.Server
}
var _ SchemaResolvers = &moduleSchema{}
func (s *moduleSchema) Install() {
dagql.Fields[*core.Query]{
dagql.Func("module", s.module).
Doc(`Create a new module.`),
dagql.Func("typeDef", s.typeDef).
Doc(`Create a new TypeDef.`),
dagql.Func("generatedCode", s.generatedCode).
Doc(`Create a code generation result, given a directory containing the generated code.`),
dagql.Func("moduleSource", s.moduleSource).
Doc(`Create a new module source instance from a source ref string.`). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | ArgDoc("refString", `The string ref representation of the module source`).
ArgDoc("stable", `If true, enforce that the source is a stable version for source kinds that support versioning.`),
dagql.Func("moduleDependency", s.moduleDependency).
Doc(`Create a new module dependency configuration from a module source and name`).
ArgDoc("source", `The source of the dependency`).
ArgDoc("name", `If set, the name to use for the dependency. Otherwise, once installed to a parent module, the name of the dependency module will be used by default.`),
dagql.Func("function", s.function).
Doc(`Creates a function.`).
ArgDoc("name", `Name of the function, in its original format from the implementation language.`).
ArgDoc("returnType", `Return type of the function.`),
dagql.Func("currentModule", s.currentModule).
Impure(`Changes depending on which module is calling it.`).
Doc(`The module currently being served in the session, if any.`),
dagql.Func("currentTypeDefs", s.currentTypeDefs).
Impure(`Changes depending on which modules are currently installed.`).
Doc(`The TypeDef representations of the objects currently being served in the session.`),
dagql.Func("currentFunctionCall", s.currentFunctionCall).
Impure(`Changes depending on which function calls it.`).
Doc(`The FunctionCall context that the SDK caller is currently executing in.`,
`If the caller is not currently executing in a function, this will
return an error.`),
}.Install(s.dag)
dagql.Fields[*core.Directory]{
dagql.NodeFunc("asModule", s.directoryAsModule).
Doc(`Load the directory as a Dagger module`).
ArgDoc("sourceRootPath",
`An optional subpath of the directory which contains the module's configuration file.`,
`This is needed when the module code is in a subdirectory but requires
parent directories to be loaded in order to execute. For example, the
module source code may need a go.mod, project.toml, package.json, etc. |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | file from a parent directory.`,
`If not set, the module source code is loaded from the root of the directory.`),
}.Install(s.dag)
dagql.Fields[*core.FunctionCall]{
dagql.Func("returnValue", s.functionCallReturnValue).
Impure(`Updates internal engine state with the given value.`).
Doc(`Set the return value of the function call to the provided value.`).
ArgDoc("value", `JSON serialization of the return value.`),
}.Install(s.dag)
dagql.Fields[*core.ModuleSource]{
dagql.Func("contextDirectory", s.moduleSourceContextDirectory).
Doc(`The directory containing everything needed to load load and use the module.`),
dagql.Func("withContextDirectory", s.moduleSourceWithContextDirectory).
Doc(`Update the module source with a new context directory. Only valid for local sources.`).
ArgDoc("dir", `The directory to set as the context directory.`),
dagql.Func("directory", s.moduleSourceDirectory).
Doc(`The directory containing the module configuration and source code (source code may be in a subdir).`).
ArgDoc(`path`, `The path from the source directory to select.`),
dagql.Func("sourceRootSubpath", s.moduleSourceRootSubpath).
Doc(`The path relative to context of the root of the module source, which contains dagger.json. It also contains the module implementation source code, but that may or may not being a subdir of this root.`),
dagql.Func("sourceSubpath", s.moduleSourceSubpath).
Doc(`The path relative to context of the module implementation source code.`),
dagql.Func("withSourceSubpath", s.moduleSourceWithSourceSubpath).
Doc(`Update the module source with a new source subpath.`).
ArgDoc("path", `The path to set as the source subpath.`),
dagql.Func("moduleName", s.moduleSourceModuleName).
Doc(`If set, the name of the module this source references, including any overrides at runtime by callers.`),
dagql.Func("moduleOriginalName", s.moduleSourceModuleOriginalName).
Doc(`The original name of the module this source references, as defined in the module configuration.`),
dagql.Func("withName", s.moduleSourceWithName). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Doc(`Update the module source with a new name.`).
ArgDoc("name", `The name to set.`),
dagql.NodeFunc("dependencies", s.moduleSourceDependencies).
Doc(`The dependencies of the module source. Includes dependencies from the configuration and any extras from withDependencies calls.`),
dagql.Func("withDependencies", s.moduleSourceWithDependencies).
Doc(`Append the provided dependencies to the module source's dependency list.`).
ArgDoc("dependencies", `The dependencies to append.`),
dagql.Func("withSDK", s.moduleSourceWithSDK).
Doc(`Update the module source with a new SDK.`).
ArgDoc("sdk", `The SDK to set.`),
dagql.Func("configExists", s.moduleSourceConfigExists).
Doc(`Returns whether the module source has a configuration file.`),
dagql.Func("resolveDependency", s.moduleSourceResolveDependency).
Doc(`Resolve the provided module source arg as a dependency relative to this module source.`).
ArgDoc("dep", `The dependency module source to resolve.`),
dagql.Func("asString", s.moduleSourceAsString).
Doc(`A human readable ref string representation of this module source.`),
dagql.NodeFunc("asModule", s.moduleSourceAsModule).
Doc(`Load the source as a module. If this is a local source, the parent directory must have been provided during module source creation`),
dagql.Func("resolveFromCaller", s.moduleSourceResolveFromCaller).
Impure(`Loads live caller-specific data from their filesystem.`).
Doc(`Load the source from its path on the caller's filesystem, including only needed+configured files and directories. Only valid for local sources.`),
dagql.Func("resolveContextPathFromCaller", s.moduleSourceResolveContextPathFromCaller).
Impure(`Queries live caller-specific data from their filesystem.`).
Doc(`The path to the module source's context directory on the caller's filesystem. Only valid for local sources.`),
}.Install(s.dag)
dagql.Fields[*core.LocalModuleSource]{}.Install(s.dag)
dagql.Fields[*core.GitModuleSource]{
dagql.Func("cloneURL", s.gitModuleSourceCloneURL).
Doc(`The URL from which the source's git repo can be cloned.`), |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | dagql.Func("htmlURL", s.gitModuleSourceHTMLURL).
Doc(`The URL to the source's git repo in a web browser`),
}.Install(s.dag)
dagql.Fields[*core.ModuleDependency]{}.Install(s.dag)
dagql.Fields[*core.Module]{
dagql.Func("withSource", s.moduleWithSource).
Doc(`Retrieves the module with basic configuration loaded if present.`).
ArgDoc("source", `The module source to initialize from.`),
dagql.Func("generatedContextDiff", s.moduleGeneratedContextDiff).
Doc(`The generated files and directories made on top of the module source's context directory.`),
dagql.NodeFunc("initialize", s.moduleInitialize).
Doc(`Retrieves the module with the objects loaded via its SDK.`),
dagql.Func("withDescription", s.moduleWithDescription).
Doc(`Retrieves the module with the given description`).
ArgDoc("description", `The description to set`),
dagql.Func("withObject", s.moduleWithObject).
Doc(`This module plus the given Object type and associated functions.`),
dagql.Func("withInterface", s.moduleWithInterface).
Doc(`This module plus the given Interface type and associated functions`),
dagql.NodeFunc("serve", s.moduleServe).
Impure(`Mutates the calling session's global schema.`).
Doc(`Serve a module's API in the current session.`,
`Note: this can only be called once per session. In the future, it could return a stream or service to remove the side effect.`),
}.Install(s.dag)
dagql.Fields[*core.CurrentModule]{
dagql.Func("name", s.currentModuleName).
Doc(`The name of the module being executed in`),
dagql.Func("source", s.currentModuleSource).
Doc(`The directory containing the module's source code loaded into the engine (plus any generated code that may have been created).`),
dagql.Func("workdir", s.currentModuleWorkdir). |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Impure(`Loads live caller-specific data from their filesystem.`).
Doc(`Load a directory from the module's scratch working directory, including any changes that may have been made to it during module function execution.`).
ArgDoc("path", `Location of the directory to access (e.g., ".").`).
ArgDoc("exclude", `Exclude artifacts that match the given pattern (e.g., ["node_modules/", ".git*"]).`).
ArgDoc("include", `Include only artifacts that match the given pattern (e.g., ["app/", "package.*"]).`),
dagql.Func("workdirFile", s.currentModuleWorkdirFile).
Impure(`Loads live caller-specific data from their filesystem.`).
Doc(`Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.Load a file from the module's scratch working directory, including any changes that may have been made to it during module function execution.`).
ArgDoc("path", `Location of the file to retrieve (e.g., "README.md").`),
}.Install(s.dag)
dagql.Fields[*core.Function]{
dagql.Func("withDescription", s.functionWithDescription).
Doc(`Returns the function with the given doc string.`).
ArgDoc("description", `The doc string to set.`),
dagql.Func("withArg", s.functionWithArg).
Doc(`Returns the function with the provided argument`).
ArgDoc("name", `The name of the argument`).
ArgDoc("typeDef", `The type of the argument`).
ArgDoc("description", `A doc string for the argument, if any`).
ArgDoc("defaultValue", `A default value to use for this argument if not explicitly set by the caller, if any`),
}.Install(s.dag)
dagql.Fields[*core.FunctionArg]{}.Install(s.dag)
dagql.Fields[*core.FunctionCallArgValue]{}.Install(s.dag)
dagql.Fields[*core.TypeDef]{
dagql.Func("withOptional", s.typeDefWithOptional).
Doc(`Sets whether this type can be set to null.`),
dagql.Func("withKind", s.typeDefWithKind).
Doc(`Sets the kind of the type.`),
dagql.Func("withListOf", s.typeDefWithListOf).
Doc(`Returns a TypeDef of kind List with the provided type for its elements.`), |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | dagql.Func("withObject", s.typeDefWithObject).
Doc(`Returns a TypeDef of kind Object with the provided name.`,
`Note that an object's fields and functions may be omitted if the
intent is only to refer to an object. This is how functions are able to
return their own object, or any other circular reference.`),
dagql.Func("withInterface", s.typeDefWithInterface).
Doc(`Returns a TypeDef of kind Interface with the provided name.`),
dagql.Func("withField", s.typeDefWithObjectField).
Doc(`Adds a static field for an Object TypeDef, failing if the type is not an object.`).
ArgDoc("name", `The name of the field in the object`).
ArgDoc("typeDef", `The type of the field`).
ArgDoc("description", `A doc string for the field, if any`),
dagql.Func("withFunction", s.typeDefWithFunction).
Doc(`Adds a function for an Object or Interface TypeDef, failing if the type is not one of those kinds.`),
dagql.Func("withConstructor", s.typeDefWithObjectConstructor).
Doc(`Adds a function for constructing a new instance of an Object TypeDef, failing if the type is not an object.`),
}.Install(s.dag)
dagql.Fields[*core.ObjectTypeDef]{}.Install(s.dag)
dagql.Fields[*core.InterfaceTypeDef]{}.Install(s.dag)
dagql.Fields[*core.InputTypeDef]{}.Install(s.dag)
dagql.Fields[*core.FieldTypeDef]{}.Install(s.dag)
dagql.Fields[*core.ListTypeDef]{}.Install(s.dag)
dagql.Fields[*core.GeneratedCode]{
dagql.Func("withVCSGeneratedPaths", s.generatedCodeWithVCSGeneratedPaths).
Doc(`Set the list of paths to mark generated in version control.`),
dagql.Func("withVCSIgnoredPaths", s.generatedCodeWithVCSIgnoredPaths).
Doc(`Set the list of paths to ignore in version control.`),
}.Install(s.dag)
}
func (s *moduleSchema) typeDef(ctx context.Context, _ *core.Query, args struct{}) (*core.TypeDef, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | return &core.TypeDef{}, nil
}
func (s *moduleSchema) typeDefWithOptional(ctx context.Context, def *core.TypeDef, args struct {
Optional bool
}) (*core.TypeDef, error) {
return def.WithOptional(args.Optional), nil
}
func (s *moduleSchema) typeDefWithKind(ctx context.Context, def *core.TypeDef, args struct {
Kind core.TypeDefKind
}) (*core.TypeDef, error) {
return def.WithKind(args.Kind), nil
}
func (s *moduleSchema) typeDefWithListOf(ctx context.Context, def *core.TypeDef, args struct {
ElementType core.TypeDefID
}) (*core.TypeDef, error) {
elemType, err := args.ElementType.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode element type: %w", err)
}
return def.WithListOf(elemType.Self), nil
}
func (s *moduleSchema) typeDefWithObject(ctx context.Context, def *core.TypeDef, args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Name string
Description string `default:""`
}) (*core.TypeDef, error) {
if args.Name == "" {
return nil, fmt.Errorf("object type def must have a name")
}
return def.WithObject(args.Name, args.Description), nil
}
func (s *moduleSchema) typeDefWithInterface(ctx context.Context, def *core.TypeDef, args struct {
Name string
Description string `default:""`
}) (*core.TypeDef, error) {
return def.WithInterface(args.Name, args.Description), nil
}
func (s *moduleSchema) typeDefWithObjectField(ctx context.Context, def *core.TypeDef, args struct {
Name string
TypeDef core.TypeDefID
Description string `default:""`
}) (*core.TypeDef, error) {
fieldType, err := args.TypeDef.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode element type: %w", err)
}
return def.WithObjectField(args.Name, fieldType.Self, args.Description)
}
func (s *moduleSchema) typeDefWithFunction(ctx context.Context, def *core.TypeDef, args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Function core.FunctionID
}) (*core.TypeDef, error) {
fn, err := args.Function.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode element type: %w", err)
}
return def.WithFunction(fn.Self)
}
func (s *moduleSchema) typeDefWithObjectConstructor(ctx context.Context, def *core.TypeDef, args struct {
Function core.FunctionID
}) (*core.TypeDef, error) {
inst, err := args.Function.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode element type: %w", err)
}
fn := inst.Self.Clone()
fn.Name = ""
fn.OriginalName = ""
return def.WithObjectConstructor(fn)
}
func (s *moduleSchema) generatedCode(ctx context.Context, _ *core.Query, args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Code core.DirectoryID
}) (*core.GeneratedCode, error) {
dir, err := args.Code.Load(ctx, s.dag)
if err != nil {
return nil, err
}
return core.NewGeneratedCode(dir), nil
}
func (s *moduleSchema) generatedCodeWithVCSGeneratedPaths(ctx context.Context, code *core.GeneratedCode, args struct {
Paths []string
}) (*core.GeneratedCode, error) {
return code.WithVCSGeneratedPaths(args.Paths), nil
}
func (s *moduleSchema) generatedCodeWithVCSIgnoredPaths(ctx context.Context, code *core.GeneratedCode, args struct {
Paths []string
}) (*core.GeneratedCode, error) {
return code.WithVCSIgnoredPaths(args.Paths), nil
}
func (s *moduleSchema) module(ctx context.Context, query *core.Query, _ struct{}) (*core.Module, error) {
return query.NewModule(), nil
}
func (s *moduleSchema) function(ctx context.Context, _ *core.Query, args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Name string
ReturnType core.TypeDefID
}) (*core.Function, error) {
returnType, err := args.ReturnType.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode return type: %w", err)
}
return core.NewFunction(args.Name, returnType.Self), nil
}
func (s *moduleSchema) functionWithDescription(ctx context.Context, fn *core.Function, args struct {
Description string
}) (*core.Function, error) {
return fn.WithDescription(args.Description), nil
}
func (s *moduleSchema) functionWithArg(ctx context.Context, fn *core.Function, args struct {
Name string
TypeDef core.TypeDefID
Description string `default:""`
DefaultValue core.JSON `default:""`
}) (*core.Function, error) {
argType, err := args.TypeDef.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode arg type: %w", err)
}
return fn.WithArg(args.Name, argType.Self, args.Description, args.DefaultValue), nil
}
func (s *moduleSchema) moduleDependency(
ctx context.Context,
query *core.Query,
args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Source core.ModuleSourceID
Name string `default:""`
},
) (*core.ModuleDependency, error) {
src, err := args.Source.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode dependency source: %w", err)
}
return &core.ModuleDependency{
Source: src,
Name: args.Name,
}, nil
}
func (s *moduleSchema) currentModule(
ctx context.Context,
self *core.Query,
_ struct{}, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | ) (*core.CurrentModule, error) {
mod, err := self.CurrentModule(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current module: %w", err)
}
return &core.CurrentModule{Module: mod}, nil
}
func (s *moduleSchema) currentFunctionCall(ctx context.Context, self *core.Query, _ struct{}) (*core.FunctionCall, error) {
return self.CurrentFunctionCall(ctx)
}
func (s *moduleSchema) moduleServe(ctx context.Context, modMeta dagql.Instance[*core.Module], _ struct{}) (dagql.Nullable[core.Void], error) {
return dagql.Null[core.Void](), modMeta.Self.Query.ServeModuleToMainClient(ctx, modMeta)
}
func (s *moduleSchema) currentTypeDefs(ctx context.Context, self *core.Query, _ struct{}) ([]*core.TypeDef, error) {
deps, err := self.CurrentServedDeps(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get current module: %w", err)
}
return deps.TypeDefs(ctx)
}
func (s *moduleSchema) functionCallReturnValue(ctx context.Context, fnCall *core.FunctionCall, args struct {
Value core.JSON
}) (dagql.Nullable[core.Void], error) {
return dagql.Null[core.Void](), fnCall.ReturnValue(ctx, args.Value)
}
func (s *moduleSchema) moduleWithDescription(ctx context.Context, mod *core.Module, args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Description string
}) (*core.Module, error) {
return mod.WithDescription(args.Description), nil
}
func (s *moduleSchema) moduleWithObject(ctx context.Context, mod *core.Module, args struct {
Object core.TypeDefID
}) (_ *core.Module, rerr error) {
def, err := args.Object.Load(ctx, s.dag)
if err != nil {
return nil, err
}
return mod.WithObject(ctx, def.Self)
}
func (s *moduleSchema) moduleWithInterface(ctx context.Context, mod *core.Module, args struct {
Iface core.TypeDefID
}) (_ *core.Module, rerr error) {
def, err := args.Iface.Load(ctx, s.dag)
if err != nil {
return nil, err
}
return mod.WithInterface(ctx, def.Self)
}
func (s *moduleSchema) currentModuleName(
ctx context.Context,
curMod *core.CurrentModule,
args struct{}, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | ) (string, error) {
return curMod.Module.Name(), nil
}
func (s *moduleSchema) currentModuleSource(
ctx context.Context,
curMod *core.CurrentModule,
args struct{},
) (inst dagql.Instance[*core.Directory], err error) {
srcSubpath, err := curMod.Module.Source.Self.SourceSubpathWithDefault(ctx)
if err != nil {
return inst, fmt.Errorf("failed to get module source subpath: %w", err)
}
err = s.dag.Select(ctx, curMod.Module.GeneratedContextDirectory, &inst,
dagql.Selector{
Field: "directory",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(srcSubpath)},
},
},
)
return inst, err
}
func (s *moduleSchema) currentModuleWorkdir(
ctx context.Context,
curMod *core.CurrentModule,
args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Path string
core.CopyFilter
},
) (inst dagql.Instance[*core.Directory], err error) {
if !filepath.IsLocal(args.Path) {
return inst, fmt.Errorf("workdir path %q escapes workdir", args.Path)
}
args.Path = filepath.Join(runtimeWorkdirPath, args.Path)
err = s.dag.Select(ctx, s.dag.Root(), &inst,
dagql.Selector{
Field: "host",
},
dagql.Selector{
Field: "directory",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(args.Path)},
{Name: "exclude", Value: asArrayInput(args.Exclude, dagql.NewString)},
{Name: "include", Value: asArrayInput(args.Include, dagql.NewString)},
},
},
)
return inst, err
}
func (s *moduleSchema) currentModuleWorkdirFile(
ctx context.Context,
curMod *core.CurrentModule,
args struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Path string
},
) (inst dagql.Instance[*core.File], err error) {
if !filepath.IsLocal(args.Path) {
return inst, fmt.Errorf("workdir path %q escapes workdir", args.Path)
}
args.Path = filepath.Join(runtimeWorkdirPath, args.Path)
err = s.dag.Select(ctx, s.dag.Root(), &inst,
dagql.Selector{
Field: "host",
},
dagql.Selector{
Field: "file",
Args: []dagql.NamedInput{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | {Name: "path", Value: dagql.String(args.Path)},
},
},
)
return inst, err
}
type directoryAsModuleArgs struct {
SourceRootPath string `default:"."`
}
func (s *moduleSchema) directoryAsModule(ctx context.Context, contextDir dagql.Instance[*core.Directory], args directoryAsModuleArgs) (*core.Module, error) {
var inst dagql.Instance[*core.Module]
err := s.dag.Select(ctx, s.dag.Root(), &inst,
dagql.Selector{
Field: "moduleSource",
Args: []dagql.NamedInput{
{Name: "refString", Value: dagql.String(args.SourceRootPath)},
},
},
dagql.Selector{
Field: "withContextDirectory",
Args: []dagql.NamedInput{
{Name: "dir", Value: dagql.NewID[*core.Directory](contextDir.ID())},
},
},
dagql.Selector{
Field: "asModule",
},
)
if err != nil {
return nil, fmt.Errorf("failed to create module from directory: %w", err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | }
return inst.Self, nil
}
func (s *moduleSchema) moduleInitialize(
ctx context.Context,
inst dagql.Instance[*core.Module],
args struct{},
) (*core.Module, error) {
if inst.Self.NameField == "" || inst.Self.SDKConfig == "" {
return nil, fmt.Errorf("module name and SDK must be set")
}
mod, err := inst.Self.Initialize(ctx, inst, dagql.CurrentID(ctx))
if err != nil {
return nil, fmt.Errorf("failed to initialize module: %w", err)
}
return mod, nil
}
func (s *moduleSchema) moduleWithSource(ctx context.Context, mod *core.Module, args struct {
Source core.ModuleSourceID
}) (*core.Module, error) {
src, err := args.Source.Load(ctx, s.dag)
if err != nil {
return nil, fmt.Errorf("failed to decode module source: %w", err)
}
mod = mod.Clone()
mod.Source = src
mod.NameField, err = src.Self.ModuleName(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get module name: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | mod.OriginalName, err = src.Self.ModuleOriginalName(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get module original name: %w", err)
}
mod.SDKConfig, err = src.Self.SDK(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get module SDK: %w", err)
}
if err := s.updateDeps(ctx, mod, src); err != nil {
return nil, fmt.Errorf("failed to update module dependencies: %w", err)
}
if err := s.updateCodegenAndRuntime(ctx, mod, src); err != nil {
return nil, fmt.Errorf("failed to update codegen and runtime: %w", err)
}
if err := s.updateDaggerConfig(ctx, mod, src); err != nil {
return nil, fmt.Errorf("failed to update dagger.json: %w", err)
}
return mod, nil
}
func (s *moduleSchema) moduleGeneratedContextDiff(
ctx context.Context,
mod *core.Module,
args struct{},
) (inst dagql.Instance[*core.Directory], err error) {
baseContext, err := mod.Source.Self.ContextDirectory()
if err != nil {
return inst, fmt.Errorf("failed to get base context directory: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | var diff dagql.Instance[*core.Directory]
err = s.dag.Select(ctx, baseContext, &diff,
dagql.Selector{
Field: "diff",
Args: []dagql.NamedInput{
{Name: "other", Value: dagql.NewID[*core.Directory](mod.GeneratedContextDirectory.ID())},
},
},
)
if err != nil {
return inst, fmt.Errorf("failed to diff generated context: %w", err)
}
return diff, nil
}
func (s *moduleSchema) updateDeps(
ctx context.Context,
mod *core.Module,
src dagql.Instance[*core.ModuleSource],
) error {
var deps []dagql.Instance[*core.ModuleDependency]
err := s.dag.Select(ctx, src, &deps, dagql.Selector{Field: "dependencies"})
if err != nil {
return fmt.Errorf("failed to load module dependencies: %w", err)
}
mod.DependencyConfig = make([]*core.ModuleDependency, len(deps))
for i, dep := range deps {
_, cfgExists, err := dep.Self.Source.Self.ModuleConfig(ctx)
if err != nil {
return fmt.Errorf("failed to load module %q dependency %q config: %w", mod.NameField, dep.Self.Name, err) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | }
if !cfgExists {
sourceRootPath, _ := dep.Self.Source.Self.SourceRootSubpath()
return fmt.Errorf("module %q dependency %q with source root path %q does not exist or does not have a configuration file", mod.NameField, dep.Self.Name, sourceRootPath)
}
mod.DependencyConfig[i] = dep.Self
}
mod.DependenciesField = make([]dagql.Instance[*core.Module], len(deps))
var eg errgroup.Group
for i, dep := range deps {
i, dep := i, dep
eg.Go(func() error {
err := s.dag.Select(ctx, dep.Self.Source, &mod.DependenciesField[i],
dagql.Selector{
Field: "withName",
Args: []dagql.NamedInput{
{Name: "name", Value: dagql.String(dep.Self.Name)},
},
},
dagql.Selector{
Field: "asModule",
},
dagql.Selector{
Field: "initialize",
},
)
if err != nil {
return fmt.Errorf("failed to initialize dependency module: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | return nil
})
}
if err := eg.Wait(); err != nil {
return fmt.Errorf("failed to initialize dependency modules: %w", err)
}
mod.Deps = core.NewModDeps(src.Self.Query, src.Self.Query.DefaultDeps.Mods)
for _, dep := range mod.DependenciesField {
mod.Deps = mod.Deps.Append(dep.Self)
}
return nil
}
func (s *moduleSchema) updateCodegenAndRuntime(
ctx context.Context,
mod *core.Module,
src dagql.Instance[*core.ModuleSource],
) error {
if mod.NameField == "" || mod.SDKConfig == "" {
return nil
}
baseContext, err := src.Self.ContextDirectory()
if err != nil {
return fmt.Errorf("failed to get base context directory: %w", err)
}
mod.GeneratedContextDirectory = baseContext
rootSubpath, err := src.Self.SourceRootSubpath()
if err != nil {
return fmt.Errorf("failed to get source root subpath: %w", err)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | sdk, err := s.sdkForModule(ctx, src.Self.Query, mod.SDKConfig, src)
if err != nil {
return fmt.Errorf("failed to load sdk for module: %w", err)
}
generatedCode, err := sdk.Codegen(ctx, mod.Deps, src)
if err != nil {
return fmt.Errorf("failed to generate code: %w", err)
}
var diff dagql.Instance[*core.Directory]
err = s.dag.Select(ctx, baseContext, &diff,
dagql.Selector{
Field: "diff",
Args: []dagql.NamedInput{
{Name: "other", Value: dagql.NewID[*core.Directory](generatedCode.Code.ID())},
},
},
)
if err != nil {
return fmt.Errorf("failed to diff generated code: %w", err)
}
err = s.dag.Select(ctx, mod.GeneratedContextDirectory, &mod.GeneratedContextDirectory,
dagql.Selector{
Field: "withDirectory",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String("/")},
{Name: "directory", Value: dagql.NewID[*core.Directory](diff.ID())},
},
},
)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | return fmt.Errorf("failed to add codegen to module context directory: %w", err)
}
if len(generatedCode.VCSGeneratedPaths) > 0 {
gitAttrsPath := filepath.Join(rootSubpath, ".gitattributes")
var gitAttrsContents []byte
gitAttrsFile, err := baseContext.Self.File(ctx, gitAttrsPath)
if err == nil {
gitAttrsContents, err = gitAttrsFile.Contents(ctx)
if err != nil {
return fmt.Errorf("failed to get git attributes file contents: %w", err)
}
if !bytes.HasSuffix(gitAttrsContents, []byte("\n")) {
gitAttrsContents = append(gitAttrsContents, []byte("\n")...)
}
}
for _, fileName := range generatedCode.VCSGeneratedPaths {
if bytes.Contains(gitAttrsContents, []byte(fileName)) {
continue
}
gitAttrsContents = append(gitAttrsContents,
[]byte(fmt.Sprintf("/%s linguist-generated\n", fileName))...,
)
}
err = s.dag.Select(ctx, mod.GeneratedContextDirectory, &mod.GeneratedContextDirectory,
dagql.Selector{
Field: "withNewFile", |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(gitAttrsPath)},
{Name: "contents", Value: dagql.String(gitAttrsContents)},
{Name: "permissions", Value: dagql.Int(0600)},
},
},
)
if err != nil {
return fmt.Errorf("failed to add vcs generated file: %w", err)
}
}
if len(generatedCode.VCSIgnoredPaths) > 0 {
gitIgnorePath := filepath.Join(rootSubpath, ".gitignore")
var gitIgnoreContents []byte
gitIgnoreFile, err := baseContext.Self.File(ctx, gitIgnorePath)
if err == nil {
gitIgnoreContents, err = gitIgnoreFile.Contents(ctx)
if err != nil {
return fmt.Errorf("failed to get .gitignore file contents: %w", err)
}
if !bytes.HasSuffix(gitIgnoreContents, []byte("\n")) {
gitIgnoreContents = append(gitIgnoreContents, []byte("\n")...)
}
}
for _, fileName := range generatedCode.VCSIgnoredPaths {
if bytes.Contains(gitIgnoreContents, []byte(fileName)) {
continue |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | }
gitIgnoreContents = append(gitIgnoreContents,
[]byte(fmt.Sprintf("/%s\n", fileName))...,
)
}
err = s.dag.Select(ctx, mod.GeneratedContextDirectory, &mod.GeneratedContextDirectory,
dagql.Selector{
Field: "withNewFile",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(gitIgnorePath)},
{Name: "contents", Value: dagql.String(gitIgnoreContents)},
{Name: "permissions", Value: dagql.Int(0600)},
},
},
)
if err != nil {
return fmt.Errorf("failed to add vcs ignore file: %w", err)
}
}
mod.Runtime, err = sdk.Runtime(ctx, mod.Deps, src)
if err != nil {
return fmt.Errorf("failed to get module runtime: %w", err)
}
return nil
}
func (s *moduleSchema) updateDaggerConfig(
ctx context.Context,
mod *core.Module,
src dagql.Instance[*core.ModuleSource],
) error { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | modCfg, ok, err := src.Self.ModuleConfig(ctx)
if err != nil {
return fmt.Errorf("failed to get module config: %w", err)
}
if !ok {
modCfg = &modules.ModuleConfig{}
}
modCfg.Name = mod.OriginalName
modCfg.SDK = mod.SDKConfig
modCfg.EngineVersion = engine.Version
sourceRootSubpath, err := src.Self.SourceRootSubpath()
if err != nil {
return fmt.Errorf("failed to get source root subpath: %w", err)
}
sourceSubpath, err := src.Self.SourceSubpathWithDefault(ctx)
if err != nil {
return fmt.Errorf("failed to get source subpath: %w", err)
}
sourceRelSubpath, err := filepath.Rel(sourceRootSubpath, sourceSubpath)
if err != nil {
return fmt.Errorf("failed to get relative source subpath: %w", err)
}
if sourceRelSubpath != "." {
modCfg.Source = sourceRelSubpath
}
modCfg.Dependencies = make([]*modules.ModuleConfigDependency, len(mod.DependencyConfig))
for i, dep := range mod.DependencyConfig {
var srcStr string
switch dep.Source.Self.Kind {
case core.ModuleSourceKindLocal: |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | depRootSubpath, err := dep.Source.Self.SourceRootSubpath()
if err != nil {
return fmt.Errorf("failed to get source root subpath: %w", err)
}
depRelPath, err := filepath.Rel(sourceRootSubpath, depRootSubpath)
if err != nil {
return fmt.Errorf("failed to get relative path to dep: %w", err)
}
srcStr = depRelPath
case core.ModuleSourceKindGit:
srcStr = dep.Source.Self.AsGitSource.Value.RefString()
default:
return fmt.Errorf("unsupported dependency source kind: %s", dep.Source.Self.Kind)
}
depName := dep.Name
if dep.Name == "" {
depName = mod.DependenciesField[i].Self.Name()
}
modCfg.Dependencies[i] = &modules.ModuleConfigDependency{
Name: depName,
Source: srcStr,
}
}
rootSubpath, err := src.Self.SourceRootSubpath()
if err != nil {
return fmt.Errorf("failed to get source root subpath: %w", err)
}
modCfgPath := filepath.Join(rootSubpath, modules.Filename) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,625 | π Modules: generated .gitxxx files are put next do dagger.json rather than on source path | Follow-up from:
- https://github.com/dagger/dagger/pull/6575
For example, in our root:
```
dagger init --sdk=python --source=dev
```
This will add, or overwrite, .gitattributes and .gitignore with `/sdk`, when it's actually in `dev/sdk`.
Everytime I do `dagger develop`, these files get overwritten.
\cc @sipsma | https://github.com/dagger/dagger/issues/6625 | https://github.com/dagger/dagger/pull/6699 | 4a04803cfb834c39b39ef7bac57fcf7b74c35d38 | 77a53a85956942540fb2078ef490ac8eeac56e0e | "2024-02-08T19:20:56Z" | go | "2024-02-20T14:01:32Z" | core/schema/module.go | updatedModCfgBytes, err := json.MarshalIndent(modCfg, "", " ")
if err != nil {
return fmt.Errorf("failed to encode module config: %w", err)
}
updatedModCfgBytes = append(updatedModCfgBytes, '\n')
if mod.GeneratedContextDirectory.Self == nil {
err = s.dag.Select(ctx, s.dag.Root(), &mod.GeneratedContextDirectory,
dagql.Selector{Field: "directory"},
)
if err != nil {
return fmt.Errorf("failed to initialize module context directory: %w", err)
}
}
err = s.dag.Select(ctx, mod.GeneratedContextDirectory, &mod.GeneratedContextDirectory,
dagql.Selector{
Field: "withNewFile",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(modCfgPath)},
{Name: "contents", Value: dagql.String(updatedModCfgBytes)},
{Name: "permissions", Value: dagql.Int(0644)},
},
},
)
if err != nil {
return fmt.Errorf("failed to update module context directory config file: %w", err)
}
return nil
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | package main
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"dagger.iodagger"
"dagger.iodaggerquerybuilder"
"github.comdaggerdaggerdagqlidtui"
"github.comdaggerdaggerengineclient"
"github.comjujuansitermtabwriter"
"github.commueslitermenv"
"github.comspf13cobra"
"github.comspf13pflag"
"github.comvitoprogrock"
)
const (
Directory string = "Directory"
Container string = "Container"
File string = "File"
Secret string = "Secret"
Service string = "Service"
Terminal string = "Terminal"
PortForward string = "PortForward"
CacheVolume string = "CacheVolume"
)
var funcGroup = &cobra.Group{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | ID: "functions",
Title: "Function Commands",
}
var funcCmds = FuncCommands{
funcListCmd,
callCmd,
}
var funcListCmd = &FuncCommand{
Name: "functions [flags] [FUNCTION]...",
Short: `List available functions`,
Long: strings.ReplaceAll(`List available functions in a module.
This is similar to Β΄dagger call --helpΒ΄, but only focused on showing the
available functions.
`,
"Β΄",
"`",
),
Execute: func(fc *FuncCommand, cmd *cobra.Command) error {
tw := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 3, ' ', tabwriter.DiscardEmptyColumns)
var o functionProvider = fc.mod.GetMainObject()
fmt.Fprintf(tw, "%s\t%s\n",
termenv.String("Name").Bold(),
termenv.String("Description").Bold(),
)
for _, field := range cmd.Flags().Args() {
nextFunc, err := o.GetFunction(field)
if err != nil {
return err |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | }
nextType := nextFunc.ReturnType
if nextType.AsFunctionProvider() != nil {
o = fc.mod.GetFunctionProvider(nextType.Name())
continue
}
return fmt.Errorf("function '%s' returns non-object type %v", field, nextType.Kind)
}
fns := o.GetFunctions()
sort.Slice(fns, func(i, j int) bool {
return fns[i].Name < fns[j].Name
})
for _, fn := range fns {
desc := strings.SplitN(fn.Description, "\n", 2)[0]
if desc == "" {
desc = "-"
}
fmt.Fprintf(tw, "%s\t%s\n", |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | cliName(fn.Name),
desc,
)
}
return tw.Flush()
},
}
type FuncCommands []*FuncCommand
func (fcs FuncCommands) AddFlagSet(flags *pflag.FlagSet) {
for _, cmd := range fcs.All() {
cmd.PersistentFlags().AddFlagSet(flags)
}
}
func (fcs FuncCommands) AddParent(rootCmd *cobra.Command) {
rootCmd.AddCommand(fcs.All()...)
}
func (fcs FuncCommands) All() []*cobra.Command {
cmds := make([]*cobra.Command, len(fcs))
for i, fc := range fcs {
cmds[i] = fc.Command()
}
return cmds
}
func setCmdOutput(cmd *cobra.Command, vtx *progrock.VertexRecorder) {
cmd.SetOut(vtx.Stdout())
cmd.SetErr(vtx.Stderr())
}
FuncCommand is a config object used to create a dynamic set of commands
for querying a module's functions.
type FuncCommand struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | The name of the command (or verb), as shown in usage.
Name string
Aliases is an array of aliases that can be used instead of the first word in Use. |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | Aliases []string
Short is the short description shown in the 'help' output.
Short string
Long is the long message shown in the 'help <this-command>' output.
Long string
Example is examples of how to use the command.
Example string
Init is called when the command is created and initialized,
before execution.
It can be useful to add persistent flags for all subcommands here.
Init func(*cobra.Command)
Execute circumvents the default behavior of traversing subcommands
from the arguments, but still has access to the loaded objects from
the module.
Execute func(*FuncCommand, *cobra.Command) error
BeforeParse is called before parsing the flags for a subcommand.
It can be useful to add any additional flags for a subcommand here.
BeforeParse func(*FuncCommand, *cobra.Command, *modFunction) error
OnSelectObjectLeaf is called when a user provided command ends in a
object and no more sub-commands are provided.
If set, it should make another selection on the object that results
return no error. Otherwise if it doesn't handle the object, it should
return an error.
OnSelectObjectLeaf func(*FuncCommand, string) error
BeforeRequest is called before making the request with the query that
contains the whole chain of functions. |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | It can be useful to validate the return type of the function or as a
last effort to select a GraphQL sub-field.
BeforeRequest func(*FuncCommand, *cobra.Command, *modTypeDef) error
AfterResponse is called when the query has completed and returned a result.
AfterResponse func(*FuncCommand, *cobra.Command, *modTypeDef, any) error
cmd is the parent cobra command.
cmd *cobra.Command
mod is the loaded module definition.
mod *moduleDef
showHelp is set in the loader vertex to flag whether to show the help
in the execution vertex.
showHelp bool
showUsage flags whether to show a one-line usage message after error.
showUsage bool
q *querybuilder.Selection
c *client.Client
}
func (fc *FuncCommand) Command() *cobra.Command {
if fc.cmd == nil {
fc.cmd = &cobra.Command{
Use: fc.Name,
Aliases: fc.Aliases,
Short: fc.Short,
Long: fc.Long,
Example: fc.Example,
GroupID: moduleGroup.ID,
Annotations: map[string]string{
"experimental": "",
}, |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | DisableFlagParsing: true,
DisableFlagsInUseLine: true,
PreRunE: func(c *cobra.Command, a []string) error {
c.DisableFlagParsing = false
c.Flags().SetInterspersed(false)
c.SetGlobalNormalizationFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
return pflag.NormalizedName(cliName(name))
})
c.FParseErrWhitelist.UnknownFlags = true
if err := c.ParseFlags(a); err != nil {
return c.FlagErrorFunc()(c, err)
}
c.FParseErrWhitelist.UnknownFlags = false |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | fc.showHelp, _ = c.Flags().GetBool("help")
return nil
},
RunE: func(c *cobra.Command, a []string) error {
return withEngineAndTUI(c.Context(), client.Params{}, func(ctx context.Context, engineClient *client.Client) (rerr error) {
fc.c = engineClient
c.SetContext(ctx)
c.SilenceErrors = true
return fc.execute(c, a)
})
},
}
if fc.Init != nil {
fc.Init(fc.cmd)
}
}
return fc.cmd
}
func (fc *FuncCommand) execute(c *cobra.Command, a []string) (rerr error) {
ctx := c.Context()
rec := progrock.FromContext(ctx)
var primaryVtx *progrock.VertexRecorder
var cmd *cobra.Command
The following is a little complicated because it needs to handle the case
where we fail to load the modules or parse the CLI. |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | In the happy path we want to initialize the PrimaryVertex with the parsed
command string, but we can't have that until we load the command.
So we just detect if we failed before getting to that point and fall back
to the outer command.
defer func() {
if cmd == nil {
cmd = c
}
if primaryVtx == nil {
primaryVtx = rec.Vertex(idtui.PrimaryVertex, cmd.CommandPath())
defer func() { primaryVtx.Done(rerr) }()
setCmdOutput(cmd, primaryVtx)
}
if ctx.Err() != nil {
cmd.PrintErrln("Canceled.")
} else if rerr != nil {
cmd.PrintErrln("Error:", rerr.Error())
if fc.showHelp {
cmd.Help()
}
if fc.showUsage {
cmd.PrintErrf("Run '%v --help' for usage.\n", cmd.CommandPath())
}
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | }()
Load the command, which may fail if modules are broken.
cmd, flags, err := fc.load(c, a)
if err != nil {
return err
}
Ok, we've loaded the command, now we can initialize the PrimaryVertex.
primaryVtx = rec.Vertex(idtui.PrimaryVertex, cmd.CommandPath())
defer func() { primaryVtx.Done(rerr) }()
setCmdOutput(cmd, primaryVtx)
if fc.showHelp {
if cmd != c {
cmd.Aliases = nil
}
return cmd.Help()
}
There should be no args left, if there are it's an unknown command.
if err := cobra.NoArgs(cmd, flags); err != nil {
return err
}
if fc.Execute != nil {
return fc.Execute(fc, cmd)
}
No args to the parent command, default to showing help.
if cmd == c {
return cmd.Help()
}
err = cmd.RunE(cmd, flags) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | if err != nil {
return err
}
return nil
}
func (fc *FuncCommand) load(c *cobra.Command, a []string) (cmd *cobra.Command, _ []string, rerr error) {
ctx := c.Context()
dag := fc.c.Dagger()
modConf, err := getDefaultModuleConfiguration(ctx, dag, true)
if err != nil {
return nil, nil, fmt.Errorf("failed to get configured module: %w", err)
}
if !modConf.FullyInitialized() {
return nil, nil, fmt.Errorf("module at source dir %q doesn't exist or is invalid", modConf.LocalRootSourcePath)
}
mod := modConf.Source.AsModule().Initialize()
_, err = mod.Serve(ctx)
if err != nil {
return nil, nil, err
}
modDef, err := loadModTypeDefs(ctx, dag, mod)
if err != nil {
return nil, nil, err
}
obj := modDef.GetMainObject()
if obj == nil {
return nil, nil, fmt.Errorf("main object not found")
}
fc.mod = modDef
if fc.Execute != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | return c, nil, nil
}
if obj.Constructor != nil {
if err := fc.addArgsForFunction(c, a, obj.Constructor, dag); err != nil {
return nil, nil, err
}
fc.selectFunc(obj.Name, obj.Constructor, c, dag)
} else {
fc.Select(obj.Name)
}
Add main object's functions as subcommands
fc.addSubCommands(c, dag, obj)
if fc.showHelp {
return c, nil, nil
}
cmd, flags, err := fc.traverse(c)
if err != nil {
if errors.Is(err, pflag.ErrHelp) {
fc.showHelp = true
return cmd, flags, nil
}
fc.showUsage = true
return cmd, flags, err
}
return cmd, flags, nil
}
traverse the arguments to build the command tree and return the leaf command.
func (fc *FuncCommand) traverse(c *cobra.Command) (*cobra.Command, []string, error) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | cmd, args, err := c.Find(c.Flags().Args())
if err != nil {
return cmd, args, err
}
Leaf command
if cmd == c {
return cmd, args, nil
}
cmd.SetContext(c.Context())
cmd.InitDefaultHelpFlag()
Load and ParseFlags
err = cmd.PreRunE(cmd, args)
if err != nil {
return cmd, args, err
}
return fc.traverse(cmd)
}
func (fc *FuncCommand) addSubCommands(cmd *cobra.Command, dag *dagger.Client, fnProvider functionProvider) {
if fnProvider != nil {
cmd.AddGroup(funcGroup)
for _, fn := range fnProvider.GetFunctions() {
subCmd := fc.makeSubCmd(dag, fn)
cmd.AddCommand(subCmd)
}
}
}
func (fc *FuncCommand) makeSubCmd(dag *dagger.Client, fn *modFunction) *cobra.Command {
newCmd := &cobra.Command{
Use: cliName(fn.Name),
Short: strings.SplitN(fn.Description, "\n", 2)[0], |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | Long: fn.Description,
GroupID: funcGroup.ID,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
if err := fc.addArgsForFunction(cmd, args, fn, dag); err != nil {
return err
}
fnProvider := fn.ReturnType.AsFunctionProvider()
if fnProvider == nil && fn.ReturnType.AsList != nil {
fnProvider = fn.ReturnType.AsList.ElementTypeDef.AsFunctionProvider()
}
fc.addSubCommands(cmd, dag, fnProvider)
help, _ := cmd.Flags().GetBool("help")
if help {
return pflag.ErrHelp
}
return fc.selectFunc(fn.Name, fn, cmd, dag)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
switch fn.ReturnType.Kind {
case dagger.ObjectKind, dagger.InterfaceKind:
if fc.OnSelectObjectLeaf == nil {
fc.showUsage = true
return fmt.Errorf("%q requires a sub-command", cmd.Name())
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | err := fc.OnSelectObjectLeaf(fc, fn.ReturnType.Name())
if err != nil {
fc.showUsage = true
return fmt.Errorf("invalid selection for command %q: %w", cmd.Name(), err)
}
case dagger.ListKind:
fnProvider := fn.ReturnType.AsList.ElementTypeDef.AsFunctionProvider()
if fnProvider != nil && len(fnProvider.GetFunctions()) > 0 {
fc.showUsage = true
return fmt.Errorf("%q requires a sub-command", cmd.Name())
}
}
if fc.BeforeRequest != nil {
if err = fc.BeforeRequest(fc, cmd, fn.ReturnType); err != nil {
return err
}
}
ctx := cmd.Context()
query, _ := fc.q.Build(ctx)
rec := progrock.FromContext(ctx)
rec.Debug("executing", progrock.Labelf("query", "%+v", query))
var response any
q := fc.q.Bind(&response)
if err := q.Execute(ctx, dag.Client); err != nil {
return fmt.Errorf("response from query: %w", err)
}
if fc.AfterResponse != nil {
return fc.AfterResponse(fc, cmd, fn.ReturnType, response)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | if fn.ReturnType.Kind != dagger.VoidKind {
cmd.Println(response)
}
return nil
},
}
Allow using the function name from the SDK as an alias for the command.
if fn.Name != newCmd.Name() {
newCmd.Aliases = append(newCmd.Aliases, fn.Name)
}
newCmd.Flags().SetInterspersed(false)
return newCmd
}
func (fc *FuncCommand) addArgsForFunction(cmd *cobra.Command, cmdArgs []string, fn *modFunction, dag *dagger.Client) error {
fc.mod.LoadTypeDef(fn.ReturnType)
for _, arg := range fn.Args {
fc.mod.LoadTypeDef(arg.TypeDef)
}
for _, arg := range fn.Args {
_, err := arg.AddFlag(cmd.Flags(), dag)
if err != nil {
return err
}
if !arg.TypeDef.Optional {
cmd.MarkFlagRequired(arg.FlagName())
}
}
if fc.BeforeParse != nil {
if err := fc.BeforeParse(fc, cmd, fn); err != nil {
return err |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | }
}
if err := cmd.ParseFlags(cmdArgs); err != nil {
return cmd.FlagErrorFunc()(cmd, err)
}
help, _ := cmd.Flags().GetBool("help")
if !help {
if err := cmd.ValidateRequiredFlags(); err != nil {
return err
}
if err := cmd.ValidateFlagGroups(); err != nil {
return err
}
}
return nil
}
selectFunc adds the function selection to the query.
Note that the type can change if there's an extra selection for supported types.
func (fc *FuncCommand) selectFunc(selectName string, fn *modFunction, cmd *cobra.Command, dag *dagger.Client) error {
fc.Select(selectName)
for _, arg := range fn.Args {
var val any
flag := cmd.Flags().Lookup(arg.FlagName())
if flag == nil {
return fmt.Errorf("no flag for %q", arg.FlagName())
}
if arg.TypeDef.Optional && !flag.Changed { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | cmd/dagger/functions.go | continue
}
val = flag.Value
switch v := val.(type) {
case DaggerValue:
obj, err := v.Get(cmd.Context(), dag)
if err != nil {
return fmt.Errorf("failed to get value for argument %q: %w", arg.Name, err)
}
if obj == nil {
return fmt.Errorf("no value for argument: %s", arg.Name)
}
val = obj
case pflag.SliceValue:
val = v.GetSlice()
}
fc.Arg(arg.Name, val)
}
return nil
}
func (fc *FuncCommand) Select(name string) {
if fc.q == nil {
fc.q = querybuilder.Query()
}
fc.q = fc.q.Select(gqlFieldName(name))
}
func (fc *FuncCommand) Arg(name string, value any) {
fc.q = fc.q.Arg(gqlArgName(name), value)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | core/integration/module_functions_test.go | package core
import (
"strings"
"testing"
"dagger.io/dagger"
"github.com/stretchr/testify/require"
)
func TestModuleDaggerCLIFunctions(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | core/integration/module_functions_test.go | t.Parallel()
c, ctx := connect(t)
ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
Contents: `package main
import (
"context"
)
type Test struct{}
// doc for FnA
func (m *Test) FnA() *Container {
return nil
}
// doc for FnB
func (m *Test) FnB() Duck {
return nil
}
type Duck interface {
DaggerObject
// quack that thang |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | core/integration/module_functions_test.go | Quack(ctx context.Context) (string, error)
}
// doc for FnC
func (m *Test) FnC() *Obj {
return nil
}
type Obj struct {
// doc for FieldA
FieldA *Container
// doc for FieldB
FieldB string
// doc for FieldC
FieldC *Obj
// doc for FieldD
FieldD *OtherObj
}
// doc for FnD
func (m *Obj) FnD() *Container {
return nil
}
type OtherObj struct {
// doc for OtherFieldA
OtherFieldA *Container
// doc for OtherFieldB
OtherFieldB string
// doc for OtherFieldC
OtherFieldC *Obj
// doc for OtherFieldD
OtherFieldD *OtherObj
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | core/integration/module_functions_test.go | // doc for FnE
func (m *OtherObj) FnE() *Container {
return nil
}
`,
})
t.Run("top-level", func(t *testing.T) {
out, err := ctr.With(daggerFunctions()).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "fn-a doc for FnA")
require.Contains(t, lines, "fn-b doc for FnB")
require.Contains(t, lines, "fn-c doc for FnC")
})
t.Run("return core object", func(t *testing.T) {
out, err := ctr.With(daggerFunctions("fn-a")).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "file Retrieves a file at the given path.")
require.Contains(t, lines, "as-tarball Returns a File representing the container serialized to a tarball.")
})
t.Run("alt casing", func(t *testing.T) {
out, err := ctr.With(daggerFunctions("fnA")).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "file Retrieves a file at the given path.")
require.Contains(t, lines, "as-tarball Returns a File representing the container serialized to a tarball.")
}) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,731 | π [CLI]: `dagger functions $function_name` returns an error if return type is not a dagger object | ### What is the issue?
calling `dagger functions foo` on the following function definition raises the following error:
`Error: function 'foo' returns non-object type STRING_KIND`
```go
package main
type Testmodule struct{}
func (m *Testmodule) Foo() string {
return "bar"
}
```
### Dagger version
dagger v0.9.11
### Steps to reproduce
run `dagger functions foo` on the code given above
### Log output
Error: function 'foo' returns non-object type STRING_KIND
| https://github.com/dagger/dagger/issues/6731 | https://github.com/dagger/dagger/pull/6733 | 58f4b8f7791786a740134ee36854002f9021c1fc | 4359dd91d1739cddbc83ca37328943f6187ce50a | "2024-02-25T14:27:41Z" | go | "2024-02-26T12:02:06Z" | core/integration/module_functions_test.go | t.Run("return user interface", func(t *testing.T) {
out, err := ctr.With(daggerFunctions("fn-b")).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "quack quack that thang")
})
t.Run("return user object", func(t *testing.T) {
out, err := ctr.With(daggerFunctions("fn-c")).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "field-a doc for FieldA")
require.Contains(t, lines, "field-b doc for FieldB")
require.Contains(t, lines, "field-c doc for FieldC")
require.Contains(t, lines, "field-d doc for FieldD")
require.Contains(t, lines, "fn-d doc for FnD")
})
t.Run("return user object nested", func(t *testing.T) {
out, err := ctr.With(daggerFunctions("fn-c", "field-d")).Stdout(ctx)
require.NoError(t, err)
lines := strings.Split(out, "\n")
require.Contains(t, lines, "other-field-a doc for OtherFieldA")
require.Contains(t, lines, "other-field-b doc for OtherFieldB")
require.Contains(t, lines, "other-field-c doc for OtherFieldC")
require.Contains(t, lines, "other-field-d doc for OtherFieldD")
require.Contains(t, lines, "fn-e doc for FnE")
})
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | package templates
import (
"fmt"
"go/ast"
"go/types"
"maps"
"reflect"
"sort"
"strconv"
"strings"
. "github.com/dave/jennifer/jen"
)
func (ps *parseState) parseGoStruct(t *types.Struct, named *types.Named) (*parsedObjectType, error) {
spec := &parsedObjectType{
goType: t,
moduleName: ps.moduleName,
}
if named == nil {
return nil, fmt.Errorf("struct types must be named")
}
spec.name = named.Obj().Name()
if spec.name == "" {
return nil, fmt.Errorf("struct types must be named")
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | objectIsDaggerGenerated := ps.isDaggerGenerated(named.Obj())
goFuncTypes := []*types.Func{}
methodSet := types.NewMethodSet(types.NewPointer(named))
for i := 0; i < methodSet.Len(); i++ {
methodObj := methodSet.At(i).Obj()
if ps.isDaggerGenerated(methodObj) {
continue
}
if objectIsDaggerGenerated {
return nil, fmt.Errorf("cannot define methods on objects from outside this module")
}
goFuncType, ok := methodObj.(*types.Func)
if !ok {
return nil, fmt.Errorf("expected method to be a func, got %T", methodObj)
}
if !goFuncType.Exported() {
continue
}
goFuncTypes = append(goFuncTypes, goFuncType)
}
if objectIsDaggerGenerated {
return nil, nil
}
sort.Slice(goFuncTypes, func(i, j int) bool {
return goFuncTypes[i].Pos() < goFuncTypes[j].Pos()
})
for _, goFuncType := range goFuncTypes {
funcTypeSpec, err := ps.parseGoFunc(named, goFuncType)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | return nil, fmt.Errorf("failed to parse method %s: %w", goFuncType.Name(), err)
}
spec.methods = append(spec.methods, funcTypeSpec)
}
astSpec, err := ps.astSpecForNamedType(named)
if err != nil {
return nil, fmt.Errorf("failed to find decl for named type %s: %w", spec.name, err)
}
spec.doc = astSpec.Doc.Text()
astStructType, ok := astSpec.Type.(*ast.StructType)
if !ok {
return nil, fmt.Errorf("expected type spec to be a struct, got %T", astSpec.Type)
}
astFields := unpackASTFields(astStructType.Fields)
for i := 0; i < t.NumFields(); i++ {
field := t.Field(i)
if !field.Exported() {
continue
}
fieldSpec := &fieldSpec{goType: field.Type()}
fieldSpec.typeSpec, err = ps.parseGoTypeReference(fieldSpec.goType, nil, false)
if err != nil {
return nil, fmt.Errorf("failed to parse field type: %w", err)
}
fieldSpec.goName = field.Name()
fieldSpec.name = fieldSpec.goName |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | tag := reflect.StructTag(t.Tag(i))
if dt := tag.Get("json"); dt != "" {
dt, _, _ = strings.Cut(dt, ",")
if dt == "-" {
continue
}
fieldSpec.name = dt
}
docPragmas, docComment := parsePragmaComment(astFields[i].Doc.Text())
linePragmas, lineComment := parsePragmaComment(astFields[i].Comment.Text())
comment := strings.TrimSpace(docComment)
if comment == "" {
comment = strings.TrimSpace(lineComment)
}
pragmas := make(map[string]string)
maps.Copy(pragmas, docPragmas)
maps.Copy(pragmas, linePragmas)
if v, ok := pragmas["private"]; ok {
if v == "" {
fieldSpec.isPrivate = true
} else {
fieldSpec.isPrivate, _ = strconv.ParseBool(v)
}
}
fieldSpec.doc = comment
spec.fields = append(spec.fields, fieldSpec)
}
if ps.isMainModuleObject(spec.name) && ps.constructor != nil {
spec.constructor, err = ps.parseGoFunc(nil, ps.constructor)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | return nil, fmt.Errorf("failed to parse constructor: %w", err)
}
}
return spec, nil
}
type parsedObjectType struct {
name string
moduleName string
doc string
fields []*fieldSpec
methods []*funcTypeSpec
constructor *funcTypeSpec
goType *types.Struct
}
var _ NamedParsedType = &parsedObjectType{}
func (spec *parsedObjectType) TypeDefCode() (*Statement, error) {
withObjectArgsCode := []Code{
Lit(spec.name),
}
withObjectOptsCode := []Code{}
if spec.doc != "" {
withObjectOptsCode = append(withObjectOptsCode, Id("Description").Op(":").Lit(strings.TrimSpace(spec.doc)))
}
if len(withObjectOptsCode) > 0 {
withObjectArgsCode = append(withObjectArgsCode, Id("TypeDefWithObjectOpts").Values(withObjectOptsCode...))
}
typeDefCode := Qual("dag", "TypeDef").Call().Dot("WithObject").Call(withObjectArgsCode...)
for _, method := range spec.methods {
fnTypeDefCode, err := method.TypeDefCode()
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | return nil, fmt.Errorf("failed to convert method %s to function def: %w", method.name, err)
}
typeDefCode = dotLine(typeDefCode, "WithFunction").Call(Add(Line(), fnTypeDefCode))
}
for _, field := range spec.fields {
if field.isPrivate {
continue
}
fieldTypeDefCode, err := field.typeSpec.TypeDefCode()
if err != nil {
return nil, fmt.Errorf("failed to convert field type: %w", err)
}
withFieldArgsCode := []Code{
Lit(field.name),
fieldTypeDefCode,
}
if field.doc != "" {
withFieldArgsCode = append(withFieldArgsCode,
Id("TypeDefWithFieldOpts").Values(
Id("Description").Op(":").Lit(field.doc),
))
}
typeDefCode = dotLine(typeDefCode, "WithField").Call(withFieldArgsCode...)
}
if spec.constructor != nil {
fnTypeDefCode, err := spec.constructor.TypeDefCode()
if err != nil {
return nil, fmt.Errorf("failed to convert constructor to function def: %w", err)
}
typeDefCode = dotLine(typeDefCode, "WithConstructor").Call(Add(Line(), fnTypeDefCode)) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | }
return typeDefCode, nil
}
func (spec *parsedObjectType) GoType() types.Type {
return spec.goType
}
func (spec *parsedObjectType) GoSubTypes() []types.Type {
var subTypes []types.Type
for _, method := range spec.methods {
subTypes = append(subTypes, method.GoSubTypes()...)
}
for _, field := range spec.fields {
if field.isPrivate {
continue
}
subTypes = append(subTypes, field.typeSpec.GoSubTypes()...)
}
if spec.constructor != nil {
subTypes = append(subTypes, spec.constructor.GoSubTypes()...)
}
return subTypes
}
func (spec *parsedObjectType) Name() string {
return spec.name
}
func (spec *parsedObjectType) ModuleName() string {
return spec.moduleName
}
/*
Extra generated code needed for the object implementation. |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | Right now, this is just an UnmarshalJSON method. This is needed because objects may have fields
of an interface type, which the JSON unmarshaller can't handle on its own. Instead, this custom
unmarshaller will unmarshal the JSON into a struct where all the fields are concrete types,
including the underlying concrete struct implementation of any interface fields.
After it unmarshals into that, it copies the fields to the real object fields, handling any
special cases around interface conversions (e.g. converting a slice of structs to a slice of
interfaces).
e.g.:
func (r *Test) UnmarshalJSON(bs []byte) error {
var concrete struct {
Iface *customIfaceImpl
IfaceList []*customIfaceImpl
OtherIfaceList []*otherIfaceImpl
}
err := json.Unmarshal(bs, &concrete)
if err != nil {
return err
}
r.Iface = concrete.Iface.toIface()
r.IfaceList = convertSlice(concrete.IfaceList, (*customIfaceImpl).toIface)
r.OtherIfaceList = convertSlice(concrete.OtherIfaceList, (*otherIfaceImpl).toIface)
return nil
}
*/
func (spec *parsedObjectType) ImplementationCode() (*Statement, error) {
concreteFields := make([]Code, 0, len(spec.fields))
setFieldCodes := make([]*Statement, 0, len(spec.fields))
for _, field := range spec.fields {
fieldTypeCode, err := spec.concreteFieldTypeCode(field.typeSpec)
if err != nil { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | return nil, fmt.Errorf("failed to generate field type code: %w", err)
}
fieldCode := Id(field.goName).Add(fieldTypeCode)
if field.goName != field.name {
fieldCode.Tag(map[string]string{"json": field.name})
}
concreteFields = append(concreteFields, fieldCode)
setFieldCode, err := spec.setFieldsFromConcreteStructCode(field)
if err != nil {
return nil, fmt.Errorf("failed to generate set field code: %w", err)
}
setFieldCodes = append(setFieldCodes, setFieldCode)
}
return Func().Params(Id("r").Op("*").Id(spec.name)).
Id("UnmarshalJSON").
Params(Id("bs").Id("[]byte")).
Params(Id("error")).
BlockFunc(func(g *Group) {
g.Var().Id("concrete").Struct(concreteFields...)
g.Id("err").Op(":=").Id("json").Dot("Unmarshal").Call(Id("bs"), Op("&").Id("concrete"))
g.If(Id("err").Op("!=").Nil()).Block(Return(Id("err")))
for _, setFieldCode := range setFieldCodes {
g.Add(setFieldCode)
}
g.Return(Nil())
}).
Line(), nil
}
/*
The code for the type of a field in the concrete struct unmarshalled into. Mainly needs to handle |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | interface types, which need to be converted to their concrete struct implementations.
*/
func (spec *parsedObjectType) concreteFieldTypeCode(typeSpec ParsedType) (*Statement, error) {
s := Empty()
switch typeSpec := typeSpec.(type) {
case *parsedPrimitiveType:
if typeSpec.isPtr {
s.Op("*")
}
if typeSpec.alias != "" {
s.Id(typeSpec.alias)
} else {
s.Id(typeSpec.GoType().String())
}
case *parsedSliceType:
fieldTypeCode, err := spec.concreteFieldTypeCode(typeSpec.underlying)
if err != nil {
return nil, fmt.Errorf("failed to generate slice field type code: %w", err)
}
s.Index().Add(fieldTypeCode)
case *parsedObjectTypeReference:
if typeSpec.isPtr {
s.Op("*")
}
s.Id(typeSpec.name)
case *parsedIfaceTypeReference:
s.Op("*").Id(formatIfaceImplName(typeSpec.name))
default:
return nil, fmt.Errorf("unsupported concrete field type %T", typeSpec)
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | return s, nil
}
/*
The code for setting the fields of the real object from the concrete struct unmarshalled into. e.g.:
r.Iface = concrete.Iface.toIface()
r.IfaceList = convertSlice(concrete.IfaceList, (*customIfaceImpl).toIface)
*/
func (spec *parsedObjectType) setFieldsFromConcreteStructCode(field *fieldSpec) (*Statement, error) {
s := Empty()
switch typeSpec := field.typeSpec.(type) {
case *parsedPrimitiveType, *parsedObjectTypeReference:
s.Id("r").Dot(field.goName).Op("=").Id("concrete").Dot(field.goName)
case *parsedSliceType:
switch underlyingTypeSpec := typeSpec.underlying.(type) {
case *parsedIfaceTypeReference:
s.Id("r").Dot(field.goName).Op("=").Id("convertSlice").Call(
Id("concrete").Dot(field.goName),
Parens(Op("*").Id(formatIfaceImplName(underlyingTypeSpec.name))).Dot("toIface"),
)
default:
s.Id("r").Dot(field.goName).Op("=").Id("concrete").Dot(field.goName)
}
case *parsedIfaceTypeReference:
s.Id("r").Dot(field.goName).Op("=").Id("concrete").Dot(field.goName).Dot("toIface").Call()
default:
return nil, fmt.Errorf("unsupported field type %T", typeSpec)
}
return s, nil
}
type fieldSpec struct { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | cmd/codegen/generator/go/templates/module_objects.go | name string
doc string
typeSpec ParsedType
isPrivate bool
goName string
goType types.Type
} |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | core/integration/module_test.go | package core
import (
"context"
_ "embed"
"encoding/json"
"fmt"
"go/format"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
"github.com/MakeNowJust/heredoc/v2"
"github.com/dagger/dagger/core/modules"
"github.com/dagger/dagger/dagql/idproto"
"github.com/iancoleman/strcase"
"github.com/moby/buildkit/identity"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
"golang.org/x/sync/errgroup"
"dagger.io/dagger"
"github.com/dagger/dagger/cmd/codegen/introspection"
)
func TestModuleGoInit(t *testing.T) { |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | core/integration/module_test.go | t.Parallel()
t.Run("from scratch", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--name=bare", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("reserved go.mod name", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--name=go", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{go{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx) |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | core/integration/module_test.go | require.NoError(t, err)
require.JSONEq(t, `{"go":{"containerEcho":{"stdout":"hello\n"}}}`, out)
})
t.Run("uses expected Go module name, camel-cases Dagger module name", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(daggerExec("init", "--source=.", "--name=My-Module", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{myModule{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"myModule":{"containerEcho":{"stdout":"hello\n"}}}`, out)
generated, err := modGen.File("go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module main")
})
t.Run("creates go.mod beneath an existing go.mod if context is beneath it", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithNewFile("/work/go.mod", dagger.ContainerWithNewFileOpts{
Contents: "module example.com/test\n",
}).
WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ |
closed | dagger/dagger | https://github.com/dagger/dagger | 6,662 | Using embedded fields with go modules fails with unhelpful error | Take the following code:
```go
type Playground struct {
// This breaks
*Directory
// This doesn't
// Directory *Directory
}
func New() Playground {
return Playground{Directory: dag.Directory()}
}
```
When attempting to evaluate anything on the `Playground` object, we get the following error:
```
Error: response from query: input: resolve: playground: failed to convert return value: unexpected result value type string for object "Playground"
``` | https://github.com/dagger/dagger/issues/6662 | https://github.com/dagger/dagger/pull/6715 | 2f975ef29ad78e08c5b9328f6db3797b4c57da69 | b966257dbc24b714e6ee39f01158f10f8fa24fd3 | "2024-02-13T15:54:25Z" | go | "2024-02-26T15:11:43Z" | core/integration/module_test.go | Contents: "package foo\n",
}).
WithWorkdir("/work/ci").
With(daggerExec("init", "--name=beneathGoMod", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{beneathGoMod{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"beneathGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("names Go module after Dagger module", func(t *testing.T) {
generated, err := modGen.Directory("dagger").File("go.mod").Contents(ctx)
require.NoError(t, err)
require.Contains(t, generated, "module main")
})
})
t.Run("respects existing go.mod", func(t *testing.T) {
t.Parallel()
c, ctx := connect(t)
modGen := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
WithExec([]string{"go", "mod", "init", "example.com/test"}).
With(daggerExec("init", "--name=hasGoMod", "--sdk=go"))
out, err := modGen.
With(daggerQuery(`{hasGoMod{containerEcho(stringArg:"hello"){stdout}}}`)).
Stdout(ctx)
require.NoError(t, err)
require.JSONEq(t, `{"hasGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out)
t.Run("preserves module name", func(t *testing.T) {
generated, err := modGen.File("go.mod").Contents(ctx) |
Subsets and Splits