From c7af8eabb3334063c9cede2916b14f23920082d7 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 17 Mar 2022 15:30:21 +1300 Subject: [PATCH] Default to running tests with Python 3 Specify PY2=1 to use Python 2. See #1779 Closes #2235 --- .github/workflows/ci.yml | 21 +++++-------------- CHANGES.current | 7 +++++++ Examples/Makefile.in | 6 +++--- .../import_packages/from_init1/Makefile | 2 +- .../import_packages/from_init2/Makefile | 2 +- .../import_packages/from_init3/Makefile | 2 +- .../import_packages/relativeimport1/Makefile | 2 +- .../import_packages/relativeimport2/Makefile | 2 +- .../import_packages/relativeimport3/Makefile | 2 +- Examples/python/index.html | 2 +- Examples/test-suite/python/Makefile.in | 2 +- Examples/test-suite/python/README | 5 +++-- Tools/CI-linux-install.sh | 12 ++++++++--- appveyor.yml | 8 +++---- 14 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fd4fbe9d..88fd32328 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: # By default, the name of the build is the language used and SWIG options, but matrix entries # can define the additional "desc" field with any additional information to include in the name. - name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ (matrix.compiler || 'gcc') }}${{ matrix.GCC }} ${{ matrix.CPPSTD }} ${{ matrix.CSTD }} ${{ matrix.desc }} ${{ matrix.continue-on-error && '(can fail)' }} + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY2 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ (matrix.compiler || 'gcc') }}${{ matrix.GCC }} ${{ matrix.CPPSTD }} ${{ matrix.CSTD }} ${{ matrix.desc }} ${{ matrix.continue-on-error && '(can fail)' }} strategy: matrix: @@ -113,45 +113,37 @@ jobs: - SWIGLANG: php VER: '8.1' - SWIGLANG: python + PY2: 2 - SWIGLANG: python - PY3: 3 VER: '3.2' os: ubuntu-18.04 # Python < 3.5 not available for 20.04. - SWIGLANG: python - PY3: 3 VER: '3.3' os: ubuntu-18.04 # Python < 3.5 not available for 20.04. - SWIGLANG: python - PY3: 3 VER: '3.4' os: ubuntu-18.04 # Python < 3.5 not available for 20.04. - SWIGLANG: python - PY3: 3 VER: '3.5' - SWIGLANG: python - PY3: 3 VER: '3.6' - SWIGLANG: python - PY3: 3 VER: '3.7' - SWIGLANG: python - PY3: 3 VER: '3.8' - SWIGLANG: python - PY3: 3 VER: '3.9' - SWIGLANG: python - PY3: 3 VER: '3.10' - SWIGLANG: python + PY2: 2 SWIG_FEATURES: -builtin - SWIGLANG: python + PY2: 2 SWIG_FEATURES: -builtin -O - SWIGLANG: python - PY3: 3 SWIG_FEATURES: -builtin - SWIGLANG: python - PY3: 3 SWIG_FEATURES: -builtin -O - SWIGLANG: r - SWIGLANG: ruby @@ -210,7 +202,6 @@ jobs: CSTD: gnu11 - SWIGLANG: python CPPSTD: c++11 - PY3: 3 - SWIGLANG: r CPPSTD: c++11 - SWIGLANG: ruby @@ -245,7 +236,6 @@ jobs: CSTD: gnu11 - SWIGLANG: python CPPSTD: c++14 - PY3: 3 - SWIGLANG: r CPPSTD: c++14 - SWIGLANG: ruby @@ -290,7 +280,6 @@ jobs: - SWIGLANG: python CPPSTD: c++17 GCC: 11 - PY3: 3 - SWIGLANG: r CPPSTD: c++17 GCC: 11 @@ -314,7 +303,7 @@ jobs: env: SWIGLANG: ${{ matrix.SWIGLANG }} - PY3: ${{ matrix.PY3 }} + PY2: ${{ matrix.PY2 }} VER: ${{ matrix.VER }} ENGINE: ${{ matrix.ENGINE }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} diff --git a/CHANGES.current b/CHANGES.current index f48d1f5ec..64f4204da 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-03-17: olly + [Python] #1779 SWIG's Python test-suite and examples are now + run with Python 3 by default. To run them with Python 2, set + PY2 to a non-empty value, e.g.: + + make check-python-test-suite PY2=1 + 2022-03-16: olly [Go] #683 -intgosize is now optional - if not specified the generated C/C++ wrapper code will use ptrdiff_t for intgo and diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 5a1fa7188..5f56f71dc 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -309,7 +309,7 @@ perl5_clean: PYTHON_FLAGS = # Make sure these locate your Python installation -ifeq (,$(PY3)) +ifneq (,$(PY2)) PYTHON_INCLUDE= $(DEFS) @PYINCLUDE@ PYTHON_LIB = @PYLIB@ PYTHON = @PYTHON@ $(PYTHON_FLAGS) @@ -320,7 +320,7 @@ else endif # Extra Python specific linking options -ifeq (,$(PY3)) +ifneq (,$(PY2)) PYTHON_DLNK = @PYTHONDYNAMICLINKING@ PYTHON_LINK = @PYLINK@ else @@ -330,7 +330,7 @@ endif PYTHON_SO = @PYTHON_SO@ # SWIG option for Python3 -ifeq (,$(PY3)) +ifneq (,$(PY2)) SWIGOPTPY3 = else SWIGOPTPY3 = -py3 diff --git a/Examples/python/import_packages/from_init1/Makefile b/Examples/python/import_packages/from_init1/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/from_init1/Makefile +++ b/Examples/python/import_packages/from_init1/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/import_packages/from_init2/Makefile b/Examples/python/import_packages/from_init2/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/from_init2/Makefile +++ b/Examples/python/import_packages/from_init2/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/import_packages/from_init3/Makefile b/Examples/python/import_packages/from_init3/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/from_init3/Makefile +++ b/Examples/python/import_packages/from_init3/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/import_packages/relativeimport1/Makefile b/Examples/python/import_packages/relativeimport1/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/relativeimport1/Makefile +++ b/Examples/python/import_packages/relativeimport1/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/import_packages/relativeimport2/Makefile b/Examples/python/import_packages/relativeimport2/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/relativeimport2/Makefile +++ b/Examples/python/import_packages/relativeimport2/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/import_packages/relativeimport3/Makefile b/Examples/python/import_packages/relativeimport3/Makefile index 90c92ab1c..f08c3344b 100644 --- a/Examples/python/import_packages/relativeimport3/Makefile +++ b/Examples/python/import_packages/relativeimport3/Makefile @@ -1,7 +1,7 @@ TOP = ../../.. LIBS = -ifeq (,$(PY3)) +ifneq (,$(PY2)) PKG1DIR = "py2" else PKG1DIR = "py3" diff --git a/Examples/python/index.html b/Examples/python/index.html index 750c0f04a..17d45fb7b 100644 --- a/Examples/python/index.html +++ b/Examples/python/index.html @@ -88,7 +88,7 @@ to look at the distutils

Compatibility

-For Python 3, set the environment variable PY3=1. +For Python 2, set the environment variable PY2=1.

Your mileage may vary. If you experience a problem, please let us know by diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 80116be13..cc6adeb69 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -2,7 +2,7 @@ # Makefile for python test-suite ####################################################################### -ifeq (,$(PY3)) +ifneq (,$(PY2)) PYBIN = @PYTHON@ else PYBIN = @PYTHON3@ diff --git a/Examples/test-suite/python/README b/Examples/test-suite/python/README index 84992ed05..402724c23 100644 --- a/Examples/test-suite/python/README +++ b/Examples/test-suite/python/README @@ -4,5 +4,6 @@ Any testcases which have _runme.py appended after the testcase name will be dete The _runme.py files needs to work for both Python 2.x and 3.x. -You can run make with PY3=y to run test case with Python 3.x, eg. - $ make voidtest.cpptest PY3=y +By default testcases are run with Python 3. You can run make with PY2=1 to run test case with Python 2, eg. + + $ make voidtest.cpptest PY2=1 diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 4dad7ba29..b88df193c 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -98,14 +98,20 @@ case "$SWIGLANG" in ;; "python") pip install --user pycodestyle + if [[ "$PY2" ]]; then + WITHLANG=$SWIGLANG + else + WITHLANG=${SWIGLANG}3 + fi if [[ "$VER" ]]; then $RETRY sudo add-apt-repository -y ppa:deadsnakes/ppa $RETRY sudo apt-get -qq update $RETRY sudo apt-get -qq install python${VER}-dev - WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER + WITHLANG=$WITHLANG=$SWIGLANG$VER + elif [[ "$PY2" ]]; then + $RETRY sudo apt-get install -qq python-dev else - $RETRY sudo apt-get install -qq python${PY3}-dev - WITHLANG=$SWIGLANG$PY3 + $RETRY sudo apt-get install -qq python3-dev fi ;; "r") diff --git a/appveyor.yml b/appveyor.yml index 52ad130cb..c6485cc65 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,18 +23,18 @@ environment: - SWIGLANG: python VSVER: 14 VER: 27 + PY2: 2 - SWIGLANG: python VSVER: 15 VER: 38 - PY3: 3 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - SWIGLANG: python VSVER: 16 VER: 39 - PY3: 3 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - SWIGLANG: python OSVARIANT: cygwin + PY2: 2 - SWIGLANG: java OSVARIANT: mingw APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 @@ -42,7 +42,6 @@ environment: OSVARIANT: mingw WITHLANG: python VER: 37 - PY3: 3 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - BUILDSYSTEM: cmake VSVER: 14 @@ -51,6 +50,7 @@ matrix: allow_failures: - SWIGLANG: python OSVARIANT: cygwin + PY2: 2 # Skip stale commits (pull requests only), see https://github.com/appveyor/ci/issues/38#issuecomment-70628826 init: @@ -154,7 +154,7 @@ build_script: - if "%OSVARIANT%"=="" bash -c "exec 0