Merge pull request #322 from go-python/py2

all: drop python2 support
This commit is contained in:
Randall O'Reilly 2023-03-31 12:31:27 -07:00 committed by GitHub
commit 042b2543e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 85 deletions

View File

@ -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 }}
@ -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

View File

@ -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

View File

@ -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

View File

@ -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"),

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/go-python/gopy
go 1.18
go 1.19
require (
github.com/gonuts/commander v0.1.0

View File

@ -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],
@ -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}
@ -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()
@ -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",

View File

@ -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 != "" {

View File

@ -40,7 +40,6 @@ func init() {
mandatory bool
}{
{"py3", py3, "", true},
// {"py2", py2, "", true},
} {
args := []string{"-c", ""}
if be.module != "" {