MCPcopy Index your code
hub / github.com/dagger/dagger / loadModuleSourceContext

Method loadModuleSourceContext

core/schema/modulesource.go:1068–1139  ·  view source on GitHub ↗

load (or re-load) the context directory for the given module source

(
	ctx context.Context,
	src *core.ModuleSource,
)

Source from the content-addressed store, hash-verified

1066
1067// load (or re-load) the context directory for the given module source
1068func (s *moduleSourceSchema) loadModuleSourceContext(
1069 ctx context.Context,
1070 src *core.ModuleSource,
1071) error {
1072 dag, err := core.CurrentDagqlServer(ctx)
1073 if err != nil {
1074 return fmt.Errorf("failed to get dag server: %w", err)
1075 }
1076
1077 // we load the includes specified by the user in dagger.json (if any) plus a few
1078 // prepended paths that are always loaded
1079 fullIncludePaths := []string{
1080 // always load the config file
1081 src.SourceRootSubpath + "/" + modules.Filename,
1082 }
1083
1084 if src.SourceSubpath == "." {
1085 // "." ends up matching nothing, so we convert it to "*"
1086 fullIncludePaths = append(fullIncludePaths, "*")
1087 } else if src.SourceSubpath != "" {
1088 // load the source dir if set
1089 fullIncludePaths = append(fullIncludePaths, src.SourceSubpath)
1090 } else {
1091 // otherwise load the source root; this supports use cases like an sdk-less module w/ a pyproject.toml
1092 // that's now going to be upgraded to using the python sdk and needs pyproject.toml to be loaded
1093 fullIncludePaths = append(fullIncludePaths, src.SourceRootSubpath)
1094 }
1095
1096 switch src.Kind {
1097 case core.ModuleSourceKindLocal:
1098 fullIncludePaths = append(fullIncludePaths, src.RebasedIncludePaths...)
1099
1100 err = dag.Select(ctx, dag.Root(), &src.ContextDirectory,
1101 dagql.Selector{Field: "host"},
1102 dagql.Selector{
1103 Field: "directory",
1104 Args: []dagql.NamedInput{
1105 {Name: "path", Value: dagql.String(src.Local.ContextDirectoryPath)},
1106 {Name: "include", Value: dagql.ArrayInput[dagql.String](dagql.NewStringArray(fullIncludePaths...))},
1107 {Name: "gitignore", Value: dagql.NewBoolean(true)},
1108 },
1109 },
1110 )
1111 if err != nil {
1112 return err
1113 }
1114
1115 case core.ModuleSourceKindGit:
1116 fullIncludePaths = append(fullIncludePaths, src.RebasedIncludePaths...)
1117 unfilteredContextDirID, err := src.Git.UnfilteredContextDir.ID()
1118 if err != nil {
1119 return fmt.Errorf("failed to get git unfiltered context directory ID: %w", err)
1120 }
1121
1122 err = dag.Select(ctx, dag.Root(), &src.ContextDirectory,
1123 dagql.Selector{Field: "directory"},
1124 dagql.Selector{
1125 Field: "withDirectory",

Callers 6

localModuleSourceMethod · 0.95
gitModuleSourceMethod · 0.95
moduleSourceWithSDKMethod · 0.95

Calls 7

CurrentDagqlServerFunction · 0.92
StringTypeAlias · 0.92
NewStringArrayFunction · 0.92
NewBooleanFunction · 0.92
SelectMethod · 0.65
IDMethod · 0.65
RootMethod · 0.45

Tested by

no test coverage detected