mirror of https://github.com/databricks/cli.git
Add missing files
This commit is contained in:
parent
3e5af6cb43
commit
e1710ff9e4
|
@ -69,12 +69,6 @@ type PyDABs struct {
|
|||
// These packages are imported to discover resources, resource generators, and mutators.
|
||||
// This list can include namespace packages, which causes the import of nested packages.
|
||||
Import []string `json:"import,omitempty"`
|
||||
|
||||
// LoadLocations is a flag to enable loading Python source locations from the PyDABs.
|
||||
//
|
||||
// Locations are only supported since PyDABs 0.6.0, and because of that,
|
||||
// this flag is disabled by default.
|
||||
LoadLocations bool `json:"load_locations,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
//
|
||||
// mergePythonLocations replaces dyn.Location with generatedFileName with locations loaded
|
||||
// from locations.json
|
||||
const generatedFileName = "__generated_by_pydabs__.yml"
|
||||
const generatedFileName = "__generated_by_python__.yml"
|
||||
|
||||
// pythonLocations is data structure for efficient location lookup for a given path
|
||||
//
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/databricks/cli/bundle/config/mutator/paths"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
|
@ -13,8 +14,6 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/databricks/cli/bundle/config/mutator/paths"
|
||||
|
||||
"github.com/databricks/databricks-sdk-go/logger"
|
||||
"github.com/fatih/color"
|
||||
|
||||
|
@ -127,6 +126,15 @@ type opts struct {
|
|||
enabled bool
|
||||
|
||||
venvPath string
|
||||
|
||||
loadLocations bool
|
||||
}
|
||||
|
||||
type runPythonMutatorOpts struct {
|
||||
cacheDir string
|
||||
bundleRootPath string
|
||||
pythonPath string
|
||||
loadLocations bool
|
||||
}
|
||||
|
||||
// getOpts adapts deprecated PyDABs and upcoming Python configuration
|
||||
|
@ -151,8 +159,9 @@ func getOpts(b *bundle.Bundle, phase phase) (opts, error) {
|
|||
// don't execute for phases for 'python' section
|
||||
if phase == PythonMutatorPhaseInit || phase == PythonMutatorPhaseLoad {
|
||||
return opts{
|
||||
enabled: true,
|
||||
venvPath: experimental.PyDABs.VEnvPath,
|
||||
enabled: true,
|
||||
venvPath: experimental.PyDABs.VEnvPath,
|
||||
loadLocations: false, // not supported in PyDABs
|
||||
}, nil
|
||||
} else {
|
||||
return opts{}, nil
|
||||
|
@ -161,8 +170,9 @@ func getOpts(b *bundle.Bundle, phase phase) (opts, error) {
|
|||
// don't execute for phases for 'pydabs' section
|
||||
if phase == PythonMutatorPhaseLoadResources || phase == PythonMutatorPhaseApplyMutators {
|
||||
return opts{
|
||||
enabled: true,
|
||||
venvPath: experimental.Python.VEnvPath,
|
||||
enabled: true,
|
||||
venvPath: experimental.Python.VEnvPath,
|
||||
loadLocations: true,
|
||||
}, nil
|
||||
} else {
|
||||
return opts{}, nil
|
||||
|
@ -201,7 +211,7 @@ func (m *pythonMutator) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagno
|
|||
cacheDir: cacheDir,
|
||||
bundleRootPath: b.BundleRootPath,
|
||||
pythonPath: pythonPath,
|
||||
loadLocations: experimental.PyDABs.LoadLocations,
|
||||
loadLocations: opts.loadLocations,
|
||||
})
|
||||
mutateDiags = diags
|
||||
if diags.HasError() {
|
||||
|
@ -246,13 +256,6 @@ func createCacheDir(ctx context.Context) (string, error) {
|
|||
return os.MkdirTemp("", "-python")
|
||||
}
|
||||
|
||||
type runPythonMutatorOpts struct {
|
||||
cacheDir string
|
||||
bundleRootPath string
|
||||
pythonPath string
|
||||
loadLocations bool
|
||||
}
|
||||
|
||||
func (m *pythonMutator) runPythonMutator(ctx context.Context, root dyn.Value, opts runPythonMutatorOpts) (dyn.Value, diag.Diagnostics) {
|
||||
inputPath := filepath.Join(opts.cacheDir, "input.json")
|
||||
outputPath := filepath.Join(opts.cacheDir, "output.json")
|
||||
|
|
|
@ -244,7 +244,7 @@ func TestPythonMutator_applyMutators(t *testing.T) {
|
|||
description, err := dyn.GetByPath(v, dyn.MustPathFromString("resources.jobs.job0.description"))
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedVirtualPath, err := filepath.Abs("__generated_by_python__.yml")
|
||||
expectedVirtualPath, err := filepath.Abs(generatedFileName)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedVirtualPath, description.Location().File)
|
||||
|
||||
|
@ -332,7 +332,7 @@ func TestGetOps_Python(t *testing.T) {
|
|||
}, PythonMutatorPhaseLoadResources)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, opts{venvPath: ".venv", enabled: true}, actual)
|
||||
assert.Equal(t, opts{venvPath: ".venv", enabled: true, loadLocations: true}, actual)
|
||||
}
|
||||
|
||||
func TestGetOps_PyDABs(t *testing.T) {
|
||||
|
@ -348,7 +348,7 @@ func TestGetOps_PyDABs(t *testing.T) {
|
|||
}, PythonMutatorPhaseInit)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, opts{venvPath: ".venv", enabled: true}, actual)
|
||||
assert.Equal(t, opts{venvPath: ".venv", enabled: true, loadLocations: false}, actual)
|
||||
}
|
||||
|
||||
func TestGetOps_empty(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue