list

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package list extracts information by parsing KCL source code and return it as list. For now, the supported information to be listed will be UpStream/DownStream dependency files. It can also be schemas, schema attributes and so on. Supporting on listing these kinds of information is in the plan.

Index

Constants

View Source
const (
	Default_KclYaml     = "kcl.yaml"
	Default_ProjectYaml = "project.yaml"
)
View Source
const KCL_MOD_PATH_ENV = "${KCL_MOD}"

Variables

This section is empty.

Functions

func FindPkgInfo

func FindPkgInfo(workDir string) (pkgroot, pkgpath string, err error)

FindPkgInfo find the pkg information(1. the pkg root 2. the pkg path of current workdir)

func ListDepFiles

func ListDepFiles(workDir string, opt *Option) (files []string, err error)

ListDepFiles return the depend files from the given path. It will scan and parse the kusion applications within the workdir, then list depend files of the applications.

func ListDownStreamFiles

func ListDownStreamFiles(workDir string, opt *DepOptions) ([]string, error)

ListDownStreamFiles returns a list of DownStream dependent packages/files from the given changed path list. A typical use is to list all the DownStream files when some files changed(added/modified/deleted) in a KCL configuration repository so that certain test cases on those files, instead of all the test cases will need to be rerun to save integration time.

Usage Caution

The implementation of this API is based on reading files in opt.Files so the time-consuming is positively related to the number of files. Do not call the API with high frequency and please ensure at least 10 seconds interval when calling.

Terminology

The word "DownStream" means the dependent direction between two files/packages. One file/package is dependent by its DownStream files/packages if there exist some directly or indirectly import statements in those files/packages that finally import f to them.

Parameters

The "workDir" must be a valid KCL program root directory, otherwise a "pkgroot: not found" error will be produced.

The param opt.Files specifies the scope of the KCL files to be analyzed. Thus only files/packages that have directly or indirectly UpStream/DownStream relations with those files will appears in the result.

The param opt.UpStreams specifies the KCL files to list DownStream files/packages on.

The API will return nil if either opt/opt.Files/opt.UpStreams is nil.

Example

For instance, a KCL program that comes with three files: main.k and base/a.k, base/b.k, and the file main.k contains an import statement that imports base/b.k to it, while the file base/b.k imports base/a.k:

demo (KCL program root)
├── base
│   ├── a.k
│   └── b.k         # import .a
└── main.k          # import base.b

To list DownStream files/packages of the file base/a.k, the function call will be:

ListDownStreamFiles("demo", &DepOptions{Files:[]string{"main.k"}, UpStreams:[]string{"base/a.k"})

Then the DownStream files/packages of the file base/a.k will be: base/b.k, base and main.k If the import statement in main.k changes to:

import base

Then its DownStream files will be: base, base/a.k and base/b.k And if the import statement in main.k changes to:

import base

And the DownStream files/packages of the file base/a.k stays the same

func ListUpStreamFiles

func ListUpStreamFiles(workDir string, opt *DepOptions) (deps []string, err error)

ListUpStreamFiles returns a list of the UpStream dependent packages/files from the given path list.

Usage Caution

The implementation of this API is based on reading files in opt.Files so the time-consuming is positively related to the number of files. Do not call the API with high frequency and please ensure at least 10 seconds interval when calling.

Terminology

The word "UpStream" means the dependent direction between two files/packages. One file/package (named f) depends on its UpStream files/packages if there exist some directly or indirectly import statements that finally import the UpStream files/packages to f.

Parameters

The "workDir" must be a valid KCL program root directory, otherwise a "pkgroot: not found" error will be produced. The param opt.Files specifies the scope of the KCL files to be analyzed and list UpStream files/packages on. The param opt.UpStreams can be set nil or empty. It will not be used.

The API will return nil if opt or opt.Files is nil.

Example

For instance a KCL program that comes with three files: main.k and base/a.k, base/b.k, and the file main.k contains an import statement that imports base/b.k to it, while the file base/b.k imports base/a.k:

demo (KCL program root)
├── base
│   ├── a.k
│   └── b.k         # import .a
└── main.k          # import base.b

Then the UpStream files/packages of the file main.k will be: base/a.k and base/b.k If the import statement in main.k changes to:

import base

To list UpStream files/packages of the file main.k, the function call will be:

ListUpStreamFiles("demo", &DepOptions{Files:[]string{"main.k"})

Then its UpStream files/packages will be: base, base/a.k and base/b.k

Types

type DepOptions

type DepOptions struct {
	// Files defines the scope to inspect the import dependency on.
	// Each value in the list should be a file or package path relative to the workdir.
	Files []string
	// UpStreams defines a list of UpStream file/package paths to ListDownStreamFiles on.
	// Each value in the list should be a file or package path relative to the workdir.
	// To list UpStream files/packages, this field will not be used and can be set nil or empty
	UpStreams []string
}

DepOptions provides the files to inspect and list dependencies on

type DepParser

type DepParser struct {
	// contains filtered or unexported fields
}

func NewDepParser

func NewDepParser(root string, opt ...Option) *DepParser

func NewDepParserWithFS

func NewDepParserWithFS(vfs fs.FS, opts ...Option) *DepParser

func (*DepParser) GetAppFiles

func (p *DepParser) GetAppFiles(pkgpath string, includeDependFiles bool) []string

func (*DepParser) GetAppPkgs

func (p *DepParser) GetAppPkgs(pkgpath string, includeDependFiles bool) []string

func (*DepParser) GetDepPkgList

func (p *DepParser) GetDepPkgList(pkgpath string) []string

func (*DepParser) GetError

func (p *DepParser) GetError() error

GetError return parser error.

func (*DepParser) GetImportMap

func (p *DepParser) GetImportMap() map[string][]string

func (*DepParser) GetImportMapString

func (p *DepParser) GetImportMapString() string

func (*DepParser) GetKList

func (p *DepParser) GetKList() []string

func (*DepParser) GetMainKList

func (p *DepParser) GetMainKList() []string

func (*DepParser) GetPkgFileList

func (p *DepParser) GetPkgFileList(pkgpath string) []string

func (*DepParser) GetPkgList

func (p *DepParser) GetPkgList() []string

func (*DepParser) GetTouchedApps

func (p *DepParser) GetTouchedApps(touchedFiles ...string) (touchedApps, untouchedApps []string)

func (*DepParser) IsApp

func (p *DepParser) IsApp(pkgpath string) bool

type Option

type Option struct {
	KclYaml     string // default: Default_KclYaml
	ProjectYaml string // default: Default_ProjectYaml
	FlagAll     bool
	UseAbsPath  bool
}

type SingleAppDepParser

type SingleAppDepParser struct {
	// contains filtered or unexported fields
}

func NewSingleAppDepParser

func NewSingleAppDepParser(root string, opt ...Option) *SingleAppDepParser

func NewSingleAppDepParserWithFS

func NewSingleAppDepParserWithFS(vfs fs.FS, opts ...Option) *SingleAppDepParser

func (*SingleAppDepParser) GetAppFiles

func (p *SingleAppDepParser) GetAppFiles(appPkgpath string, includeDependFiles bool) ([]string, error)

func (*SingleAppDepParser) GetAppPkgs

func (p *SingleAppDepParser) GetAppPkgs(appPkgpath string, includeDependFiles bool) ([]string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL