func()

in gazelle/parser.go [114:155]


func (p *python3Parser) parse(pyFilepath string) (*treeset.Set, error) {
	parserMutex.Lock()
	defer parserMutex.Unlock()

	modules := treeset.NewWith(moduleComparator)

	relFilepath := filepath.Join(p.relPackagePath, pyFilepath)
	absFilepath := filepath.Join(p.repoRoot, relFilepath)
	fmt.Fprintln(parserStdin, absFilepath)
	reader := bufio.NewReader(parserStdout)
	data, err := reader.ReadBytes(0)
	if err != nil {
		return nil, fmt.Errorf("failed to parse %s: %w", pyFilepath, err)
	}
	data = data[:len(data)-1]
	var res parserResponse
	if err := json.Unmarshal(data, &res); err != nil {
		return nil, fmt.Errorf("failed to parse %s: %w", pyFilepath, err)
	}

	annotations := annotationsFromComments(res.Comments)

	for _, m := range res.Modules {
		// Check for ignored dependencies set via an annotation to the Python
		// module.
		if annotations.ignores(m.Name) {
			continue
		}

		// Check for ignored dependencies set via a Gazelle directive in a BUILD
		// file.
		if p.ignoresDependency(m.Name) {
			continue
		}

		m.Filepath = relFilepath

		modules.Add(m)
	}

	return modules, nil
}