Skip to content

Commit d2a750b

Browse files
authored
Merge pull request #12 from cpunion/docs
Docs
2 parents f5104e3 + e5ef464 commit d2a750b

File tree

12 files changed

+46
-27
lines changed

12 files changed

+46
-27
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636
## Examples
3737

38-
See the [examples](_demo).
38+
See the [examples](demo).
3939

4040
### Hello World: Plot a line
4141

4242
```go
43-
// _demo/plot/plot.go
43+
// demo/plot/plot.go
4444

4545
package main
4646

@@ -58,7 +58,7 @@ func main() {
5858
### Typed Python Objects
5959

6060
```go
61-
// _demo/plot2/plot2.go
61+
// demo/plot2/plot2.go
6262

6363
package main
6464

@@ -93,7 +93,7 @@ func main() {
9393
### Define Python Objects with Go
9494

9595
```go
96-
// _demo/module/foo/foo.go
96+
// demo/module/foo/foo.go
9797

9898
package foo
9999

@@ -145,15 +145,15 @@ func InitFooModule() gp.Module {
145145
Call foo module from Python and Go.
146146

147147
```go
148-
// _demo/module/module.go
148+
// demo/module/module.go
149149

150150
package main
151151

152152
import (
153153
"fmt"
154154

155155
gp "github.com/cpunion/go-python"
156-
"github.com/cpunion/go-python/_demo/module/foo"
156+
"github.com/cpunion/go-python/demo/module/foo"
157157
)
158158

159159
func main() {
@@ -214,7 +214,7 @@ point.print()
214214
### Call gradio
215215

216216
```go
217-
// _demo/gradio/gradio.go
217+
// demo/gradio/gradio.go
218218

219219
package main
220220

@@ -265,6 +265,7 @@ func main() {
265265
}
266266

267267
gp.Initialize()
268+
defer gp.Finalize()
268269
gr = gp.ImportModule("gradio")
269270
fn := gp.CreateFunc(UpdateExamples,
270271
"(country, /)\n--\n\nUpdate examples based on country")
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ for i in range(10):
2929

3030
mod := gp.ImportModule("__main__")
3131
gbl := mod.Dict()
32-
code := gp.CompileString(pythonCode, "<string>", gp.FileInput)
32+
code, err := gp.CompileString(pythonCode, "<string>", gp.FileInput)
33+
if err != nil {
34+
fmt.Printf("Failed to compile Python code: %v\n", err)
35+
return
36+
}
3337
_ = gp.EvalCode(code, gbl, gp.Nil().AsDict())
3438
for i := 0; i < 10; i++ {
3539
result := gp.EvalCode(code, gbl, gp.Nil().AsDict())
@@ -49,12 +53,9 @@ for i in range(10):
4953
runtime.GC()
5054
}
5155

52-
for i := 1; i <= 100000; i++ {
53-
println(i)
56+
for i := 1; i <= 1000000; i++ {
5457
f := gp.MakeFloat(float64(i))
55-
r := pymath.Sqrt(f)
56-
b := r.IsInteger()
57-
var _ bool = b.Bool()
58+
_ = pymath.Sqrt(f)
5859
if i%10000 == 0 {
5960
fmt.Printf("Iteration %d in go\n", i)
6061
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func main() {
4747
}
4848

4949
gp.Initialize()
50+
defer gp.Finalize()
5051
gr = gp.ImportModule("gradio")
5152
fn := gp.CreateFunc(UpdateExamples,
5253
"(country, /)\n--\n\nUpdate examples based on country")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55

66
gp "github.com/cpunion/go-python"
7-
"github.com/cpunion/go-python/_demo/module/foo"
7+
"github.com/cpunion/go-python/demo/module/foo"
88
)
99

1010
func main() {
File renamed without changes.

math/math_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package math
22

33
import (
4-
"runtime"
54
"testing"
65

76
gp "github.com/cpunion/go-python"
87
)
98

109
func TestSqrt(t *testing.T) {
11-
runtime.LockOSThread()
1210
// Initialize Python
1311
gp.Initialize()
1412
defer gp.Finalize()

object.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (obj Object) object() Object {
5252

5353
func newObject(obj *PyObject) Object {
5454
if obj == nil {
55+
C.PyErr_Print()
5556
return Object{}
5657
}
5758
o := &pyObject{obj: obj}

object_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ class TestClass:
8282
globals := MakeDict(nil)
8383
globals.Set(MakeStr("__builtins__"), builtins.Object)
8484

85-
code := CompileString(pyCode, "<string>", FileInput)
85+
code, err := CompileString(pyCode, "<string>", FileInput)
86+
if err != nil {
87+
t.Errorf("CompileString() error = %v", err)
88+
}
8689

8790
EvalCode(code, globals, locals).AsModule()
8891
testClass := locals.Get(MakeStr("TestClass")).AsFunc()
@@ -237,7 +240,10 @@ class TestClass:
237240
builtins := ImportModule("builtins")
238241
globals.Set(MakeStr("__builtins__"), builtins.Object)
239242

240-
code := CompileString(pyCode, "<string>", FileInput)
243+
code, err := CompileString(pyCode, "<string>", FileInput)
244+
if err != nil {
245+
t.Errorf("CompileString() error = %v", err)
246+
}
241247
EvalCode(code, globals, locals)
242248

243249
testClass := locals.Get(MakeStr("TestClass")).AsFunc()
@@ -278,7 +284,10 @@ def make_tuple():
278284
builtins := ImportModule("builtins")
279285
globals.Set(MakeStr("__builtins__"), builtins.Object)
280286

281-
code := CompileString(pyCode, "<string>", FileInput)
287+
code, err := CompileString(pyCode, "<string>", FileInput)
288+
if err != nil {
289+
t.Errorf("CompileString() error = %v", err)
290+
}
282291
EvalCode(code, globals, locals)
283292

284293
makeTuple := locals.Get(MakeStr("make_tuple")).AsFunc()

0 commit comments

Comments
 (0)