feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
package generators
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-03-26 17:41:53 +00:00
|
|
|
"dappco.re/go/core/build/internal/ax"
|
2026-03-22 01:34:37 +00:00
|
|
|
coreerr "dappco.re/go/core/log"
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// PythonGenerator generates Python SDKs from OpenAPI specs.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// g := generators.NewPythonGenerator()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
type PythonGenerator struct{}
|
|
|
|
|
|
|
|
|
|
// NewPythonGenerator creates a new Python generator.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// g := generators.NewPythonGenerator()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func NewPythonGenerator() *PythonGenerator {
|
|
|
|
|
return &PythonGenerator{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Language returns the generator's target language identifier.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// lang := g.Language() // → "python"
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func (g *PythonGenerator) Language() string {
|
|
|
|
|
return "python"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Available checks if generator dependencies are installed.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// if g.Available() { err = g.Generate(ctx, opts) }
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func (g *PythonGenerator) Available() bool {
|
2026-03-30 01:28:57 +00:00
|
|
|
_, err := g.resolveNativeCli()
|
|
|
|
|
return err == nil || dockerRuntimeAvailable()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Install returns instructions for installing the generator.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// fmt.Println(g.Install()) // → "pip install openapi-python-client"
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func (g *PythonGenerator) Install() string {
|
|
|
|
|
return "pip install openapi-python-client"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate creates SDK from OpenAPI spec.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// err := g.Generate(ctx, generators.Options{SpecPath: "docs/openapi.yaml", OutputDir: "sdk/python"})
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func (g *PythonGenerator) Generate(ctx context.Context, opts Options) error {
|
2026-03-30 05:29:24 +00:00
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return coreerr.E("python.Generate", "generation cancelled", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 00:05:46 +00:00
|
|
|
if err := ax.MkdirAll(opts.OutputDir, 0o755); err != nil {
|
2026-03-16 21:03:21 +00:00
|
|
|
return coreerr.E("python.Generate", "failed to create output dir", err)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 01:28:57 +00:00
|
|
|
if command, err := g.resolveNativeCli(); err == nil {
|
|
|
|
|
return g.generateNative(ctx, opts, command)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
2026-03-30 05:29:24 +00:00
|
|
|
if !dockerRuntimeAvailableWithContext(ctx) {
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return coreerr.E("python.Generate", "generation cancelled", err)
|
|
|
|
|
}
|
2026-03-26 14:58:13 +00:00
|
|
|
return coreerr.E("python.Generate", "Docker is required for fallback generation but not available", nil)
|
|
|
|
|
}
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
return g.generateDocker(ctx, opts)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 01:28:57 +00:00
|
|
|
func (g *PythonGenerator) resolveNativeCli(paths ...string) (string, error) {
|
|
|
|
|
command, err := ax.ResolveCommand("openapi-python-client", paths...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", coreerr.E("python.resolveNativeCli", "openapi-python-client not found. Install it with: "+g.Install(), err)
|
|
|
|
|
}
|
|
|
|
|
return command, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *PythonGenerator) generateNative(ctx context.Context, opts Options, command string) error {
|
2026-03-26 17:41:53 +00:00
|
|
|
parentDir := ax.Dir(opts.OutputDir)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
|
2026-03-30 01:28:57 +00:00
|
|
|
return ax.ExecDir(ctx, parentDir, command, "generate",
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
"--path", opts.SpecPath,
|
|
|
|
|
"--output-path", opts.OutputDir,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *PythonGenerator) generateDocker(ctx context.Context, opts Options) error {
|
2026-03-30 01:28:57 +00:00
|
|
|
dockerCommand, err := resolveDockerRuntimeCli()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return coreerr.E("python.generateDocker", "docker CLI not available", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 17:41:53 +00:00
|
|
|
specDir := ax.Dir(opts.SpecPath)
|
|
|
|
|
specName := ax.Base(opts.SpecPath)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
|
|
|
|
|
args := []string{"run", "--rm"}
|
|
|
|
|
args = append(args, dockerUserArgs()...)
|
|
|
|
|
args = append(args,
|
|
|
|
|
"-v", specDir+":/spec",
|
|
|
|
|
"-v", opts.OutputDir+":/out",
|
|
|
|
|
"openapitools/openapi-generator-cli", "generate",
|
|
|
|
|
"-i", "/spec/"+specName,
|
|
|
|
|
"-g", "python",
|
|
|
|
|
"-o", "/out",
|
|
|
|
|
"--additional-properties=packageName="+opts.PackageName,
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-30 01:28:57 +00:00
|
|
|
return ax.Exec(ctx, dockerCommand, args...)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|