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-26 17:41:53 +00:00
|
|
|
// Usage example: declare a value of type generators.PythonGenerator in integrating code.
|
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-26 17:41:53 +00:00
|
|
|
// Usage example: call generators.NewPythonGenerator(...) from integrating code.
|
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-26 17:41:53 +00:00
|
|
|
// Usage example: call value.Language(...) from integrating code.
|
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-26 17:41:53 +00:00
|
|
|
// Usage example: call value.Available(...) from integrating code.
|
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-26 17:41:53 +00:00
|
|
|
_, err := ax.LookPath("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
|
|
|
return err == nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Install returns instructions for installing the generator.
|
2026-03-26 17:41:53 +00:00
|
|
|
// Usage example: call value.Install(...) from integrating code.
|
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-26 17:41:53 +00:00
|
|
|
// Usage example: call value.Generate(...) from integrating code.
|
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 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if g.Available() {
|
|
|
|
|
return g.generateNative(ctx, opts)
|
|
|
|
|
}
|
2026-03-26 14:58:13 +00:00
|
|
|
if !dockerRuntimeAvailable() {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *PythonGenerator) generateNative(ctx context.Context, opts Options) 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-26 17:41:53 +00:00
|
|
|
return ax.ExecDir(ctx, parentDir, "openapi-python-client", "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-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-26 17:41:53 +00:00
|
|
|
return ax.Exec(ctx, "docker", 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
|
|
|
}
|