python

package
v0.0.0-...-abfd595 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLanguage

func NewLanguage() language.Language

Types

type Configuration

type Configuration struct {
	// Enable the Python Gazelle language extension.
	Enable bool
	// Root directory for Python code.
	RootDir string
	// Python package path (slash separated); its value is Bazel package path
	// relative to RootDir. If this starts with '..', then it means we have not
	// yet reached the Python workspace.
	PythonPackagePath string
	// List of modules internal to the interpreter, whether part of stdlib, or
	// available as a system installation. A common default for such a list
	// would be given by
	// `python3 -c "import sys; print(sorted(sys.stdlib_module_names))"`.
	InternalModuleList map[string]struct{}
	// Path to list (one per line; comment char '#') of internal modules.
	// Functions as a caching key for InternalModuleList.
	InternalModuleListPath string
	// Map of import specifiers for external module names to their sources.
	ExternalModuleMap map[string]ExternalModule
	// Path to map of external modules from where ExternalModuleMap is
	// read. Functions as a caching key for ExternalModuleMap.
	ExternalModuleMapPath string
	// Name prefix under which the external repositories are defined, e.g. "pip_".
	ExternalRepoNamePrefix string
	// Name template to use for naming targets.
	NameTemplate string
}

Configuration is configuration for the Python language extension. A default configuration is set through command line flags and their default values. Each directory gets its own copy and the values may be changed by Configurer.Configure().

type Configurer

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

Configurer manages the configuration at root and for each subdirectory.

func (*Configurer) CheckFlags

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

CheckFlags implements config.Configurer.

It performs any resource initialization based on the flags, validates the initial configuration, and sets the configuration extension.

func (Configurer) Configure

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

Configure implements config.Configurer.

func (Configurer) KnownDirectives

func (pc Configurer) KnownDirectives() []string

KnownDirectives implements config.Configurer.

func (*Configurer) RegisterFlags

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

RegisterFlags implements config.Configurer.

It registers the flags to their relevant fields in an initial copy of the Configuration object. The configuration extension is not set yet.

type ExternalModule

type ExternalModule struct {
	Dist        string // Distribution name.
	PkgPath     string // A slash separated path to the package.
	Module      string // Name of the module, can be blank for __init__.py (but not when PkgPath is also blank).
	BazelTarget string // Bazel target for this import.
	Type        string // py or so (currently not relevant).
}

ExternalModule is a Python module available from an external distribution.

type Language

type Language struct {
	Configurer
	Resolver
}

func (*Language) Fix

func (l *Language) Fix(c *config.Config, f *rule.File)

Fix implements language.Language.

func (*Language) GenerateRules

func (l *Language) GenerateRules(args language.GenerateArgs) language.GenerateResult

GenerateRules implements language.Language.

Generates one py_library (or py_binary) rule for each Python module, including one for __init__.py with name as the last component of the Python package name. If modules within a package depend on each other, then their src files are included in multiple rules, which allows us to have cyclical dependencies in the package. The inefficiency of repeating src files is expected to be minor because py_library is a very thin implementation. An alternative would be to disallow cycles and not repeat src files and depend on the rules for the modules, with the possible exception for __init__.py where cycles are common.

Each module also depends on the py_library rule for the package __init__.py, and the package __init__.py depends on its parent package __init__.py.

REQUIRES: No cyclical dependencies across packages.

REQUIRES: This is not a split namespace package.

REQUIRES: PYTHONSAFEPATH is enabled.

func (*Language) Kinds

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

Kinds implements language.Language.

func (*Language) Loads

func (l *Language) Loads() []rule.LoadInfo

Loads implements language.Language.

type Module

type Module struct {
	parser.Result
	ImportSpec   string
	PkgPath      string
	Name         string
	Filename     string
	InPkgDeps    map[*Module]struct{} // Module deps within the package.
	ExPkgImports []string             // Import statements not satisfied from within the package.
}

Module represents a parsed Python module.

func (*Module) DepsClosure

func (module *Module) DepsClosure()

DepsClosure expands the ModuleDeps to get all transitive deps.

func (Module) GenerateRule

func (module Module) GenerateRule(nameTemplate, relPythonRoot string) *rule.Rule

func (*Module) ProcessImports

func (module *Module) ProcessImports(moduleMap map[string]*Module, subPackages map[string]struct{})

ProcessImports computes direct InPkgDeps and ExPkgImports.

type Resolver

type Resolver struct{}

func (Resolver) Embeds

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

Embeds implements resolve.Resolver.

func (Resolver) Imports

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

Imports implements resolve.Resolver.

Returns all Python module import specs defined by the files in "srcs" attribute.

func (Resolver) Name

func (pr Resolver) Name() string

Name implements resolve.Resolve.

func (Resolver) Resolve

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

Resolve implements resolve.Resolver.

Directories

Path Synopsis
Package parser parses Python files and returns relevant information to the Gazelle Python extension.
Package parser parses Python files and returns relevant information to the Gazelle Python extension.

Jump to

Keyboard shortcuts

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