python

package
v3.114.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 42 Imported by: 60

Documentation

Overview

Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the goconst linter's warning.

Pulling out some of the repeated strings tokens into constants would harm readability, so we just ignore the goconst linter's warning.

Index

Constants

This section is empty.

Variables

View Source
var Importer schema.Language = importer(0)

Importer implements schema.Language for Python.

View Source
var Keywords = codegen.NewStringSet(
	"False",
	"None",
	"True",
	"and",
	"as",
	"assert",
	"async",
	"await",
	"break",
	"class",
	"continue",
	"def",
	"del",
	"elif",
	"else",
	"except",
	"exec",
	"finally",
	"for",
	"from",
	"global",
	"if",
	"import",
	"in",
	"is",
	"lambda",
	"nonlocal",
	"not",
	"or",
	"pass",
	"print",
	"raise",
	"return",
	"try",
	"while",
	"with",
	"yield")

Keywords is a map of reserved keywords used by Python 2 and 3. We use this to avoid generating unspeakable names in the resulting code. This map was sourced by merging the following reference material:

Functions

func Check added in v3.27.0

func Check(t *testing.T, path string, _ codegen.StringSet)

func EnsureKeywordSafe

func EnsureKeywordSafe(name string) string

EnsureKeywordSafe adds a trailing underscore if the generated name clashes with a Python 2 or 3 keyword, per PEP 8: https://www.python.org/dev/peps/pep-0008/?#function-and-method-arguments

func GeneratePackage

func GeneratePackage(tool string, pkg *schema.Package, extraFiles map[string][]byte) (map[string][]byte, error)

func GenerateProgram

func GenerateProgram(program *pcl.Program) (map[string][]byte, hcl.Diagnostics, error)

func GenerateProgramBatchTest added in v3.44.0

func GenerateProgramBatchTest(t *testing.T, testCases []test.ProgramTest)

func GenerateProject added in v3.31.0

func GenerateProject(
	directory string, project workspace.Project,
	program *pcl.Program, localDependencies map[string]string,
) error

func InitParamName

func InitParamName(name string) string

InitParamName returns a PyName-encoded name but also deduplicates the name against built-in parameters of resource __init__.

func LanguageResources

func LanguageResources(tool string, pkg *schema.Package) (map[string]LanguageResource, error)

LanguageResources returns a map of resources that can be used by downstream codegen. The map key is the resource schema token.

func PyName

func PyName(name string) string

PyName turns a variable or function name, normally using camelCase, to an underscore_case name.

func PypiVersion added in v3.104.0

func PypiVersion(v semver.Version) string

PypiVersion translates semver 2.0 into pypi's versioning scheme: Details can be found here: https://www.python.org/dev/peps/pep-0440/#version-scheme [N!]N(.N)*[{a|b|rc}N][.postN][.devN]

Types

type BuildSystem added in v3.81.0

type BuildSystem struct {
	Requires     []string `toml:"requires,omitempty" json:"requires,omitempty"`
	BuildBackend string   `toml:"build-backend,omitempty" json:"build-backend,omitempty"`
}

type Contact added in v3.69.0

type Contact struct {
	Name  string `toml:"name,omitempty" json:"name,omitempty"`
	Email string `toml:"email,omitempty" json:"email,omitempty"`
}

Contact references someone associated with the project, including their contact information. Contacts are used for both Authors and Maintainers, since both fields have the same schema and specification. It is often easier to specify both fields, but the precise rules for specifying either one or the other field can be found here: https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#authors-maintainers

type DocLanguageHelper

type DocLanguageHelper struct{}

DocLanguageHelper is the Python-specific implementation of the DocLanguageHelper.

func (DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType

func (d DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string

GetDocLinkForFunctionInputOrOutputType is not implemented at this time for Python.

func (DocLanguageHelper) GetDocLinkForPulumiType

func (d DocLanguageHelper) GetDocLinkForPulumiType(pkg *schema.Package, typeName string) string

GetDocLinkForPulumiType is not implemented at this time for Python.

func (DocLanguageHelper) GetDocLinkForResourceInputOrOutputType

func (d DocLanguageHelper) GetDocLinkForResourceInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string

GetDocLinkForResourceInputOrOutputType is not implemented at this time for Python.

func (DocLanguageHelper) GetDocLinkForResourceType

func (d DocLanguageHelper) GetDocLinkForResourceType(pkg *schema.Package, modName, typeName string) string

GetDocLinkForResourceType returns the Python API doc for a type belonging to a resource provider.

func (DocLanguageHelper) GetEnumName

func (d DocLanguageHelper) GetEnumName(e *schema.Enum, typeName string) (string, error)

GetEnumName returns the enum name specific to Python.

func (DocLanguageHelper) GetFunctionName

func (d DocLanguageHelper) GetFunctionName(modName string, f *schema.Function) string

func (DocLanguageHelper) GetLanguageTypeString

func (d DocLanguageHelper) GetLanguageTypeString(pkg *schema.Package, moduleName string, t schema.Type, input bool) string

GetLanguageTypeString returns the Python-specific type given a Pulumi schema type.

func (DocLanguageHelper) GetMethodName added in v3.10.2

func (d DocLanguageHelper) GetMethodName(m *schema.Method) string

func (DocLanguageHelper) GetMethodResultName added in v3.10.2

func (d DocLanguageHelper) GetMethodResultName(pkg *schema.Package, modName string, r *schema.Resource,
	m *schema.Method,
) string
func (d DocLanguageHelper) GetModuleDocLink(pkg *schema.Package, modName string) (string, string)

GetModuleDocLink returns the display name and the link for a module.

func (DocLanguageHelper) GetPropertyName

func (d DocLanguageHelper) GetPropertyName(p *schema.Property) (string, error)

GetPropertyName returns the property name specific to Python.

func (DocLanguageHelper) GetResourceFunctionResultName

func (d DocLanguageHelper) GetResourceFunctionResultName(modName string, f *schema.Function) string

GetResourceFunctionResultName returns the name of the result type when a function is used to lookup an existing resource.

type Entrypoints added in v3.69.0

type Entrypoints map[string]string

An Entrypoint is an object reference for an executable Python script. These scripts can be applications, plugins, or build-time metadata. Since Pulumi distributes libraries, we largely don't use this field, though we include it for completeness and consistency with the spec.

type LanguageResource

type LanguageResource struct {
	*schema.Resource

	Name    string // The resource name (e.g. Deployment)
	Package string // The package name (e.g. pulumi_kubernetes.apps.v1)
}

LanguageResource is derived from the schema and can be used by downstream codegen.

type License added in v3.69.0

type License struct {
	File string `toml:"file,omitempty" json:"file,omitempty"`
	Text string `toml:"text,omitempty" json:"text,omitempty"`
}

The license instance must populate either file or text, but not both. File is a path to a license file, while text is either the name of the license, or the text of the license.

type OptionalDependencies added in v3.69.0

type OptionalDependencies map[string][]string

OptionalDependencies provides a map from "Extras" (parlance specific to Python) to their dependencies. Each value in the array becomes a required dependency if the Extra is enabled.

type PackageInfo

type PackageInfo struct {
	// PackageName is an override for the name of the generated python package.
	PackageName string `json:"packageName,omitempty"`
	// PythonRequires determines the Python versions that the generated provider supports
	PythonRequires string            `json:"pythonRequires,omitempty"`
	Requires       map[string]string `json:"requires,omitempty"`
	// Readme contains the text for the package's README.md files.
	Readme string `json:"readme,omitempty"`
	// Optional overrides for Pulumi module names
	//
	//    { "flowcontrol.apiserver.k8s.io/v1alpha1": "flowcontrol/v1alpha1" }
	//
	ModuleNameOverrides map[string]string `json:"moduleNameOverrides,omitempty"`
	// Toggle compatibility mode for a specified target.
	Compatibility string `json:"compatibility,omitempty"`
	// Deprecated: This bool is no longer needed since all providers now use input/output classes.
	UsesIOClasses bool `json:"usesIOClasses,omitempty"`
	// Determines whether to make single-return-value methods return an output object or the single value.
	LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`

	// Respect the Pkg.Version field for emitted code.
	RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"`

	// If enabled, a pyproject.toml file will be generated.
	PyProject struct {
		Enabled bool `json:"enabled,omitempty"`
	} `json:"pyproject,omitempty"`
}

PackageInfo tracks Python-specific information associated with a package.

type Project added in v3.69.0

type Project struct {
	Name         *string     `toml:"name,omitempty" json:"name,omitempty"`
	Authors      []Contact   `toml:"authors,omitempty" json:"authors,omitempty"`
	Classifiers  []string    `toml:"classifiers,omitempty" json:"classifiers,omitempty"`
	Description  *string     `toml:"description,omitempty" json:"description,omitempty"`
	Dependencies []string    `toml:"dependencies,omitempty" json:"dependencies,omitempty"`
	Dynamic      []string    `toml:"dynamic,omitempty" json:"dynamic,omitempty"`
	EntryPoints  Entrypoints `toml:"entry-points,omitempty" json:"entry-points,omitempty"`
	GUIScripts   Entrypoints `toml:"gui-scripts,omitempty" json:"gui-scripts,omitempty"`
	// These are keywords used in package search.
	Keywords    []string  `toml:"keywords,omitempty" json:"keywords,omitempty"`
	License     *License  `toml:"license,omitempty" json:"license,omitempty"`
	Maintainers []Contact `toml:"maintainers,omitempty" json:"maintainers,omitempty"`
	//nolint:lll
	OptionalDependencies OptionalDependencies `toml:"optional-dependencies,omitempty" json:"optional-dependencies,omitempty"`
	// README is a path to a .md file or a .rst file
	README *string `toml:"readme,omitempty" json:"readme,omitempty"`
	// The version constraint e.g. ">=3.8"
	RequiresPython *string     `toml:"requires-python,omitempty" json:"requires-python,omitempty"`
	Scripts        Entrypoints `toml:"scripts,omitempty" json:"scripts,omitempty"`
	// URLs provides core metadata about this project's website, a link
	// to the repo, project documentation, and the project homepage.
	URLs map[string]string `toml:"urls,omitempty" json:"urls,omitempty"`
	// Version is the package version.
	Version *string `toml:"version,omitempty" json:"version,omitempty"`
}

Project is a view layer for a pyproject.toml file.

type PropertyInfo

type PropertyInfo struct {
	MapCase bool `json:"mapCase,omitempty"`
}

PropertyInfo tracks Python-specific information associated with properties in a package.

type PyprojectSchema added in v3.69.0

type PyprojectSchema struct {
	Project     *Project               `toml:"project,omitempty" json:"project,omitempty"`
	BuildSystem *BuildSystem           `toml:"build-system,omitempty" json:"build-system,omitempty"`
	Tool        map[string]interface{} `toml:"tool,omitempty" json:"tool,omitempty"`
}

The specification for the pyproject.toml file can be found here. https://packaging.python.org/en/latest/specifications/declaring-project-metadata/

Jump to

Keyboard shortcuts

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