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

Method localModuleSource

core/schema/modulesource.go:338–571  ·  view source on GitHub ↗

nolint:gocyclo

(
	ctx context.Context,
	query dagql.ObjectResult[*core.Query],
	bk *engineutil.Client,

	// localPath is the path the user provided to load the module, it may be relative or absolute and
	// may point to either the directory containing dagger.json or any subdirectory in the
	// filetree under the directory containing dagger.json.
	// When findUp is enabled, it can also be a name of a dependency in the default dagger.json found-up from the cwd.
	localPath string,

	// whether to search up the directory tree for a dagger.json file. additionally, when enabled if a dagger.json is found-up
	// and localPath is a named dependency in that dagger.json, the returned source will be for that dependency.
	doFindUp bool,

	// if true, tolerate the localPath not existing on the filesystem (for dagger init on directories that don't exist yet)
	allowNotExists bool,
)

Source from the content-addressed store, hash-verified

336
337//nolint:gocyclo
338func (s *moduleSourceSchema) localModuleSource(
339 ctx context.Context,
340 query dagql.ObjectResult[*core.Query],
341 bk *engineutil.Client,
342
343 // localPath is the path the user provided to load the module, it may be relative or absolute and
344 // may point to either the directory containing dagger.json or any subdirectory in the
345 // filetree under the directory containing dagger.json.
346 // When findUp is enabled, it can also be a name of a dependency in the default dagger.json found-up from the cwd.
347 localPath string,
348
349 // whether to search up the directory tree for a dagger.json file. additionally, when enabled if a dagger.json is found-up
350 // and localPath is a named dependency in that dagger.json, the returned source will be for that dependency.
351 doFindUp bool,
352
353 // if true, tolerate the localPath not existing on the filesystem (for dagger init on directories that don't exist yet)
354 allowNotExists bool,
355) (inst dagql.Result[*core.ModuleSource], err error) {
356 if localPath == "" {
357 localPath = "."
358 }
359
360 // figure out the absolute path to the local module source
361 var localAbsPath string
362
363 // first, check if the local path exists outright
364 stat, err := bk.StatCallerHostPath(ctx, localPath, true)
365 switch {
366 case err == nil:
367 localAbsPath = stat.Path
368 case status.Code(err) == codes.NotFound:
369 // tolerate for now, we may not be enforcing it's existence and/or may find it as named dep in a find-up
370 default:
371 return inst, fmt.Errorf("failed to stat local path: %w", err)
372 }
373
374 // if localPath doesn't exist and find-up is enabled, check if it's a named dep in the default dagger.json
375 if localAbsPath == "" && doFindUp {
376 cwd, err := bk.AbsPath(ctx, ".")
377 if err != nil {
378 return inst, fmt.Errorf("failed to get cwd: %w", err)
379 }
380 defaultFindUpSourceRootDir, defaultFindUpExists, err := core.Host{}.FindUp(ctx, core.NewCallerStatFS(bk), cwd, modules.Filename)
381 if err != nil {
382 return inst, fmt.Errorf("failed to find up root: %w", err)
383 }
384 if defaultFindUpExists {
385 configPath := filepath.Join(defaultFindUpSourceRootDir, modules.Filename)
386 contents, err := bk.ReadCallerHostFile(ctx, configPath)
387 if err != nil {
388 return inst, fmt.Errorf("failed to read module config file: %w", err)
389 }
390 modCfg, err := modules.ParseModuleConfig(contents)
391 if err != nil {
392 return inst, fmt.Errorf("failed to parse module config: %w", err)
393 }
394
395 namedDep, ok := modCfg.DependencyByName(localPath)

Callers 1

moduleSourceMethod · 0.95

Calls 15

gitModuleSourceMethod · 0.95
initFromModConfigMethod · 0.95
loadBlueprintModuleMethod · 0.95
LoadUserDefaultsMethod · 0.95
NewCallerStatFSFunction · 0.92
ParseModuleConfigFunction · 0.92
ParseRefStringFunction · 0.92
StatFSFuncFuncType · 0.92
LexicalRelativePathFunction · 0.92
StringTypeAlias · 0.92
NewLoaderFunction · 0.92

Tested by

no test coverage detected