From 3b3e9b5a0aea87c42418a8b8b18e3af190dce53f Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Wed, 29 Mar 2023 10:55:10 +0200 Subject: [PATCH 1/5] all: remove tests for python2 Signed-off-by: Sebastien Binet --- .github/workflows/ci.yml | 11 +------- SUPPORT_MATRIX.md | 56 +++++++++++++++++++-------------------- appveyor.yml | 8 ++---- main_test.go | 57 ++++++++++++++++++---------------------- main_unix_test.go | 3 --- main_windows_test.go | 1 - 6 files changed, 56 insertions(+), 80 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f1dbd4..c24b46e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/SUPPORT_MATRIX.md b/SUPPORT_MATRIX.md index f23c8f6..9153644 100644 --- a/SUPPORT_MATRIX.md +++ b/SUPPORT_MATRIX.md @@ -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 diff --git a/appveyor.yml b/appveyor.yml index acded50..03aeeb6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ branches: environment: GOPATH: C:\gopath - GOROOT: C:\go115 + GOROOT: C:\go119 GOPY_APPVEYOR_CI: '1' GOTRACEBACK: 'crash' #CPYTHON2DIR: "C:\\Python27-x64" @@ -22,17 +22,13 @@ environment: #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 diff --git a/main_test.go b/main_test.go index 5af625e..fd684de 100644 --- a/main_test.go +++ b/main_test.go @@ -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"}, } @@ -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], @@ -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 { @@ -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() diff --git a/main_unix_test.go b/main_unix_test.go index 0d709f7..f01f8e8 100644 --- a/main_unix_test.go +++ b/main_unix_test.go @@ -19,9 +19,7 @@ func init() { testEnvironment = os.Environ() var ( - py2 = "python2" py3 = "python3" - // pypy2 = "pypy" // pypy3 = "pypy3" ) @@ -40,7 +38,6 @@ func init() { mandatory bool }{ {"py3", py3, "", true}, - {"py2", py2, "", true}, } { args := []string{"-c", ""} if be.module != "" { diff --git a/main_windows_test.go b/main_windows_test.go index 037b33a..64d4aa9 100644 --- a/main_windows_test.go +++ b/main_windows_test.go @@ -40,7 +40,6 @@ func init() { mandatory bool }{ {"py3", py3, "", true}, - // {"py2", py2, "", true}, } { args := []string{"-c", ""} if be.module != "" { From 1e88c8eb7ee47364880b89403033475e136b639e Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 31 Mar 2023 18:28:08 +0200 Subject: [PATCH 2/5] gopy: simplify test output error if diff is available Signed-off-by: Sebastien Binet --- main_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main_test.go b/main_test.go index fd684de..0dbbd3b 100644 --- a/main_test.go +++ b/main_test.go @@ -1055,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", From eddc00b4b661ca193fb072b0017c20d05ba6b19e Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 31 Mar 2023 18:28:34 +0200 Subject: [PATCH 3/5] gopy: update test for new error message Signed-off-by: Sebastien Binet --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 0dbbd3b..4f34797 100644 --- a/main_test.go +++ b/main_test.go @@ -215,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: -caught: an integer is required (got type str) | err-type: +caught: 'str' object cannot be interpreted as an integer | err-type: *ERROR* no exception raised! hi.Person{Name="name", Age=0} hi.Person{Name="name", Age=42} From b7e1c5e7f25813b7ce600977fc8dbd4793530bdd Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 31 Mar 2023 18:36:55 +0200 Subject: [PATCH 4/5] all: bump to Go-1.20 Signed-off-by: Sebastien Binet --- .github/workflows/ci.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c24b46e..5be3246 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/go.mod b/go.mod index d0e31cc..512c22f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-python/gopy -go 1.18 +go 1.19 require ( github.com/gonuts/commander v0.1.0 From 3941218a0266895a097a5e9daae97d9a4a78430d Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 31 Mar 2023 18:55:29 +0200 Subject: [PATCH 5/5] bind: add support for PEP-632 Signed-off-by: Sebastien Binet --- bind/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bind/utils.go b/bind/utils.go index 42ef5bc..02620d6 100644 --- a/bind/utils.go +++ b/bind/utils.go @@ -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 @@ -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"),