-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
bat
command to build-and-test applications
This moves the data-prep-kit tests out of tests/tests and into demos/data-prep-kit, and updates their layout to improve compatbility with the test-data scheme. Also fixes: tester should Down() the run Signed-off-by: Nick Mitchell <nickm@us.ibm.com>
- Loading branch information
Showing
218 changed files
with
316 additions
and
767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//go:build full || manage | ||
|
||
package subcommands | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"lunchpail.io/cmd/options" | ||
"lunchpail.io/pkg/be" | ||
"lunchpail.io/pkg/boot" | ||
) | ||
|
||
func init() { | ||
var cmd = &cobra.Command{ | ||
Use: "bat", | ||
Short: "Build and test", | ||
Long: "Build and test", | ||
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs), | ||
} | ||
|
||
buildOpts, err := options.AddBuildOptions(cmd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
concurrency := 4 | ||
cmd.Flags().IntVarP(&concurrency, "concurrency", "j", concurrency, "Maximum tests to run concurrently") | ||
|
||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
|
||
backend, err := be.NewInitOk(ctx, true, *buildOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return boot.BuildAndTester{Backend: backend, Concurrency: concurrency, Options: *buildOpts}.RunAll(ctx, args) | ||
} | ||
|
||
rootCmd.AddCommand(cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Lunchpail data-prep-kit Demos | ||
|
||
These are ports of most of the transforms from the [data-prep-kit](https://github.com/IBM/data-prep-kit). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ode-header-cleanser/pail/requirements.txt → ...kit/code/header-cleanser/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+3.72 KB
demos/data-prep-kit/language/pii-redactor/test-data/sm/expected/sm.parquet.gz
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
max_rows_per_table: 125 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python3.12 main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker.io/python:3.12 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
//go:build full || manage | ||
|
||
package boot | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"slices" | ||
|
||
"golang.org/x/sync/errgroup" | ||
|
||
"lunchpail.io/pkg/be" | ||
"lunchpail.io/pkg/build" | ||
"lunchpail.io/pkg/fe/builder" | ||
"lunchpail.io/pkg/fe/builder/overlay" | ||
"lunchpail.io/pkg/observe/colors" | ||
) | ||
|
||
type BuildAndTester struct { | ||
Concurrency int | ||
be.Backend | ||
build.Options | ||
} | ||
|
||
// Run build&test for all applications in all of the given `dirs` | ||
func (t BuildAndTester) RunAll(ctx context.Context, dirs []string) error { | ||
fmt.Fprintln(os.Stderr, "Starting build and test for", dirs) | ||
|
||
dirForBinaries, err := ioutil.TempDir("", "lunchpail-bat-") | ||
if err != nil { | ||
return err | ||
} | ||
defer os.RemoveAll(dirForBinaries) | ||
|
||
group, gctx := errgroup.WithContext(ctx) | ||
if t.Concurrency != 0 { | ||
group.SetLimit(t.Concurrency) | ||
} | ||
|
||
for _, dir := range dirs { | ||
if err := t.RunDir(gctx, group, dir, dirForBinaries); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return group.Wait() | ||
} | ||
|
||
// Run build&test for all applications in the given `dir` | ||
func (t BuildAndTester) RunDir(ctx context.Context, group *errgroup.Group, dir, dirForBinaries string) error { | ||
return filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
if d.Name() == "src" || d.Name() == "test-data" { | ||
return fs.SkipDir | ||
} else if !d.IsDir() || d.Name() == filepath.Base(dir) { | ||
return nil | ||
} | ||
|
||
if files, err := os.ReadDir(path); err != nil { | ||
return err | ||
} else if slices.IndexFunc(files, func(f fs.DirEntry) bool { return f.Name() == "src" || f.Name() == "test-data" }) < 0 { | ||
// not an app directory | ||
if t.Options.Verbose() { | ||
fmt.Fprintln(os.Stderr, "Skipping build and test for", path) | ||
} | ||
return nil | ||
} | ||
|
||
group.Go(func() error { | ||
binaryRelPath, err := filepath.Rel(dir, path) | ||
if err != nil { | ||
return err | ||
} | ||
binaryFullPath := filepath.Join(dirForBinaries, binaryRelPath) | ||
return t.Run(ctx, path, binaryRelPath, binaryFullPath) | ||
}) | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
// Run one build&test for the application specified in `sourcePath`, storing the build in `binaryFullPath` | ||
func (t BuildAndTester) Run(ctx context.Context, sourcePath, binaryRelPath, binaryFullPath string) error { | ||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
default: | ||
} | ||
|
||
if err := builder.Build( | ||
ctx, | ||
sourcePath, | ||
builder.Options{ | ||
Name: binaryFullPath, | ||
OverlayOptions: overlay.Options{BuildOptions: t.Options}, | ||
}, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
args := []string{"test"} | ||
if t.Options.Verbose() { | ||
args = append(args, "--verbose") | ||
} | ||
|
||
cmd := exec.CommandContext(ctx, binaryFullPath, args...) | ||
|
||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
stderr, err := cmd.StderrPipe() | ||
if err != nil { | ||
return err | ||
} | ||
if err := cmd.Start(); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error launching test %s: %v\n", binaryRelPath, err) | ||
return err | ||
} | ||
doneout := make(chan struct{}) | ||
doneerr := make(chan struct{}) | ||
|
||
go pipe(binaryRelPath, stdout, os.Stdout, doneout) | ||
go pipe(binaryRelPath, stderr, os.Stderr, doneerr) | ||
|
||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case <-doneout: | ||
} | ||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case <-doneerr: | ||
} | ||
|
||
return cmd.Wait() | ||
} | ||
|
||
// Pipe the output of the test, prefixing emitted lines with the given prefix (application name) | ||
func pipe(prefix string, r io.Reader, w io.Writer, done chan<- struct{}) { | ||
reader := bufio.NewReader(r) | ||
|
||
for { | ||
line, _, err := reader.ReadLine() | ||
|
||
if err == io.EOF { | ||
break | ||
} | ||
|
||
fmt.Fprintf(w, "%s %s\n", colors.Yellow.Render(prefix), line) | ||
} | ||
|
||
done <- struct{}{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.