Documentation ¶
Index ¶
- func NewLanguage() language.Language
- type Configuration
- type Configurer
- type ExternalModule
- type Language
- type Module
- type Resolver
- func (pr Resolver) Embeds(r *rule.Rule, from label.Label) []label.Label
- func (pr Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec
- func (pr Resolver) Name() string
- func (pr Resolver) Resolve(c *config.Config, ix *resolve.RuleIndex, _ *repo.RemoteCache, r *rule.Rule, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLanguage ¶
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 ¶
CheckFlags implements config.Configurer.
It performs any resource initialization based on the flags, validates the initial configuration, and sets the configuration extension.
func (Configurer) KnownDirectives ¶
func (pc Configurer) KnownDirectives() []string
KnownDirectives implements config.Configurer.
func (*Configurer) RegisterFlags ¶
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) 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.
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.