MCPcopy Index your code
hub / github.com/go-python/gopy / parsePackage

Function parsePackage

gen.go:132–160  ·  view source on GitHub ↗
(bpkg *packages.Package)

Source from the content-addressed store, hash-verified

130}
131
132func parsePackage(bpkg *packages.Package) (*bind.Package, error) {
133 if len(bpkg.GoFiles) == 0 {
134 err := fmt.Errorf("gopy: no files in package %q", bpkg.PkgPath)
135 fmt.Println(err)
136 return nil, err
137 }
138 dir, _ := filepath.Split(bpkg.GoFiles[0])
139 p := bpkg.Types
140
141 if bpkg.Name == "main" {
142 err := fmt.Errorf("gopy: skipping 'main' package %q", bpkg.PkgPath)
143 fmt.Println(err)
144 return nil, err
145 }
146
147 fset := token.NewFileSet()
148 var pkgast *ast.Package
149 pkgs, err := parser.ParseDir(fset, dir, nil, parser.ParseComments)
150 if err != nil {
151 return nil, err
152 }
153 pkgast = pkgs[p.Name()]
154 if pkgast == nil {
155 return nil, fmt.Errorf("gopy: could not find AST for package %q", p.Name())
156 }
157
158 pkgdoc := doc.New(pkgast, bpkg.PkgPath, 0)
159 return bind.NewPackage(p, pkgdoc)
160}

Callers 3

buildPkgRecurseFunction · 0.85
gopyRunCmdGenFunction · 0.85
gopyRunCmdBuildFunction · 0.85

Calls 3

NewPackageFunction · 0.92
PrintlnMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected