当前位置: 首页>>代码示例>>Golang>>正文


Golang SourceUnit.Dependencies方法代码示例

本文整理汇总了Golang中sourcegraph/com/sourcegraph/srclib/unit.SourceUnit.Dependencies方法的典型用法代码示例。如果您正苦于以下问题:Golang SourceUnit.Dependencies方法的具体用法?Golang SourceUnit.Dependencies怎么用?Golang SourceUnit.Dependencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sourcegraph/com/sourcegraph/srclib/unit.SourceUnit的用法示例。


在下文中一共展示了SourceUnit.Dependencies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Scan

// Scan a directory, listing all source units
func Scan(srcdir string, repoURI string, repoSubdir string) ([]*unit.SourceUnit, error) {
	if units, isSpecial := specialUnits[repoURI]; isSpecial {
		return units, nil
	}

	p, err := getVENVBinPath()
	if err != nil {
		return nil, err
	}

	cmd := exec.Command(filepath.Join(p, "python"), filepath.Join(p, "pydep-run.py"), "list", srcdir)

	cmd.Stderr = os.Stderr
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	if err := cmd.Start(); err != nil {
		return nil, err
	}

	var pkgs []*pkgInfo
	if err := json.NewDecoder(stdout).Decode(&pkgs); err != nil {
		return nil, err
	}

	if err := cmd.Wait(); err != nil {
		return nil, err
	}

	// Keep track of all files that have been successfully discovered
	discoveredScripts := make(map[string]bool)

	units := make([]*unit.SourceUnit, len(pkgs))
	for i, pkg := range pkgs {
		units[i] = pkg.SourceUnit()
		units[i].Files = pythonSourceFiles(pkg.RootDir, discoveredScripts)
		units[i].Repo = repoURI // override whatever's in the setup.py file with the actual reposit;5Dory URI

		reqs, err := requirements(pkg.RootDir)
		if err != nil {
			return nil, err
		}
		reqs_ := make([]interface{}, len(reqs))
		for i, req := range reqs {
			reqs_[i] = req
		}
		units[i].Dependencies = reqs_
	}

	// Scan for independant scripts, appending to the current set of source units
	scripts := pythonSourceFiles(srcdir, discoveredScripts)
	if len(scripts) > 0 {
		scriptsUnit := unit.SourceUnit{
			Name:  ".",
			Type:  "PythonProgram",
			Files: scripts,
			Dir:   ".",
			Ops:   map[string]*srclib.ToolRef{"depresolve": nil, "graph": nil},
		}

		reqs, err := requirements(srcdir)
		if err == nil {
			reqs_ := make([]interface{}, len(reqs))
			for i, req := range reqs {
				reqs_[i] = req
			}
			scriptsUnit.Dependencies = reqs_
		}

		units = append(units, &scriptsUnit)
	}

	return units, nil
}
开发者ID:pombredanne,项目名称:srclib-python,代码行数:76,代码来源:scan.go


注:本文中的sourcegraph/com/sourcegraph/srclib/unit.SourceUnit.Dependencies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。