Skip to content

Commit

Permalink
fix python stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed Sep 12, 2024
1 parent 873d042 commit b1356ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
27 changes: 11 additions & 16 deletions pkg/codegen/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package codegen

import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/pulumi/pkg/v3/codegen/python"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)
Expand All @@ -35,23 +36,17 @@ func GeneratePython(pg *PackageGenerator, name string) (map[string]*bytes.Buffer
oldName := pkg.Name
pkg.Name = name

moduleToPackage, err := pg.ModuleToPackage()
// Save a serialized version of the package for debugging purposes.
// Save the unflattened OpenAPI spec for debugging purposes.
f2 := "/Users/rquitales/code/environs/pulumi-gen-sdk/new/pulumi-final-pkg.json"
file2, err := os.Create(f2)
if err != nil {
return nil, fmt.Errorf("%w", err)
}
pkg.Language[langName], err = ijson.RawMessage(map[string]any{
"compatibility": "kubernetes20",
"moduleNameOverrides": moduleToPackage,
"requires": map[string]string{
"pulumi": "\u003e=3.0.0,\u003c4.0.0",
"pyyaml": "\u003e=5.3",
"requests": "\u003e=2.21.0,\u003c2.22.0",
},
"ignorePyNamePanic": true,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal language metadata: %w", err)
return nil, fmt.Errorf("error opening file: %w", err)
}
defer file2.Close()
en2 := json.NewEncoder(file2)
en2.SetIndent("", " ")
en2.Encode(pkg)

files, err := python.GeneratePackage(PulumiToolName, pkg, nil)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (
)

// DefaultName specifies the default value for the package name
const DefaultName = "kubernetes" // Hack since upstream schemagen creates types in the `kubernetes` namespace.
const DefaultName = "crds"
const PulumiKubernetesNameShim = "kubernetes" // Hack since upstream schemagen creates types in the `kubernetes` namespace.

const (
Boolean string = "boolean"
Expand Down Expand Up @@ -131,7 +132,7 @@ func genPackage(version string, crgenerators []CustomResourceGenerator, includeO

// Populate the package spec with information used in previous versions of crd2pulumi to maintain backwards
// compatibility.
pkgSpec.Name = DefaultName
pkgSpec.Name = PulumiKubernetesNameShim
pkgSpec.Version = version
pkgSpec.Config = pschema.ConfigSpec{}
pkgSpec.Provider = pschema.ResourceSpec{}
Expand Down

0 comments on commit b1356ef

Please sign in to comment.