From 299de178e2ea4d421f52ee0e45623fe85089f0aa Mon Sep 17 00:00:00 2001 From: Yang Kaiyong Date: Mon, 3 Mar 2025 20:09:53 +0800 Subject: [PATCH 1/2] refactor(processor): replace filepath.Glob with doublestar.Glob for enhanced pattern matching - Replaced `filepath.Glob` with `doublestar.Glob` to support advanced glob patterns (e.g., `**/*.py` for recursive matching). Signed-off-by: Yang Kaiyong --- go.mod | 1 + go.sum | 2 ++ pkg/backend/processor/base.go | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 07446cd4..467ba724 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/VividCortex/ewma v1.2.0 // indirect github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bmatcuk/doublestar/v4 v4.8.1 github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect diff --git a/go.sum b/go.sum index 9f76ae12..7aef594f 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38= +github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= diff --git a/pkg/backend/processor/base.go b/pkg/backend/processor/base.go index bb12a6ba..29ce2aa8 100644 --- a/pkg/backend/processor/base.go +++ b/pkg/backend/processor/base.go @@ -19,6 +19,7 @@ package processor import ( "context" "fmt" + "os" "path/filepath" "sort" "sync" @@ -26,6 +27,7 @@ import ( "github.com/CloudNativeAI/modctl/pkg/backend/build" "github.com/CloudNativeAI/modctl/pkg/storage" + doublestar "github.com/bmatcuk/doublestar/v4" "github.com/chelnak/ysmrr" humanize "github.com/dustin/go-humanize" @@ -58,11 +60,14 @@ func (b *base) Process(ctx context.Context, workDir, repo string, opts ...Option var matchedPaths []string for _, pattern := range b.patterns { - matches, err := filepath.Glob(filepath.Join(absWorkDir, pattern)) + matches, err := doublestar.Glob(os.DirFS(absWorkDir), pattern) if err != nil { return nil, err } - + // convert to absolute paths + for i := range matches { + matches[i] = filepath.Join(absWorkDir, matches[i]) + } matchedPaths = append(matchedPaths, matches...) } From ea5b98ed9c7f028705b57d0a8481964c31921915 Mon Sep 17 00:00:00 2001 From: Yang Kaiyong Date: Tue, 4 Mar 2025 10:05:43 +0800 Subject: [PATCH 2/2] docs: add documentation for unix-like glob path pattern support in modelfile Added a detailed explanation of the unix-like glob path pattern. Signed-off-by: Yang Kaiyong --- docs/getting-started.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 2d9ec077..92351259 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -22,6 +22,11 @@ $ ./output/modctl -h Build the model artifact you need to prepare a Modelfile describe your expected layout of the model artifact in your model repo. +Notes: We support Unix-like glob path patterns, where: +- `*` matches any number of characters except path separators (`/`). +- `**` matches any number of directories, including zero directories. +For example, `**/*.py` matches all `.py` files in the current directory and its subdirectories. + Example of Modelfile: ```shell