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

Method loadFiles

sdk/python/runtime/discovery.go:285–362  ·  view source on GitHub ↗

loadFiles loads the contents of certain module source files.

(ctx context.Context, m *PythonSdk)

Source from the content-addressed store, hash-verified

283
284// loadFiles loads the contents of certain module source files.
285func (d *Discovery) loadFiles(ctx context.Context, m *PythonSdk) error {
286 // If there's a dagger.json and no pyproject.toml, it's an init'ed module
287 // adding sources (`dagger develop --sdk`).
288 if !m.IsInit && !d.HasFile("pyproject.toml") {
289 m.IsInit = true
290 }
291
292 // These paths should be in "exclude" in dagger.json.
293 // Let's remove them just in case, to avoid conflicts.
294 for _, exclude := range DirExcludes {
295 if d.HasFile(exclude) {
296 m.ContextDir = m.ContextDir.WithoutDirectory(
297 path.Join(m.SubPath, exclude),
298 )
299 }
300 }
301
302 eg, gctx := errgroup.WithContext(ctx)
303
304 if d.EnableCustomConfig {
305 for _, name := range FileContents {
306 if d.HasFile(name) {
307 eg.Go(func() error {
308 contents, err := m.GetFile(name).Contents(gctx)
309 if err != nil {
310 return fmt.Errorf("get file contents of %q: %w", name, err)
311 }
312 d.mu.Lock()
313 d.Files[name] = strings.TrimSpace(contents)
314 d.mu.Unlock()
315 return nil
316 })
317 }
318 }
319 }
320
321 eg.Go(func() error {
322 // We'll use a glob pattern in fileSet to check for the existence of
323 // python files later. The error is normal when the target directory
324 // on `dagger init` doesn't exist, but just ignore otherwise (best
325 // effort).
326 entries, err := m.Source().Glob(gctx, "src/**/*.py|*.py")
327 if len(entries) > 0 {
328 d.mu.Lock()
329 d.FileSet["*.py"] = struct{}{}
330 d.mu.Unlock()
331 } else if err == nil && !m.IsInit {
332 // This can also happen on `dagger develop --sdk` if there's also
333 // a pyproject.toml present to customize the base container.
334 return fmt.Errorf("no python files found in module source")
335 }
336 return nil
337 })
338
339 eg.Go(func() error {
340 entries, _ := m.SdkSourceDir.Entries(gctx)
341 d.mu.Lock()
342 for _, entry := range entries {

Callers

nothing calls this directly

Calls 10

HasFileMethod · 0.95
SdkHasFileMethod · 0.95
WaitMethod · 0.65
WithoutDirectoryMethod · 0.45
GoMethod · 0.45
ContentsMethod · 0.45
GetFileMethod · 0.45
GlobMethod · 0.45
SourceMethod · 0.45
EntriesMethod · 0.45

Tested by

no test coverage detected