pythonconfig

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: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PythonExtensionDirective represents the directive that controls whether
	// this Python extension is enabled or not. Sub-packages inherit this value.
	// Can be either "enabled" or "disabled". Defaults to "enabled".
	PythonExtensionDirective = "python_extension"
	// PythonRootDirective represents the directive that sets a Bazel package as
	// a Python root. This is used on monorepos with multiple Python projects
	// that don't share the top-level of the workspace as the root.
	PythonRootDirective = "python_root"
	// PythonManifestFileNameDirective represents the directive that overrides
	// the default gazelle_python.yaml manifest file name.
	PythonManifestFileNameDirective = "python_manifest_file_name"
	// IgnoreFilesDirective represents the directive that controls the ignored
	// files from the generated targets.
	IgnoreFilesDirective = "python_ignore_files"
	// IgnoreDependenciesDirective represents the directive that controls the
	// ignored dependencies from the generated targets.
	IgnoreDependenciesDirective = "python_ignore_dependencies"
	// ValidateImportStatementsDirective represents the directive that controls
	// whether the Python import statements should be validated.
	ValidateImportStatementsDirective = "python_validate_import_statements"
	// GenerationMode represents the directive that controls the target generation
	// mode. See below for the GenerationModeType constants.
	GenerationMode = "python_generation_mode"
	// GenerationModePerFileIncludeInit represents the directive that augments
	// the "per_file" GenerationMode by including the package's __init__.py file.
	// This is a boolean directive.
	GenerationModePerFileIncludeInit = "python_generation_mode_per_file_include_init"
	// GenerationModePerPackageRequireTestEntryPoint represents the directive that
	// requires a test entry point to generate test targets in "package" GenerationMode.
	// This is a boolean directive.
	GenerationModePerPackageRequireTestEntryPoint = "python_generation_mode_per_package_require_test_entry_point"
	// LibraryNamingConvention represents the directive that controls the
	// py_library naming convention. It interpolates $package_name$ with the
	// Bazel package name. E.g. if the Bazel package name is `foo`, setting this
	// to `$package_name$_my_lib` would render to `foo_my_lib`.
	LibraryNamingConvention = "python_library_naming_convention"
	// BinaryNamingConvention represents the directive that controls the
	// py_binary naming convention. See python_library_naming_convention for
	// more info on the package name interpolation.
	BinaryNamingConvention = "python_binary_naming_convention"
	// TestNamingConvention represents the directive that controls the py_test
	// naming convention. See python_library_naming_convention for more info on
	// the package name interpolation.
	TestNamingConvention = "python_test_naming_convention"
	// DefaultVisibilty represents the directive that controls what visibility
	// labels are added to generated python targets.
	DefaultVisibilty = "python_default_visibility"
	// Visibility represents the directive that controls what additional
	// visibility labels are added to generated targets. It mimics the behavior
	// of the `go_visibility` directive.
	Visibility = "python_visibility"
	// TestFilePattern represents the directive that controls which python
	// files are mapped to `py_test` targets.
	TestFilePattern = "python_test_file_pattern"
	// LabelConvention represents the directive that defines the format of the
	// labels to third-party dependencies.
	LabelConvention = "python_label_convention"
	// LabelNormalization represents the directive that controls how distribution
	// names of labels to third-party dependencies are normalized. Supported values
	// are 'none', 'pep503' and 'snake_case' (default). See LabelNormalizationType.
	LabelNormalization = "python_label_normalization"
)

Directives

View Source
const (
	// The default visibility label, including a format placeholder for `python_root`.
	DefaultVisibilityFmtString = "//%s:__subpackages__"
	// The default globs used to determine pt_test targets.
	DefaultTestFilePatternString = "*_test.py,test_*.py"
	// The default convention of label of third-party dependencies.
	DefaultLabelConvention = "$distribution_name$"
	// The default normalization applied to distribution names of third-party dependency labels.
	DefaultLabelNormalizationType = SnakeCaseLabelNormalizationType
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config represents a config extension for a specific Bazel package.

func New

func New(
	repoRoot string,
	pythonProjectRoot string,
) *Config

New creates a new Config.

func (*Config) AddExcludedPattern

func (c *Config) AddExcludedPattern(pattern string)

AddExcludedPattern adds a glob pattern parsed from the standard gazelle:exclude directive.

func (*Config) AddIgnoreDependency

func (c *Config) AddIgnoreDependency(dep string)

AddIgnoreDependency adds a dependency to the list of ignored dependencies for a given package. Adding an ignored dependency to a package also makes it ignored on a subpackage.

func (*Config) AddIgnoreFile

func (c *Config) AddIgnoreFile(file string)

AddIgnoreFile adds a file to the list of ignored files for a given package. Adding an ignored file to a package also makes it ignored on a subpackage.

func (*Config) AppendVisibility

func (c *Config) AppendVisibility(visibility string)

AppendVisibility adds additional items to the target's visibility.

func (*Config) CoarseGrainedGeneration

func (c *Config) CoarseGrainedGeneration() bool

CoarseGrainedGeneration returns whether coarse-grained targets should be generated or not.

func (*Config) DefaultVisibilty

func (c *Config) DefaultVisibilty() []string

DefaultVisibilty returns the target's default visibility.

func (*Config) ExcludedPatterns

func (c *Config) ExcludedPatterns() *singlylinkedlist.List

ExcludedPatterns returns the excluded patterns list.

func (*Config) ExtensionEnabled

func (c *Config) ExtensionEnabled() bool

ExtensionEnabled returns whether the extension is enabled or not.

func (*Config) FindThirdPartyDependency

func (c *Config) FindThirdPartyDependency(modName string) (string, string, bool)

FindThirdPartyDependency scans the gazelle manifests for the current config and the parent configs up to the root finding if it can resolve the module name.

func (*Config) FormatThirdPartyDependency

func (c *Config) FormatThirdPartyDependency(repositoryName string, distributionName string) label.Label

FormatThirdPartyDependency returns a label to a third-party dependency performing all formating and normalization.

func (*Config) IgnoresDependency

func (c *Config) IgnoresDependency(dep string) bool

IgnoresDependency checks if a dependency is ignored in the given package or in one of the parent packages up to the workspace root.

func (*Config) IgnoresFile

func (c *Config) IgnoresFile(file string) bool

IgnoresFile checks if a file is ignored in the given package or in one of the parent packages up to the workspace root.

func (*Config) LabelConvention

func (c *Config) LabelConvention() string

LabelConvention returns the label convention used for third-party dependencies.

func (*Config) LabelNormalization

func (c *Config) LabelNormalization() LabelNormalizationType

LabelConvention returns the label normalization applied to distribution names of third-party dependencies.

func (*Config) NewChild

func (c *Config) NewChild() *Config

NewChild creates a new child Config. It inherits desired values from the current Config and sets itself as the parent to the child.

func (*Config) Parent

func (c *Config) Parent() *Config

Parent returns the parent config.

func (*Config) PerFileGeneration

func (c *Config) PerFileGeneration() bool

PerFileGeneration returns whether a separate py_library target should be generated for each file.

func (*Config) PerFileGenerationIncludeInit

func (c *Config) PerFileGenerationIncludeInit() bool

PerFileGenerationIncludeInit returns whether py_library targets should include __init__.py files when PerFileGeneration() is true.

func (*Config) PerPackageGenerationRequireTestEntryPoint

func (c *Config) PerPackageGenerationRequireTestEntryPoint() bool

func (*Config) PythonProjectRoot

func (c *Config) PythonProjectRoot() string

PythonProjectRoot returns the Python project root.

func (*Config) RenderBinaryName

func (c *Config) RenderBinaryName(packageName string) string

RenderBinaryName returns the py_binary target name by performing all substitutions.

func (*Config) RenderLibraryName

func (c *Config) RenderLibraryName(packageName string) string

RenderLibraryName returns the py_library target name by performing all substitutions.

func (*Config) RenderTestName

func (c *Config) RenderTestName(packageName string) string

RenderTestName returns the py_test target name by performing all substitutions.

func (*Config) SetBinaryNamingConvention

func (c *Config) SetBinaryNamingConvention(binaryNamingConvention string)

SetBinaryNamingConvention sets the py_binary target naming convention.

func (*Config) SetCoarseGrainedGeneration

func (c *Config) SetCoarseGrainedGeneration(coarseGrained bool)

SetCoarseGrainedGeneration sets whether coarse-grained targets should be generated or not.

func (*Config) SetDefaultVisibility

func (c *Config) SetDefaultVisibility(visibility []string)

SetDefaultVisibility sets the default visibility of the target.

func (*Config) SetExtensionEnabled

func (c *Config) SetExtensionEnabled(enabled bool)

SetExtensionEnabled sets whether the extension is enabled or not.

func (*Config) SetGazelleManifest

func (c *Config) SetGazelleManifest(gazelleManifest *manifest.Manifest)

SetGazelleManifest sets the Gazelle manifest parsed from the gazelle_python.yaml file.

func (*Config) SetLabelConvention

func (c *Config) SetLabelConvention(convention string)

SetLabelConvention sets the label convention used for third-party dependencies.

func (*Config) SetLabelNormalization

func (c *Config) SetLabelNormalization(normalizationType LabelNormalizationType)

SetLabelConvention sets the label normalization applied to distribution names of third-party dependencies.

func (*Config) SetLibraryNamingConvention

func (c *Config) SetLibraryNamingConvention(libraryNamingConvention string)

SetLibraryNamingConvention sets the py_library target naming convention.

func (*Config) SetPerFileGeneration

func (c *Config) SetPerFileGeneration(perFile bool)

SetPerFileGneration sets whether a separate py_library target should be generated for each file.

func (*Config) SetPerFileGenerationIncludeInit

func (c *Config) SetPerFileGenerationIncludeInit(includeInit bool)

SetPerFileGenerationIncludeInit sets whether py_library targets should include __init__.py files when PerFileGeneration() is true.

func (*Config) SetPerPackageGenerationRequireTestEntryPoint

func (c *Config) SetPerPackageGenerationRequireTestEntryPoint(perPackageGenerationRequireTestEntryPoint bool)

func (*Config) SetPythonProjectRoot

func (c *Config) SetPythonProjectRoot(pythonProjectRoot string)

SetPythonProjectRoot sets the Python project root.

func (*Config) SetTestFilePattern

func (c *Config) SetTestFilePattern(patterns []string)

SetTestFilePattern sets the file patterns that should be mapped to 'py_test' rules.

func (*Config) SetTestNamingConvention

func (c *Config) SetTestNamingConvention(testNamingConvention string)

SetTestNamingConvention sets the py_test target naming convention.

func (*Config) SetValidateImportStatements

func (c *Config) SetValidateImportStatements(validate bool)

SetValidateImportStatements sets whether Python import statements should be validated or not. It throws an error if this is set multiple times, i.e. if the directive is specified multiple times in the Bazel workspace.

func (*Config) TestFilePattern

func (c *Config) TestFilePattern() []string

TestFilePattern returns the patterns that should be mapped to 'py_test' rules.

func (*Config) ValidateImportStatements

func (c *Config) ValidateImportStatements() bool

ValidateImportStatements returns whether the Python import statements should be validated or not. If this option was not explicitly specified by the user, it defaults to true.

func (*Config) Visibility

func (c *Config) Visibility() []string

Visibility returns the target's visibility.

type Configs

type Configs map[string]*Config

Configs is an extension of map[string]*Config. It provides finding methods on top of the mapping.

func (*Configs) ParentForPackage

func (c *Configs) ParentForPackage(pkg string) *Config

ParentForPackage returns the parent Config for the given Bazel package.

type GenerationModeType

type GenerationModeType string

GenerationModeType represents one of the generation modes for the Python extension.

const (
	// GenerationModePackage defines the mode in which targets will be generated
	// for each __init__.py, or when an existing BUILD or BUILD.bazel file already
	// determines a Bazel package.
	GenerationModePackage GenerationModeType = "package"
	// GenerationModeProject defines the mode in which a coarse-grained target will
	// be generated englobing sub-directories containing Python files.
	GenerationModeProject GenerationModeType = "project"
	GenerationModeFile    GenerationModeType = "file"
)

Generation modes

type LabelNormalizationType

type LabelNormalizationType int
const (
	NoLabelNormalizationType LabelNormalizationType = iota
	Pep503LabelNormalizationType
	SnakeCaseLabelNormalizationType
)

type StringMapList

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

StringMapList satisfies the flag.Value interface. It constructs a string map by parsing the flag string value using the provided list and map separators.

func NewStringMapList

func NewStringMapList(listSeparator, mapSeparator string) *StringMapList

NewStringMapList constructs a new StringMapList with the given separators.

func (*StringMapList) Get

func (sml *StringMapList) Get(key string) (string, bool)

Get returns the value for the given key.

func (*StringMapList) Set

func (sml *StringMapList) Set(s string) error

Set satisfies flag.Value.Set.

func (*StringMapList) String

func (sml *StringMapList) String() string

String satisfies flag.Value.String.

type StringSet

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

StringSet satisfies the flag.Value interface. It constructs a set backed by a hashmap by parsing the flag string value using the provided separator.

func NewStringSet

func NewStringSet(separator string) *StringSet

NewStringSet constructs a new StringSet with the given separator.

func (*StringSet) Contains

func (ss *StringSet) Contains(s string) bool

Contains returns whether the StringSet contains the provided element or not.

func (*StringSet) Set

func (ss *StringSet) Set(s string) error

Set satisfies flag.Value.Set.

func (*StringSet) String

func (ss *StringSet) String() string

String satisfies flag.Value.String.

Jump to

Keyboard shortcuts

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