Skip to content

Commit

Permalink
Try to auto-build python SDK referenced by path (temporalio#519)
Browse files Browse the repository at this point in the history
* Try to auto-build python SDK referenced by path

* Fix typo

Co-authored-by: Dan Davison <[email protected]>

---------

Co-authored-by: Dan Davison <[email protected]>
  • Loading branch information
Sushisource and dandavison authored Aug 6, 2024
1 parent 0e085c5 commit f67fbc5
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions sdkbuild/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,39 @@ func BuildPythonProgram(ctx context.Context, options BuildPythonProgramOptions)
versionStr := strconv.Quote(strings.TrimPrefix(options.Version, "v"))
if strings.ContainsAny(options.Version, `/\`) {
// We expect a dist/ directory with a single whl file present
wheels, err := filepath.Glob(filepath.Join(options.Version, "dist/*.whl"))
sdkPath, err := filepath.Abs(options.Version)
if err != nil {
return nil, fmt.Errorf("unable to make sdk path absolute: %w", err)
}
triedBuilding := false

getWheels:
wheels, err := filepath.Glob(filepath.Join(sdkPath, "dist/*.whl"))
if err != nil {
return nil, fmt.Errorf("failed glob wheel lookup: %w", err)
} else if len(wheels) == 0 && !triedBuilding {
triedBuilding = true
// Try to build the project
cmd := exec.CommandContext(ctx, "poetry", "install", "--no-root")
cmd.Dir = sdkPath
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
err = cmd.Run()
if err != nil {
return nil, fmt.Errorf("problem installing deps when building sdk by path: %w", err)
}
cmd = exec.CommandContext(ctx, "poetry", "build")
cmd.Dir = sdkPath
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
err = cmd.Run()
if err != nil {
return nil, fmt.Errorf("problem buildling sdk by path: %w", err)
}
// This constitutes a legitimate use of goto, fight me.
goto getWheels
} else if len(wheels) != 1 {
return nil, fmt.Errorf("expected single dist wheel, found %v", wheels)
return nil, fmt.Errorf("expected single dist wheel, found %v - consider cleaning dist dir", wheels)
}

absWheel, err := filepath.Abs(wheels[0])
if err != nil {
return nil, fmt.Errorf("unable to make wheel path absolute: %w", err)
Expand Down

0 comments on commit f67fbc5

Please sign in to comment.