Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
name: Build
strategy:
matrix:
go-version: [1.19.x, 1.18.x]
go-version: [1.20.x, 1.19.x]
platform: [ubuntu-latest]
#platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
Expand Down Expand Up @@ -52,26 +52,17 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install curl libffi-dev python-cffi python3-cffi python3-pip
sudo apt-get install curl libffi-dev python3-cffi python3-pip
# pypy3 isn't packaged in ubuntu yet.
TEMPDIR=$(mktemp -d)
curl -L https://downloads.python.org/pypy/pypy2.7-${PYPYVERSION}-linux64.tar.bz2 --output $TEMPDIR/pypy2.tar.bz2
curl -L https://downloads.python.org/pypy/pypy3.6-${PYPYVERSION}-linux64.tar.bz2 --output $TEMPDIR/pypy3.tar.bz2
tar xf $TEMPDIR/pypy2.tar.bz2 -C $TEMPDIR
tar xf $TEMPDIR/pypy3.tar.bz2 -C $TEMPDIR
sudo ln -s $TEMPDIR/pypy2.7-$PYPYVERSION-linux64/bin/pypy /usr/local/bin/pypy
sudo ln -s $TEMPDIR/pypy3.6-$PYPYVERSION-linux64/bin/pypy3 /usr/local/bin/pypy3
# install pip (for pypy, python2)
curl -L https://bootstrap.pypa.io/pip/2.7/get-pip.py --output ${TEMPDIR}/get-pip2.py
python2 ${TEMPDIR}/get-pip2.py
# curl -L https://bootstrap.pypa.io/get-pip.py --output ${TEMPDIR}/get-pip.py
# pypy ${TEMPDIR}/get-pip.py
# pypy3 ${TEMPDIR}/get-pip.py

# install pybindgen
python2 -m pip install --user -U pybindgen
python3 -m pip install --user -U pybindgen
# pypy -m pip install --user -U pybindgen
# pypy3 -m pip install --user -U pybindgen

# install goimports
Expand Down
56 changes: 28 additions & 28 deletions SUPPORT_MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
NOTE: File auto-generated by TestCheckSupportMatrix in main_test.go. Please
don't modify manually.

Feature |py2 | py3
--- | --- | ---
_examples/arrays | yes | yes
_examples/cgo | yes | yes
_examples/consts | yes | yes
_examples/cstrings | yes | yes
_examples/empty | yes | yes
_examples/funcs | yes | yes
_examples/gopygc | yes | yes
_examples/gostrings | yes | yes
_examples/hi | no | yes
_examples/iface | no | yes
_examples/lot | yes | yes
_examples/maps | yes | yes
_examples/named | yes | yes
_examples/osfile | yes | yes
_examples/pkgconflict | yes | yes
_examples/pointers | yes | yes
_examples/pyerrors | yes | yes
_examples/rename | yes | yes
_examples/seqs | yes | yes
_examples/simple | yes | yes
_examples/sliceptr | yes | yes
_examples/slices | yes | yes
_examples/structs | yes | yes
_examples/unicode | no | yes
_examples/variadic | no | yes
_examples/vars | yes | yes
Feature |py3
--- | ---
_examples/arrays | yes
_examples/cgo | yes
_examples/consts | yes
_examples/cstrings | yes
_examples/empty | yes
_examples/funcs | yes
_examples/gopygc | yes
_examples/gostrings | yes
_examples/hi | yes
_examples/iface | yes
_examples/lot | yes
_examples/maps | yes
_examples/named | yes
_examples/osfile | yes
_examples/pkgconflict | yes
_examples/pointers | yes
_examples/pyerrors | yes
_examples/rename | yes
_examples/seqs | yes
_examples/simple | yes
_examples/sliceptr | yes
_examples/slices | yes
_examples/structs | yes
_examples/unicode | yes
_examples/variadic | yes
_examples/vars | yes
8 changes: 2 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ branches:

environment:
GOPATH: C:\gopath
GOROOT: C:\go115
GOROOT: C:\go119
GOPY_APPVEYOR_CI: '1'
GOTRACEBACK: 'crash'
#CPYTHON2DIR: "C:\\Python27-x64"
CPYTHON3DIR: "C:\\Python37-x64"
#PATH: '%GOPATH%\bin;%CPYTHON2DIR%;%CPYTHON2DIR%\\Scripts;%CPYTHON3DIR%;%CPYTHON3DIR%\\Scripts;C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%'
PATH: '%GOPATH%\bin;%GOROOT%\bin;%CPYTHON3DIR%;%CPYTHON3DIR%\\Scripts;C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%'

stack: go 1.15
stack: go 1.19

build_script:
- python --version
#- "%CPYTHON2DIR%\\python --version"
- "%CPYTHON3DIR%\\python --version"
#- "%CPYTHON2DIR%\\python -m pip install --upgrade pip"
- "%CPYTHON3DIR%\\python -m pip install --upgrade pip"
#- "%CPYTHON2DIR%\\python -m pip install cffi"
- "%CPYTHON3DIR%\\python -m pip install cffi"
#- "%CPYTHON2DIR%\\python -m pip install pybindgen"
- "%CPYTHON3DIR%\\python -m pip install pybindgen"
- go version
- go env
Expand Down
10 changes: 8 additions & 2 deletions bind/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ func (pc *PyConfig) AllFlags() string {
// python VM (python, python2, python3, pypy, etc...)
func GetPythonConfig(vm string) (PyConfig, error) {
code := `import sys
import distutils.sysconfig as ds
try:
import sysconfig as ds
def _get_python_inc():
return ds.get_path('include')
except ImportError:
import distutils.sysconfig as ds
_get_python_inc = ds.get_config_var
import json
import os
version=sys.version_info.major
Expand Down Expand Up @@ -133,7 +139,7 @@ else:
print(json.dumps({
"version": sys.version_info.major,
"minor": sys.version_info.minor,
"incdir": ds.get_python_inc(),
"incdir": _get_python_inc(),
"libdir": ds.get_config_var("LIBDIR"),
"libpy": ds.get_config_var("LIBRARY"),
"shlibs": ds.get_config_var("SHLIBS"),
Expand Down
15 changes: 11 additions & 4 deletions cmd_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bytes"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -215,11 +216,17 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {

if bind.WindowsOS {
fmt.Printf("Doing windows sed hack to fix declspec for PyInit\n")
cmd = exec.Command("sed", "-i", "s/ PyInit_/ __declspec(dllexport) PyInit_/g", cfg.Name+".c")
cmdout, err = cmd.CombinedOutput()
fname := cfg.Name + ".c"
raw, err := os.ReadFile(fname)
if err != nil {
fmt.Printf("cmd had error: %v output:\no%v\n", err, string(cmdout))
return err
fmt.Printf("could not read %s: %+v", fname, err)
return fmt.Errorf("could not read %s: %w", fname, err)
}
raw = bytes.ReplaceAll(raw, []byte(" PyInit_"), []byte(" __declspec(dllexport) PyInit_"))
err = os.WriteFile(fname, raw, 0644)
if err != nil {
fmt.Printf("could not apply sed hack to fix declspec for PyInit: %+v", err)
return fmt.Errorf("could not apply sed hack to fix PyInit: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/go-python/gopy

go 1.18
go 1.19

require (
github.com/gonuts/commander v0.1.0
Expand Down
63 changes: 30 additions & 33 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ import (
var (
testBackends = map[string]string{}
features = map[string][]string{
"_examples/hi": []string{"py3"}, // output is different for 2 vs. 3 -- only checking 3 output
"_examples/funcs": []string{"py2", "py3"},
"_examples/sliceptr": []string{"py2", "py3"},
"_examples/simple": []string{"py2", "py3"},
"_examples/empty": []string{"py2", "py3"},
"_examples/named": []string{"py2", "py3"},
"_examples/structs": []string{"py2", "py3"},
"_examples/consts": []string{"py2", "py3"}, // 2 doesn't report .666 decimals
"_examples/vars": []string{"py2", "py3"},
"_examples/seqs": []string{"py2", "py3"},
"_examples/cgo": []string{"py2", "py3"},
"_examples/pyerrors": []string{"py2", "py3"},
"_examples/iface": []string{"py3"}, // output order diff for 2, fails but actually works
"_examples/pointers": []string{"py2", "py3"},
"_examples/arrays": []string{"py2", "py3"},
"_examples/slices": []string{"py2", "py3"},
"_examples/maps": []string{"py2", "py3"},
"_examples/gostrings": []string{"py2", "py3"},
"_examples/rename": []string{"py2", "py3"},
"_examples/lot": []string{"py2", "py3"},
"_examples/unicode": []string{"py3"}, // doesn't work for 2
"_examples/osfile": []string{"py2", "py3"},
"_examples/gopygc": []string{"py2", "py3"},
"_examples/cstrings": []string{"py2", "py3"},
"_examples/pkgconflict": []string{"py2", "py3"},
"_examples/hi": []string{"py3"},
"_examples/funcs": []string{"py3"},
"_examples/sliceptr": []string{"py3"},
"_examples/simple": []string{"py3"},
"_examples/empty": []string{"py3"},
"_examples/named": []string{"py3"},
"_examples/structs": []string{"py3"},
"_examples/consts": []string{"py3"},
"_examples/vars": []string{"py3"},
"_examples/seqs": []string{"py3"},
"_examples/cgo": []string{"py3"},
"_examples/pyerrors": []string{"py3"},
"_examples/iface": []string{"py3"},
"_examples/pointers": []string{"py3"},
"_examples/arrays": []string{"py3"},
"_examples/slices": []string{"py3"},
"_examples/maps": []string{"py3"},
"_examples/gostrings": []string{"py3"},
"_examples/rename": []string{"py3"},
"_examples/lot": []string{"py3"},
"_examples/unicode": []string{"py3"},
"_examples/osfile": []string{"py3"},
"_examples/gopygc": []string{"py3"},
"_examples/cstrings": []string{"py3"},
"_examples/pkgconflict": []string{"py3"},
"_examples/variadic": []string{"py3"},
}

Expand Down Expand Up @@ -130,7 +130,6 @@ ignoring python incompatible function: .func github.com/go-python/gopy/_examples
func TestHi(t *testing.T) {
// t.Parallel()
path := "_examples/hi"
// NOTE: output differs for python2 -- only valid checking for 3
testPkg(t, pkg{
path: path,
lang: features[path],
Expand Down Expand Up @@ -216,7 +215,7 @@ caught: can't work for 24 hours!
--- p.Salary(24): caught: can't work for 24 hours!
--- Person.__init__
caught: argument 2 must be str, not int | err-type: <class 'TypeError'>
caught: an integer is required (got type str) | err-type: <class 'TypeError'>
caught: 'str' object cannot be interpreted as an integer | err-type: <class 'TypeError'>
*ERROR* no exception raised!
hi.Person{Name="name", Age=0}
hi.Person{Name="name", Age=42}
Expand Down Expand Up @@ -923,7 +922,6 @@ type pkg struct {
}

func testPkg(t *testing.T, table pkg) {
// backends := []string{"py2", "py3"}
backends := []string{"py3"}
// backends := table.lang // todo: enabling py2 testing requires separate "want" output
for _, be := range backends {
Expand All @@ -935,11 +933,6 @@ func testPkg(t *testing.T, table pkg) {
continue
}
switch be {
case "py2":
t.Run(be, func(t *testing.T) {
// t.Parallel()
testPkgBackend(t, vm, table)
})
case "py3":
t.Run(be, func(t *testing.T) {
// t.Parallel()
Expand Down Expand Up @@ -1062,6 +1055,10 @@ func testPkgBackend(t *testing.T, pyvm string, table pkg) {
diff, _ := cmd.CombinedOutput()
diffTxt = string(diff) + "\n"
}
t.Fatalf("[%s:%s]: error running python module:\n%s",
pyvm, table.path,
diffTxt,
)
}

t.Fatalf("[%s:%s]: error running python module:\ngot:\n%s\n\nwant:\n%s\n[%s:%s] diff:\n%s",
Expand Down
3 changes: 0 additions & 3 deletions main_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func init() {
testEnvironment = os.Environ()

var (
py2 = "python2"
py3 = "python3"
// pypy2 = "pypy"
// pypy3 = "pypy3"
)

Expand All @@ -40,7 +38,6 @@ func init() {
mandatory bool
}{
{"py3", py3, "", true},
{"py2", py2, "", true},
} {
args := []string{"-c", ""}
if be.module != "" {
Expand Down
1 change: 0 additions & 1 deletion main_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func init() {
mandatory bool
}{
{"py3", py3, "", true},
// {"py2", py2, "", true},
} {
args := []string{"-c", ""}
if be.module != "" {
Expand Down