mirror of https://github.com/databricks/cli.git
removed sync include code
This commit is contained in:
parent
2be69af604
commit
2e3c5ca9ea
|
@ -22,8 +22,6 @@ import (
|
||||||
"github.com/hashicorp/terraform-exec/tfexec"
|
"github.com/hashicorp/terraform-exec/tfexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
const InternalFolder = ".internal"
|
|
||||||
|
|
||||||
type Bundle struct {
|
type Bundle struct {
|
||||||
Config config.Root
|
Config config.Root
|
||||||
|
|
||||||
|
@ -153,21 +151,6 @@ func (b *Bundle) CacheDir(paths ...string) (string, error) {
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bundle) InternalDir() (string, error) {
|
|
||||||
cacheDir, err := b.CacheDir()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
dir := filepath.Join(cacheDir, InternalFolder)
|
|
||||||
err = os.MkdirAll(dir, 0700)
|
|
||||||
if err != nil {
|
|
||||||
return dir, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return dir, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Bundle) GitRepository() (*git.Repository, error) {
|
func (b *Bundle) GitRepository() (*git.Repository, error) {
|
||||||
rootPath, err := folders.FindDirWithLeaf(b.Config.Path, ".git")
|
rootPath, err := folders.FindDirWithLeaf(b.Config.Path, ".git")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -74,9 +74,6 @@ type Root struct {
|
||||||
// If not specified, the code below initializes this field with a
|
// If not specified, the code below initializes this field with a
|
||||||
// single default-initialized environment called "default".
|
// single default-initialized environment called "default".
|
||||||
Environments map[string]*Environment `json:"environments,omitempty"`
|
Environments map[string]*Environment `json:"environments,omitempty"`
|
||||||
|
|
||||||
// Sync section specifies options for files syncronisation
|
|
||||||
Sync Sync `json:"sync,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(path string) (*Root, error) {
|
func Load(path string) (*Root, error) {
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
type Sync struct {
|
|
||||||
Include []string `json:"include,omitempty"`
|
|
||||||
Exclude []string `json:"exclude,omitempty"`
|
|
||||||
}
|
|
|
@ -14,21 +14,13 @@ func getSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) {
|
||||||
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDir, err := b.InternalDir()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot get bundle internal directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := sync.SyncOptions{
|
opts := sync.SyncOptions{
|
||||||
LocalPath: b.Config.Path,
|
LocalPath: b.Config.Path,
|
||||||
RemotePath: b.Config.Workspace.FilesPath,
|
RemotePath: b.Config.Workspace.FilesPath,
|
||||||
Include: b.Config.Sync.Include,
|
|
||||||
Exclude: b.Config.Sync.Exclude,
|
|
||||||
|
|
||||||
Full: false,
|
Full: false,
|
||||||
CurrentUser: b.Config.Workspace.CurrentUser.User,
|
CurrentUser: b.Config.Workspace.CurrentUser.User,
|
||||||
|
|
||||||
InternalDir: internalDir,
|
|
||||||
SnapshotBasePath: cacheDir,
|
SnapshotBasePath: cacheDir,
|
||||||
WorkspaceClient: b.WorkspaceClient(),
|
WorkspaceClient: b.WorkspaceClient(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (m *transform) Apply(ctx context.Context, b *bundle.Bundle) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDir, err := b.InternalDir()
|
internalDir, err := getInternalDir(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -85,11 +85,21 @@ func (m *transform) Apply(ctx context.Context, b *bundle.Bundle) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateNotebookWrapper(b *bundle.Bundle, task *jobs.PythonWheelTask, libraries []compute.Library) (string, error) {
|
func getInternalDir(b *bundle.Bundle) (string, error) {
|
||||||
internalDir, err := b.InternalDir()
|
cacheDir, err := b.CacheDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
internalDir := filepath.Join(cacheDir, ".internal")
|
||||||
|
return internalDir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateNotebookWrapper(b *bundle.Bundle, task *jobs.PythonWheelTask, libraries []compute.Library) (string, error) {
|
||||||
|
internalDir, err := getInternalDir(b)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
notebookName := fmt.Sprintf("notebook_%s_%s", task.PackageName, task.EntryPoint)
|
notebookName := fmt.Sprintf("notebook_%s_%s", task.PackageName, task.EntryPoint)
|
||||||
path := filepath.Join(internalDir, notebookName+".py")
|
path := filepath.Join(internalDir, notebookName+".py")
|
||||||
|
|
||||||
|
|
|
@ -23,20 +23,12 @@ func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, b *bundle.Bundle)
|
||||||
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDir, err := b.InternalDir()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot get bundle internal directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := sync.SyncOptions{
|
opts := sync.SyncOptions{
|
||||||
LocalPath: b.Config.Path,
|
LocalPath: b.Config.Path,
|
||||||
RemotePath: b.Config.Workspace.FilesPath,
|
RemotePath: b.Config.Workspace.FilesPath,
|
||||||
Include: b.Config.Sync.Include,
|
|
||||||
Exclude: b.Config.Sync.Exclude,
|
|
||||||
Full: f.full,
|
Full: f.full,
|
||||||
PollInterval: f.interval,
|
PollInterval: f.interval,
|
||||||
|
|
||||||
InternalDir: internalDir,
|
|
||||||
SnapshotBasePath: cacheDir,
|
SnapshotBasePath: cacheDir,
|
||||||
WorkspaceClient: b.WorkspaceClient(),
|
WorkspaceClient: b.WorkspaceClient(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,21 +35,13 @@ func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, args []string, b *
|
||||||
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
internalDir, err := b.InternalDir()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot get bundle internal directory: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := sync.SyncOptions{
|
opts := sync.SyncOptions{
|
||||||
LocalPath: b.Config.Path,
|
LocalPath: b.Config.Path,
|
||||||
RemotePath: b.Config.Workspace.FilesPath,
|
RemotePath: b.Config.Workspace.FilesPath,
|
||||||
Include: b.Config.Sync.Include,
|
|
||||||
Exclude: b.Config.Sync.Exclude,
|
|
||||||
|
|
||||||
Full: f.full,
|
Full: f.full,
|
||||||
PollInterval: f.interval,
|
PollInterval: f.interval,
|
||||||
|
|
||||||
InternalDir: internalDir,
|
|
||||||
SnapshotBasePath: cacheDir,
|
SnapshotBasePath: cacheDir,
|
||||||
WorkspaceClient: b.WorkspaceClient(),
|
WorkspaceClient: b.WorkspaceClient(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,27 +3,21 @@ package sync
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/filer"
|
"github.com/databricks/cli/libs/filer"
|
||||||
"github.com/databricks/cli/libs/fileset"
|
|
||||||
"github.com/databricks/cli/libs/git"
|
"github.com/databricks/cli/libs/git"
|
||||||
"github.com/databricks/cli/libs/log"
|
"github.com/databricks/cli/libs/log"
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
"github.com/databricks/databricks-sdk-go/service/iam"
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncOptions struct {
|
type SyncOptions struct {
|
||||||
LocalPath string
|
LocalPath string
|
||||||
RemotePath string
|
RemotePath string
|
||||||
Include []string
|
|
||||||
Exclude []string
|
|
||||||
|
|
||||||
Full bool
|
Full bool
|
||||||
|
|
||||||
InternalDir string
|
|
||||||
SnapshotBasePath string
|
SnapshotBasePath string
|
||||||
|
|
||||||
PollInterval time.Duration
|
PollInterval time.Duration
|
||||||
|
@ -39,8 +33,6 @@ type Sync struct {
|
||||||
*SyncOptions
|
*SyncOptions
|
||||||
|
|
||||||
fileSet *git.FileSet
|
fileSet *git.FileSet
|
||||||
includeFileSet *fileset.GlobSet
|
|
||||||
excludeFileSet *fileset.GlobSet
|
|
||||||
|
|
||||||
snapshot *Snapshot
|
snapshot *Snapshot
|
||||||
filer filer.Filer
|
filer filer.Filer
|
||||||
|
@ -61,17 +53,6 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
includes := []string{}
|
|
||||||
if opts.InternalDir != "" {
|
|
||||||
includes = append(includes, filepath.Join(opts.InternalDir, "*.*"))
|
|
||||||
}
|
|
||||||
if opts.Include != nil {
|
|
||||||
includes = append(includes, opts.Include...)
|
|
||||||
}
|
|
||||||
|
|
||||||
includeFileSet := fileset.NewGlobSet(opts.LocalPath, includes)
|
|
||||||
excludeFileSet := fileset.NewGlobSet(opts.LocalPath, opts.Exclude)
|
|
||||||
|
|
||||||
// Verify that the remote path we're about to synchronize to is valid and allowed.
|
// Verify that the remote path we're about to synchronize to is valid and allowed.
|
||||||
err = EnsureRemotePathIsUsable(ctx, opts.WorkspaceClient, opts.RemotePath, opts.CurrentUser)
|
err = EnsureRemotePathIsUsable(ctx, opts.WorkspaceClient, opts.RemotePath, opts.CurrentUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,8 +90,6 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
|
||||||
SyncOptions: &opts,
|
SyncOptions: &opts,
|
||||||
|
|
||||||
fileSet: fileSet,
|
fileSet: fileSet,
|
||||||
includeFileSet: includeFileSet,
|
|
||||||
excludeFileSet: excludeFileSet,
|
|
||||||
snapshot: snapshot,
|
snapshot: snapshot,
|
||||||
filer: filer,
|
filer: filer,
|
||||||
notifier: &NopNotifier{},
|
notifier: &NopNotifier{},
|
||||||
|
@ -154,44 +133,15 @@ func (s *Sync) notifyComplete(ctx context.Context, d diff) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) RunOnce(ctx context.Context) error {
|
func (s *Sync) RunOnce(ctx context.Context) error {
|
||||||
all := make([]fileset.File, 0)
|
|
||||||
if s.SyncOptions.Include == nil {
|
|
||||||
// tradeoff: doing portable monitoring only due to macOS max descriptor manual ulimit setting requirement
|
// tradeoff: doing portable monitoring only due to macOS max descriptor manual ulimit setting requirement
|
||||||
// https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py#L394-L418
|
// https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py#L394-L418
|
||||||
gitFiles, err := s.fileSet.All()
|
all, err := s.fileSet.All()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(ctx, "cannot list files: %s", err)
|
log.Errorf(ctx, "cannot list files: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
all = append(all, gitFiles...)
|
|
||||||
}
|
|
||||||
|
|
||||||
include, err := s.includeFileSet.All()
|
change, err := s.snapshot.diff(ctx, all)
|
||||||
if err != nil {
|
|
||||||
log.Errorf(ctx, "cannot list include files: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
all = append(all, include...)
|
|
||||||
|
|
||||||
exclude, err := s.excludeFileSet.All()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf(ctx, "cannot list exclude files: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
files := make([]fileset.File, 0)
|
|
||||||
for _, f := range all {
|
|
||||||
if slices.ContainsFunc(exclude, func(a fileset.File) bool {
|
|
||||||
return a.Absolute == f.Absolute
|
|
||||||
}) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
files = append(files, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
change, err := s.snapshot.diff(ctx, files)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue