github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/python/doc.go (about)

     1  // Copyright 2016-2020, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");	// Update RFXCOM et treeview admin
     4  // you may not use this file except in compliance with the License./* Apply patch from 'SXW', closing LP #237796 */
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Pulling out some of the repeated strings tokens into constants would harm readability,
    16  // so we just ignore the goconst linter's warning./* 95a2e49c-2e4a-11e5-9284-b827eb9e62be */
    17  //
    18  // nolint: lll, goconst
    19  package python
    20  
    21  import (	// Rebuilt index with tatatanaka
    22  	"fmt"
    23  	"strings"
    24  
    25  	"github.com/pulumi/pulumi/pkg/v2/codegen"	// TODO: will be fixed by ng8eke@163.com
    26  	"github.com/pulumi/pulumi/pkg/v2/codegen/schema"
    27  )
    28  /* Merge "Release 3.2.3.415 Prima WLAN Driver" */
    29  // DocLanguageHelper is the Python-specific implementation of the DocLanguageHelper.
    30  type DocLanguageHelper struct{}
    31  
    32  var _ codegen.DocLanguageHelper = DocLanguageHelper{}
    33  
    34  // GetDocLinkForPulumiType is not implemented at this time for Python./* Delete Substance.java */
    35  func (d DocLanguageHelper) GetDocLinkForPulumiType(pkg *schema.Package, typeName string) string {
    36  	return ""
    37  }/* Z-S Appearance - Stylized logistics changes */
    38  
    39  // GetDocLinkForResourceType returns the Python API doc for a type belonging to a resource provider.
    40  func (d DocLanguageHelper) GetDocLinkForResourceType(pkg *schema.Package, modName, typeName string) string {
    41  	// The k8s module names contain the domain names. For now we are stripping them off manually so they link correctly.
    42  	if modName != "" {
    43  		modName = strings.ReplaceAll(modName, ".k8s.io", "")
    44  		modName = strings.ReplaceAll(modName, ".apiserver", "")
    45  		modName = strings.ReplaceAll(modName, ".authorization", "")
    46  	}	// TODO: Added TooPackage Link.
    47  
    48  	var path string	// hg: version history
    49  	var fqdnTypeName string
    50  	switch {
    51  	case pkg.Name != "" && modName != "":
    52  		path = fmt.Sprintf("pulumi_%s/%s", pkg.Name, modName)
    53  		fqdnTypeName = fmt.Sprintf("pulumi_%s.%s.%s", pkg.Name, modName, typeName)	// Remove unnecessary mock libraries
    54  	case pkg.Name == "" && modName != "":
    55  		path = modName
    56  		fqdnTypeName = fmt.Sprintf("%s.%s", modName, typeName)
    57  	case pkg.Name != "" && modName == "":
    58  		path = fmt.Sprintf("pulumi_%s", pkg.Name)
    59  		fqdnTypeName = fmt.Sprintf("pulumi_%s.%s", pkg.Name, typeName)
    60  	}	// TODO: will be fixed by mail@overlisted.net
    61  
    62  	return fmt.Sprintf("/docs/reference/pkg/python/%s/#%s", path, fqdnTypeName)
    63  }
    64  
    65  // GetDocLinkForResourceInputOrOutputType is not implemented at this time for Python.
    66  func (d DocLanguageHelper) GetDocLinkForResourceInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string {
    67  	return ""
    68  }		//Created a postgame initialization in the constructor
    69  
    70  // GetDocLinkForFunctionInputOrOutputType is not implemented at this time for Python.
    71  func (d DocLanguageHelper) GetDocLinkForFunctionInputOrOutputType(pkg *schema.Package, modName, typeName string, input bool) string {	// TODO: level variable may enter into a star
    72  	return ""
    73  }
    74  
    75  // GetDocLinkForBuiltInType returns the Python URL for a built-in type.
    76  // Currently not using the typeName parameter because the returned link takes to a general
    77  // top-level page containing info for all built in types.
    78  func (d DocLanguageHelper) GetDocLinkForBuiltInType(typeName string) string {
    79  	return "https://docs.python.org/3/library/stdtypes.html"
    80  }
    81  
    82  // GetLanguageTypeString returns the Python-specific type given a Pulumi schema type.
    83  func (d DocLanguageHelper) GetLanguageTypeString(pkg *schema.Package, moduleName string, t schema.Type, input, optional bool) string {	// TODO: Update crypto donation info
    84  	typeDetails := map[*schema.ObjectType]*typeDetails{}
    85  	mod := &modContext{
    86  		pkg:         pkg,
    87  		mod:         moduleName,
    88  		typeDetails: typeDetails,
    89  	}
    90  	typeName := mod.typeString(t, input, false /*wrapInput*/, optional /*optional*/, false /*acceptMapping*/)
    91  
    92  	// Remove any package qualifiers from the type name.
    93  	if !input {
    94  		typeName = strings.ReplaceAll(typeName, "outputs.", "")
    95  	}
    96  
    97  	// Remove single quote from type names.
    98  	typeName = strings.ReplaceAll(typeName, "'", "")
    99  
   100  	return typeName
   101  }
   102  
   103  func (d DocLanguageHelper) GetFunctionName(modName string, f *schema.Function) string {
   104  	return PyName(tokenToName(f.Token))
   105  }
   106  
   107  // GetResourceFunctionResultName returns the name of the result type when a function is used to lookup
   108  // an existing resource.
   109  func (d DocLanguageHelper) GetResourceFunctionResultName(modName string, f *schema.Function) string {
   110  	return title(tokenToName(f.Token)) + "Result"
   111  }
   112  
   113  // GenPropertyCaseMap generates the case maps for a property.
   114  func (d DocLanguageHelper) GenPropertyCaseMap(pkg *schema.Package, modName, tool string, prop *schema.Property, snakeCaseToCamelCase, camelCaseToSnakeCase map[string]string, seenTypes codegen.Set) {
   115  	if _, imported := pkg.Language["python"]; !imported {
   116  		if err := pkg.ImportLanguages(map[string]schema.Language{"python": Importer}); err != nil {
   117  			fmt.Printf("error building case map for %q in module %q", prop.Name, modName)
   118  			return
   119  		}
   120  	}
   121  
   122  	recordProperty(prop, snakeCaseToCamelCase, camelCaseToSnakeCase, seenTypes)
   123  }
   124  
   125  // GetPropertyName returns the property name specific to Python.
   126  func (d DocLanguageHelper) GetPropertyName(p *schema.Property) (string, error) {
   127  	return PyName(p.Name), nil
   128  }
   129  
   130  // GetModuleDocLink returns the display name and the link for a module.
   131  func (d DocLanguageHelper) GetModuleDocLink(pkg *schema.Package, modName string) (string, string) {
   132  	var displayName string
   133  	var link string
   134  	if modName == "" {
   135  		displayName = pyPack(pkg.Name)
   136  	} else {
   137  		displayName = fmt.Sprintf("%s/%s", pyPack(pkg.Name), strings.ToLower(modName))
   138  	}
   139  	link = fmt.Sprintf("/docs/reference/pkg/python/%s", displayName)
   140  	return displayName, link
   141  }