From 1bff19e98e862689ae944226f20fd5bebae60fcb Mon Sep 17 00:00:00 2001 From: b-long Date: Sun, 25 Jan 2026 13:42:52 -0500 Subject: [PATCH 1/9] Update GitHub Actions and skip failing CGO tests Changes: - Remove appveyor.yml - Upgrade actions/checkout from v2 to v4 - Upgrade actions/setup-go from v2 to v5 with built-in caching - Add actions/setup-python@v5 pinned to Python 3.11 - Remove separate actions/cache step (now handled by setup-go) - Upgrade codecov/codecov-action from v1 to v4 - Skip TestBindSimple and TestBindCgoPackage (Go 1.21+ CGO issue) Python 3.11 pinning avoids issues with Python 3.12 changes while we focus on infrastructure improvements. The two skipped tests fail due to known Go 1.21+ CGO limitations when multiple C-shared libraries are loaded in the same process (see go-python/gopy#370). These changes provide a clean, passing CI baseline for future PRs. Similar to upstream PR go-python/gopy#378 from @coffeemakingtoaster. Co-authored-by: @coffeemakingtoaster --- .github/workflows/ci.yml | 29 +++++++++++------------------ appveyor.yml | 37 ------------------------------------- main_test.go | 2 ++ 3 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 appveyor.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29987c4f..612d937c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,26 +26,19 @@ jobs: #platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - - - name: Cache-Go - uses: actions/cache@v1 - with: - path: | - ~/go/pkg/mod # Module download cache - ~/.cache/go-build # Build cache (Linux) - ~/Library/Caches/go-build # Build cache (Mac) - '%LocalAppData%\go-build' # Build cache (Windows) - - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - - - name: Checkout code - uses: actions/checkout@v2 + cache: true - name: Install Linux packages if: matrix.platform == 'ubuntu-latest' @@ -68,4 +61,4 @@ jobs: make test - name: Upload-Coverage if: matrix.platform == 'ubuntu-latest' - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 98b9cd9f..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,37 +0,0 @@ -image: Previous Visual Studio 2019 - -build: off - -clone_folder: c:\gopath\src\github.com\go-python\gopy - -cache: - - '%LocalAppData%\\go-build' - - '%LocalAppData%\\pip' - -branches: - only: - - master - -environment: - GOPATH: C:\gopath - GOROOT: C:\go121 - GOPY_APPVEYOR_CI: '1' - GOTRACEBACK: 'crash' - CPYTHON3DIR: "C:\\Python311-x64" - PATH: '%GOPATH%\bin;%GOROOT%\bin;%CPYTHON3DIR%;%CPYTHON3DIR%\\Scripts;C:\msys64\mingw64\bin;C:\msys64\usr\bin\;%PATH%' - -stack: go 1.21 - -build_script: - - python --version - - "%CPYTHON3DIR%\\python --version" - - "%CPYTHON3DIR%\\python -m pip install --upgrade pip" - - "%CPYTHON3DIR%\\python -m pip install cffi" - - "%CPYTHON3DIR%\\python -m pip install pybindgen" - - go version - - go env - - go get -v -t ./... - - go install golang.org/x/tools/cmd/goimports@latest - -test_script: - - go test ./... diff --git a/main_test.go b/main_test.go index e7d4292c..c5f6c29e 100644 --- a/main_test.go +++ b/main_test.go @@ -316,6 +316,7 @@ OK } func TestBindSimple(t *testing.T) { + t.Skip("Skipping due to Go 1.21+ CGO issue (see https://github.com/go-python/gopy/issues/370)") // t.Parallel() path := "_examples/simple" testPkg(t, pkg{ @@ -545,6 +546,7 @@ OK } func TestBindCgoPackage(t *testing.T) { + t.Skip("Skipping due to Go 1.21+ CGO issue (see https://github.com/go-python/gopy/issues/370)") // t.Parallel() path := "_examples/cgo" testPkg(t, pkg{ From 3283211fbc2538361ec4af761aa93fc65887d539 Mon Sep 17 00:00:00 2001 From: b-long Date: Sun, 25 Jan 2026 14:17:15 -0500 Subject: [PATCH 2/9] Enable CI for stacked PRs targeting any branch Updates pull_request trigger to run on PRs targeting any branch (branches: ['**']) instead of only master branch. This enables GitHub Actions CI to run on stacked PRs that target feature branches rather than master. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 612d937c..f0b81a68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: push: branches: [ master ] pull_request: - branches: [ master ] + branches: [ '**' ] env: TAGS: "-tags=ci" From f56fbb0add8e21eecee2b174bfc5584994ca3811 Mon Sep 17 00:00:00 2001 From: b-long Date: Sun, 25 Jan 2026 14:17:46 -0500 Subject: [PATCH 3/9] Add Go 1.24.x to CI test matrix Adds Go 1.24.x to the CI test matrix alongside existing 1.22.x and 1.21.x. This ensures gopy works with the latest Go version. Based on go-python/gopy#378 by @coffeemakingtoaster. Note: Two tests remain skipped due to known Go 1.21+ CGO issues (see go-python/gopy#370). This is expected. Co-Authored-By: Max --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0b81a68..3410832a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: name: Build strategy: matrix: - go-version: [1.22.x, 1.21.x] + go-version: [1.24.x, 1.22.x, 1.21.x] platform: [ubuntu-latest] #platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} From ea13169b2be7e61b129e49292db9b6f7d44cd660 Mon Sep 17 00:00:00 2001 From: b-long Date: Sun, 25 Jan 2026 14:09:00 -0500 Subject: [PATCH 4/9] Add C23 compatibility for bool typedef Wraps 'typedef uint8_t bool;' with preprocessor guards to avoid conflicts with C23's native bool type. This fixes compilation errors with newer C compilers that default to C23 standard. Based on go-python/gopy#379 by @deuill. Co-Authored-By: Marid de Uill --- bind/gen.go | 6 ++++-- cmd_build.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bind/gen.go b/bind/gen.go index 05fd70e9..3685bbab 100644 --- a/bind/gen.go +++ b/bind/gen.go @@ -52,7 +52,9 @@ package main %[3]s // #define Py_LIMITED_API // need full API for PyRun* #include +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L) typedef uint8_t bool; +#endif // static inline is trick for avoiding need for extra .c file // the following are used for build value -- switch on reflect.Kind // or the types equivalent @@ -409,8 +411,8 @@ build: # goimports is needed to ensure that the imports list is valid $(GOIMPORTS) -w %[1]s.go # this will otherwise be built during go build and may be out of date - - rm %[1]s.c - echo "typedef uint8_t bool;" > %[1]s_go.h + - rm %[1]s.c + printf "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n" > %[1]s_go.h # this will fail but is needed to generate the .c file that then allows go build to work - $(PYTHON) build.py >/dev/null 2>&1 # generate %[1]s_go.h from %[1]s.go -- unfortunately no way to build .h only diff --git a/cmd_build.go b/cmd_build.go index 6c63dff7..24b0191c 100644 --- a/cmd_build.go +++ b/cmd_build.go @@ -125,7 +125,7 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error { if mode == bind.ModeExe { of, err := os.Create(buildname + ".h") // overwrite existing - fmt.Fprintf(of, "typedef uint8_t bool;\n") + fmt.Fprintf(of, "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n") of.Close() fmt.Printf("%v build.py # will fail, but needed to generate .c file\n", cfg.VM) From 81ec50f00c93850fea3d79ea54c803fd1dac99ff Mon Sep 17 00:00:00 2001 From: b-long Date: Sun, 25 Jan 2026 14:31:30 -0500 Subject: [PATCH 5/9] Add Go 1.25.x to CI test matrix and update dependencies Adds Go 1.25.x to the CI test matrix alongside existing versions (1.25.x, 1.24.x, 1.22.x, 1.21.x). This ensures gopy works with the latest Go version. Updates golang.org/x/tools from v0.16.0 to v0.29.0 to support Go 1.25.x, which has breaking changes that make older versions of x/tools incompatible. Note: Two tests remain skipped due to known Go 1.21+ CGO issues (see go-python/gopy#370). This is expected. --- .github/workflows/ci.yml | 2 +- go.mod | 9 ++++++--- go.sum | 16 ++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3410832a..546c1d78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: name: Build strategy: matrix: - go-version: [1.24.x, 1.22.x, 1.21.x] + go-version: [1.25.x, 1.24.x, 1.22.x, 1.21.x] platform: [ubuntu-latest] #platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} diff --git a/go.mod b/go.mod index 673ca252..b591801e 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,15 @@ module github.com/go-python/gopy -go 1.19 +go 1.22.0 require ( github.com/gonuts/commander v0.1.0 github.com/gonuts/flag v0.1.0 github.com/pkg/errors v0.9.1 - golang.org/x/tools v0.16.0 + golang.org/x/tools v0.29.0 ) -require golang.org/x/mod v0.14.0 // indirect +require ( + golang.org/x/mod v0.22.0 // indirect + golang.org/x/sync v0.10.0 // indirect +) diff --git a/go.sum b/go.sum index fe0b52ca..4b74f8cf 100644 --- a/go.sum +++ b/go.sum @@ -2,13 +2,13 @@ github.com/gonuts/commander v0.1.0 h1:EcDTiVw9oAVORFjQOEOuHQqcl6OXMyTgELocTq6zJ0 github.com/gonuts/commander v0.1.0/go.mod h1:qkb5mSlcWodYgo7vs8ulLnXhfinhZsZcm6+H/z1JjgY= github.com/gonuts/flag v0.1.0 h1:fqMv/MZ+oNGu0i9gp0/IQ/ZaPIDoAZBOBaJoV7viCWM= github.com/gonuts/flag v0.1.0/go.mod h1:ZTmTGtrSPejTo/SRNhCqwLTmiAgyBdCkLYhHrAoBdz4= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= From d2157360556d6daabd10e749ceadd83bd8e6b8e7 Mon Sep 17 00:00:00 2001 From: b-long Date: Mon, 26 Jan 2026 21:02:09 -0500 Subject: [PATCH 6/9] Fix Windows CI error by enforcing LF line endings Add .gitattributes to ensure consistent line endings across all platforms. This fixes the TestCheckSupportMatrix failure on Windows, which was caused by Git converting LF to CRLF on Windows, breaking the byte-level comparison between the generated and committed SUPPORT_MATRIX.md file. The test passes on Linux because line endings remain as LF, but fails on Windows where Git may convert them to CRLF during checkout. By explicitly setting eol=lf for text files, we ensure consistent behavior across all platforms. --- .gitattributes | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..76acfc00 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +# Ensure all text files use LF line endings in the repository +* text=auto + +# Explicitly set LF for specific files that are checked in tests +*.go text eol=lf +*.md text eol=lf +*.sh text eol=lf +*.py text eol=lf +*.yml text eol=lf +*.yaml text eol=lf +*.json text eol=lf +*.txt text eol=lf + +# Binary files +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.so binary +*.pyd binary +*.dll binary +*.exe binary +*.pyc binary From 9234e3281c3fc80661c2987781cdf7a4c58f856e Mon Sep 17 00:00:00 2001 From: b-long Date: Mon, 26 Jan 2026 20:30:12 -0500 Subject: [PATCH 7/9] Update CI configuration to include Windows --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++---- _examples/cstrings/test.py | 26 ++++++++++++++++++++------ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 546c1d78..d90e7982 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,19 @@ jobs: build: name: Build strategy: + fail-fast: false matrix: - go-version: [1.25.x, 1.24.x, 1.22.x, 1.21.x] - platform: [ubuntu-latest] - #platform: [ubuntu-latest, macos-latest, windows-latest] + include: + - go-version: 1.25.x + platform: ubuntu-latest + - go-version: 1.24.x + platform: ubuntu-latest + - go-version: 1.22.x + platform: ubuntu-latest + - go-version: 1.21.x + platform: ubuntu-latest + - go-version: 1.25.x + platform: windows-latest runs-on: ${{ matrix.platform }} steps: - name: Checkout code @@ -50,7 +59,15 @@ jobs: # install goimports go install golang.org/x/tools/cmd/goimports@latest - + - name: Install Windows packages + if: matrix.platform == 'windows-latest' + run: | + # install pybindgen and psutil (for memory tracking in tests) + python -m pip install -U pybindgen psutil + # install goimports + go install golang.org/x/tools/cmd/goimports@latest + + - name: Build-Linux if: matrix.platform == 'ubuntu-latest' run: | @@ -59,6 +76,15 @@ jobs: if: matrix.platform == 'ubuntu-latest' run: | make test + + - name: Build-Windows + if: matrix.platform == 'windows-latest' + run: | + go build -v ./... + - name: Test Windows + if: matrix.platform == 'windows-latest' + run: | + go test -v ./... - name: Upload-Coverage if: matrix.platform == 'ubuntu-latest' uses: codecov/codecov-action@v4 diff --git a/_examples/cstrings/test.py b/_examples/cstrings/test.py index d7b8a830..74def9ce 100644 --- a/_examples/cstrings/test.py +++ b/_examples/cstrings/test.py @@ -7,7 +7,16 @@ import cstrings import gc -import resource +import sys + +# resource module is Unix-only, not available on Windows +# On Windows, use psutil for memory tracking +if sys.platform == 'win32': + import psutil + HAS_RESOURCE = False +else: + import resource + HAS_RESOURCE = True verbose = False iterations = 10000 @@ -39,7 +48,11 @@ def gofnMap(): def print_memory(s): - m = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + if HAS_RESOURCE: + m = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + else: + # psutil returns memory in bytes, convert to KB to match resource module + m = psutil.Process().memory_info().rss // 1024 if verbose: print(s, m) return m @@ -69,17 +82,18 @@ def _run_fn(fn): for fn in [gofnString, gofnStruct, gofnNestedStruct, gofnSlice, gofnMap]: alloced = size * iterations - a = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + a = print_memory("Initial memory:") pass1 = _run_fn(fn) - b = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + b = print_memory("After first pass:") pass2 = _run_fn(fn) - c = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss + c = print_memory("After second pass:") if verbose: print(fn.__name__, pass1) print(fn.__name__, pass2) print(fn.__name__, a, b, c) - print(fn.__name__, "leaked: ", (c-b) > (size * iterations)) + leaked = (c-b) > (size * iterations) + print(fn.__name__, "leaked: ", leaked) # bump up the size of each successive test to ensure that leaks # are not absorbed by previous rss growth. From 1b2f1fb56cc370e516e0e743a0f40f6f20427f4b Mon Sep 17 00:00:00 2001 From: b-long Date: Tue, 27 Jan 2026 13:03:36 -0500 Subject: [PATCH 8/9] Add instructions for running tests on Windows with psutil dependency --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6774b75a..2eec0f17 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ https://stackoverflow.com/questions/39910730/python3-is-not-recognized-as-an-int If you get a bunch of errors during linking in the build process, set `LIBDIR` or `GOPY_LIBDIR` to path to python libraries, and `LIBRARY` or `GOPY_PYLIB` to name of python library (e.g., python39 for 3.9). +#### Running Tests on Windows + +To run the test suite on Windows, you need to install `psutil` for memory tracking. This is required because Python's built-in `resource` module is [only available on Unix](https://docs.python.org/3/library/resource.html): + +```sh +python -m pip install psutil +``` + +Without `psutil`, tests that check for memory leaks will fail with `ModuleNotFoundError`. + ## Community See the [CONTRIBUTING](https://github.com/go-python/gopy/blob/master/CONTRIBUTE.md) guide for pointers on how to contribute to `gopy`. From b86e38e6b2c37b3d461d11d799f06e0657f2d711 Mon Sep 17 00:00:00 2001 From: b-long Date: Tue, 27 Jan 2026 17:20:13 -0500 Subject: [PATCH 9/9] Simplify & expand test matrix --- .github/workflows/ci.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d90e7982..e232aa0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,17 +22,9 @@ jobs: strategy: fail-fast: false matrix: - include: - - go-version: 1.25.x - platform: ubuntu-latest - - go-version: 1.24.x - platform: ubuntu-latest - - go-version: 1.22.x - platform: ubuntu-latest - - go-version: 1.21.x - platform: ubuntu-latest - - go-version: 1.25.x - platform: windows-latest + go-version: [1.25.x, 1.24.x, 1.22.x, 1.21.x] + platform: [ubuntu-latest, windows-latest] + #platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - name: Checkout code