Skip to content

Commit 86b4a9b

Browse files
author
Randall C. O'Reilly
committed
fix for exe mode imports -- ignores package-prefix entirely and does the right thing. Fixes issue #257
1 parent 8569a8d commit 86b4a9b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

bind/gen.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,14 @@ func (g *pyGen) genPyWrapPreamble() {
633633
impgenstr += fmt.Sprintf("import %s\n", name)
634634
}
635635
}
636+
case g.mode == ModeExe:
637+
// exe mode ignores PkgPrefix, because it is always built in to exe
638+
impgenstr += fmt.Sprintf("import _%s\n", g.cfg.Name)
639+
impgenstr += fmt.Sprintf("from %s import go\n", g.cfg.Name)
636640
default:
637-
pkg := "." + g.cfg.Name
641+
pkg := g.cfg.Name
638642
if g.cfg.PkgPrefix != "" {
639-
pkg = g.cfg.PkgPrefix + pkg
643+
pkg = g.cfg.PkgPrefix + "." + pkg
640644
}
641645
for _, name := range impgenNames {
642646
impgenstr += fmt.Sprintf("from %s import %s\n", pkg, name)

bind/symbols.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (k symkind) String() string {
7676
}
7777

7878
var pyKeywords = map[string]struct{}{
79-
"False": struct{}{}, "None": struct{}{}, "True": struct{}{}, "and": struct{}{}, "as": struct{}{}, "assert": struct{}{}, "break": struct{}{}, "class": struct{}{}, "continue": struct{}{}, "def": struct{}{}, "del": struct{}{}, "elif": struct{}{}, "else": struct{}{}, "except": struct{}{}, "finally": struct{}{}, "for": struct{}{}, "from": struct{}{}, "global": struct{}{}, "if": struct{}{}, "import": struct{}{}, "in": struct{}{}, "is": struct{}{}, "lambda": struct{}{}, "nonlocal": struct{}{}, "not": struct{}{}, "or": struct{}{}, "pass": struct{}{}, "raise": struct{}{}, "return": struct{}{}, "try": struct{}{}, "while": struct{}{}, "with": struct{}{}, "yield": struct{}{},
79+
"False": struct{}{}, "None": struct{}{}, "True": struct{}{}, "and": struct{}{}, "as": struct{}{}, "assert": struct{}{}, "break": struct{}{}, "class": struct{}{}, "continue": struct{}{}, "def": struct{}{}, "del": struct{}{}, "elif": struct{}{}, "else": struct{}{}, "except": struct{}{}, "finally": struct{}{}, "for": struct{}{}, "from": struct{}{}, "global": struct{}{}, "if": struct{}{}, "import": struct{}{}, "in": struct{}{}, "is": struct{}{}, "lambda": struct{}{}, "nonlocal": struct{}{}, "not": struct{}{}, "or": struct{}{}, "pass": struct{}{}, "raise": struct{}{}, "return": struct{}{}, "try": struct{}{}, "while": struct{}{}, "with": struct{}{}, "yield": struct{}{}, "self": struct{}{},
8080
}
8181

8282
// pySafeName returns a name that python will not barf on

cmd_exe.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ex:
4545
cmd.Flag.String("name", "", "name of output package (otherwise name of first package is used)")
4646
cmd.Flag.String("main", "", "code string to run in the go main() function in the cgo library "+
4747
"-- defaults to GoPyMainRun() but typically should be overriden")
48-
cmd.Flag.String("package-prefix", ".", "custom package prefix used when generating import "+
49-
"statements for generated package")
48+
// cmd.Flag.String("package-prefix", ".", "custom package prefix used when generating import "+
49+
// "statements for generated package")
5050
cmd.Flag.Bool("rename", false, "rename Go symbols to python PEP snake_case")
5151
cmd.Flag.Bool("symbols", true, "include symbols in output")
5252
cmd.Flag.String("exclude", "", "comma-separated list of package names to exclude")
@@ -74,7 +74,8 @@ func gopyRunCmdExe(cmdr *commander.Command, args []string) error {
7474
cfg.Name = cmdr.Flag.Lookup("name").Value.Get().(string)
7575
cfg.Main = cmdr.Flag.Lookup("main").Value.Get().(string)
7676
cfg.VM = cmdr.Flag.Lookup("vm").Value.Get().(string)
77-
cfg.PkgPrefix = cmdr.Flag.Lookup("package-prefix").Value.Get().(string)
77+
// cfg.PkgPrefix = cmdr.Flag.Lookup("package-prefix").Value.Get().(string)
78+
cfg.PkgPrefix = "" // doesn't make sense for exe
7879
cfg.RenameCase = cmdr.Flag.Lookup("rename").Value.Get().(bool)
7980
cfg.Symbols = cmdr.Flag.Lookup("symbols").Value.Get().(bool)
8081
cfg.NoWarn = cmdr.Flag.Lookup("no-warn").Value.Get().(bool)

0 commit comments

Comments
 (0)