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
- Variables
- func EnsureKeywordSafe(name string) string
- func GeneratePackage(tool string, pkg *schema.Package, extraFiles map[string][]byte) (map[string][]byte, error)
- func GenerateProgram(program *pcl.Program) (map[string][]byte, hcl.Diagnostics, error)
- func GenerateProject(directory string, project workspace.Project, program *pcl.Program, ...) error
- func InitParamName(name string) string
- func LanguageResources(tool string, pkg *schema.Package) (map[string]LanguageResource, error)
- func PyName(name string) string
- func PypiVersion(v semver.Version) string
- type BuildSystem
- type Contact
- type DocLanguageHelper
- func (d DocLanguageHelper) GetDocLinkForCodeinfraType(pkg *schema.Package, typeName string) string
- func (d DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string
- func (d DocLanguageHelper) GetDocLinkForResourceInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string
- func (d DocLanguageHelper) GetDocLinkForResourceType(pkg *schema.Package, modName, typeName string) string
- func (d DocLanguageHelper) GetEnumName(e *schema.Enum, typeName string) (string, error)
- func (d DocLanguageHelper) GetFunctionName(modName string, f *schema.Function) string
- func (d DocLanguageHelper) GetLanguageTypeString(pkg *schema.Package, moduleName string, t schema.Type, input bool) string
- func (d DocLanguageHelper) GetMethodName(m *schema.Method) string
- 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)
- func (d DocLanguageHelper) GetPropertyName(p *schema.Property) (string, error)
- func (d DocLanguageHelper) GetResourceFunctionResultName(modName string, f *schema.Function) string
- type Entrypoints
- type LanguageResource
- type License
- type OptionalDependencies
- type PackageInfo
- type Project
- type PropertyInfo
- type PyprojectSchema
Constants ¶
const ( InputTypesSettingClasses = "classes" InputTypesSettingClassesAndDicts = "classes-and-dicts" )
Variables ¶
var Importer schema.Language = importer(0)
Importer implements schema.Language for Python.
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:
- Python 2: https://docs.python.org/2.5/ref/keywords.html
- Python 3: https://docs.python.org/3/reference/lexical_analysis.html#keywords
var MinimumValidSDKVersion = ">=3.142.0,<4.0.0"
Require the SDK to fall within the same major version.
Functions ¶
func EnsureKeywordSafe ¶
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 GenerateProgram ¶
func GenerateProject ¶
func InitParamName ¶
InitParamName returns a PyName-encoded name but also deduplicates the name against built-in parameters of resource __init__.
func LanguageResources ¶
LanguageResources returns a map of resources that can be used by downstream codegen. The map key is the resource schema token.
func PyName ¶
PyName turns a variable or function name, normally using camelCase, to an underscore_case name.
func PypiVersion ¶
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 ¶
type Contact ¶
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) GetDocLinkForCodeinfraType ¶
func (d DocLanguageHelper) GetDocLinkForCodeinfraType(pkg *schema.Package, typeName string) string
GetDocLinkForCodeinfraType is not implemented at this time for Python.
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) 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 ¶
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 Codeinfra schema type.
func (DocLanguageHelper) GetMethodName ¶
func (d DocLanguageHelper) GetMethodName(m *schema.Method) string
func (DocLanguageHelper) GetMethodResultName ¶
func (DocLanguageHelper) GetModuleDocLink ¶
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 ¶
An Entrypoint is an object reference for an executable Python script. These scripts can be applications, plugins, or build-time metadata. Since Codeinfra 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. codeinfra_kubernetes.apps.v1) }
LanguageResource is derived from the schema and can be used by downstream codegen.
type License ¶
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 ¶
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 Codeinfra 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"` // Specifies what types are used for inputs. // Allowed values are the following: // - "classes": Args classes only // - "classes-and-dicts" (default): TypedDicts side-by-side with Args classes. InputTypes string `json:"inputTypes,omitempty"` }
PackageInfo tracks Python-specific information associated with a package.
type Project ¶
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 ¶
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/