python

package
v0.0.0-...-66a8b5b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetActualKindName

func GetActualKindName(kind string, args language.GenerateArgs) string

func NewLanguage

func NewLanguage() language.Language

NewLanguage initializes a new Python that satisfies the language.Language interface. This is the entrypoint for the extension initialization.

func ParseCode

func ParseCode(code []byte, path string) (*sitter.Node, error)

ParseCode instantiates a new tree-sitter Parser and parses the python code, returning the tree-sitter RootNode. It prints a warning if parsing fails.

Types

type Configurer

type Configurer struct{}

Configurer satisfies the config.Configurer interface. It's the language-specific configuration extension.

func (*Configurer) CheckFlags

func (py *Configurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error

CheckFlags validates the configuration after command line flags are parsed. This is called once with the root configuration when Gazelle starts. CheckFlags may set default values in flags or make implied changes.

func (*Configurer) Configure

func (py *Configurer) Configure(c *config.Config, rel string, f *rule.File)

Configure modifies the configuration using directives and other information extracted from a build file. Configure is called in each directory.

c is the configuration for the current directory. It starts out as a copy of the configuration for the parent directory.

rel is the slash-separated relative path from the repository root to the current directory. It is "" for the root directory itself.

f is the build file for the current directory or nil if there is no existing build file.

func (*Configurer) KnownDirectives

func (py *Configurer) KnownDirectives() []string

KnownDirectives returns a list of directive keys that this Configurer can interpret. Gazelle prints errors for directives that are not recoginized by any Configurer.

func (*Configurer) RegisterFlags

func (py *Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config)

RegisterFlags registers command-line flags used by the extension. This method is called once with the root configuration when Gazelle starts. RegisterFlags may set an initial values in Config.Exts. When flags are set, they should modify these values.

type FileParser

type FileParser struct {
	// contains filtered or unexported fields
}

func NewFileParser

func NewFileParser() *FileParser

func (*FileParser) Parse

func (p *FileParser) Parse(ctx context.Context) (*ParserOutput, error)

func (*FileParser) ParseFile

func (p *FileParser) ParseFile(ctx context.Context, repoRoot, relPackagePath, filename string) (*ParserOutput, error)

func (*FileParser) SetCodeAndFile

func (p *FileParser) SetCodeAndFile(code []byte, relPackagePath, filename string)

type ParserOutput

type ParserOutput struct {
	FileName string
	Modules  []module
	Comments []comment
	HasMain  bool
}

type Python

type Python struct {
	Configurer
	Resolver
}

Python satisfies the language.Language interface. It is the Gazelle extension for Python rules.

func (*Python) Fix

func (py *Python) Fix(c *config.Config, f *rule.File)

Fix repairs deprecated usage of language-specific rules in f. This is called before the file is indexed. Unless c.ShouldFix is true, fixes that delete or rename rules should not be performed.

func (*Python) GenerateRules

func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateResult

GenerateRules extracts build metadata from source files in a directory. GenerateRules is called in each directory where an update is requested in depth-first post-order.

func (*Python) Kinds

func (*Python) Kinds() map[string]rule.KindInfo

Kinds returns a map that maps rule names (kinds) and information on how to match and merge attributes that may be found in rules of those kinds.

func (*Python) Loads

func (py *Python) Loads() []rule.LoadInfo

Loads returns .bzl files and symbols they define. Every rule generated by GenerateRules, now or in the past, should be loadable from one of these files.

type Resolver

type Resolver struct{}

Resolver satisfies the resolve.Resolver interface. It resolves dependencies in rules generated by this extension.

func (*Resolver) Embeds

func (py *Resolver) Embeds(r *rule.Rule, from label.Label) []label.Label

Embeds returns a list of labels of rules that the given rule embeds. If a rule is embedded by another importable rule of the same language, only the embedding rule will be indexed. The embedding rule will inherit the imports of the embedded rule.

func (*Resolver) Imports

func (py *Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec

Imports returns a list of ImportSpecs that can be used to import the rule r. This is used to populate RuleIndex.

If nil is returned, the rule will not be indexed. If any non-nil slice is returned, including an empty slice, the rule will be indexed.

func (*Resolver) Name

func (*Resolver) Name() string

Name returns the name of the language. This is the prefix of the kinds of rules generated. E.g. py_library and py_binary.

func (*Resolver) Resolve

func (py *Resolver) Resolve(
	c *config.Config,
	ix *resolve.RuleIndex,
	rc *repo.RemoteCache,
	r *rule.Rule,
	modulesRaw interface{},
	from label.Label,
)

Resolve translates imported libraries for a given rule into Bazel dependencies. Information about imported libraries is returned for each rule generated by language.GenerateRules in language.GenerateResult.Imports. Resolve generates a "deps" attribute (or the appropriate language-specific equivalent) for each import according to language-specific rules and heuristics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL