From f5b415acabcdb96094dd211a5d9db97fbf33e990 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Mon, 14 Oct 2024 10:46:45 +0100 Subject: [PATCH 1/4] Allow tests to be run from different directory --- setup.py | 4 ++-- tests/test_abilities_list.py | 6 +++++- tests/test_camera.py | 6 +++++- tests/test_context.py | 6 +++++- tests/test_filesys.py | 6 +++++- tests/test_port.py | 6 +++++- tests/test_port_info_list.py | 6 +++++- tests/test_widget.py | 6 +++++- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index bc5edf9..0ef68fd 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2014-23 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2014-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -92,7 +92,7 @@ 'gphoto2.libgphoto2.locale.' + name + '.LC_MESSAGES') # module compile options extra_link_args = ['-Wl,-rpath,$ORIGIN/libgphoto2'] - if sys.platform =='linux': + if sys.platform == 'linux': extra_link_args += ['-Wl,--disable-new-dtags'] cmd = ['pkg-config', '--modversion', 'libgphoto2'] diff --git a/tests/test_abilities_list.py b/tests/test_abilities_list.py index 4b0ccb8..4ddd77c 100644 --- a/tests/test_abilities_list.py +++ b/tests/test_abilities_list.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,10 +19,14 @@ # . import os +import sys import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam diff --git a/tests/test_camera.py b/tests/test_camera.py index 384166e..cde6ec8 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,11 +19,15 @@ # . import os +import sys import time import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam diff --git a/tests/test_context.py b/tests/test_context.py index 073ce3f..addff76 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -20,10 +20,14 @@ from collections import defaultdict import os +import sys import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam diff --git a/tests/test_filesys.py b/tests/test_filesys.py index 0d9128a..110c85e 100644 --- a/tests/test_filesys.py +++ b/tests/test_filesys.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,11 +19,15 @@ # . import os +import sys import time import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam diff --git a/tests/test_port.py b/tests/test_port.py index 28180d2..b9df0f6 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,11 +19,15 @@ # . import logging +import os import sys import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam diff --git a/tests/test_port_info_list.py b/tests/test_port_info_list.py index 60cd199..213dd48 100644 --- a/tests/test_port_info_list.py +++ b/tests/test_port_info_list.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,10 +19,14 @@ # . import os +import sys import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import use_vcam diff --git a/tests/test_widget.py b/tests/test_widget.py index d7b251f..771568d 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -1,6 +1,6 @@ # python-gphoto2 - Python interface to libgphoto2 # http://github.com/jim-easterbrook/python-gphoto2 -# Copyright (C) 2023 Jim Easterbrook jim@jim-easterbrook.me.uk +# Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk # # This file is part of python-gphoto2. # @@ -19,11 +19,15 @@ # . import os +import sys import time import unittest import gphoto2 as gp +path = os.path.dirname(os.path.dirname(__file__)) +if path not in sys.path: + sys.path.insert(0, path) from tests.vcamera import has_vcam, use_vcam From 509218143f98f70dc719de05cecd16e94b384a27 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Mon, 14 Oct 2024 10:57:31 +0100 Subject: [PATCH 2/4] Minor tweak of locale setting in tests --- tests/test_result.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_result.py b/tests/test_result.py index a186e4e..49ed7c6 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -36,8 +36,10 @@ def test_exceptions(self): self.assertEqual(ex.string, gp.gp_result_as_string(error)) def set_lang(self, lang): - # setting LANGUAGE works on Ubuntu, setlocale works on openSUSE + # setting environ works on Ubuntu, setlocale works on openSUSE # using both seems to be harmless + os.environ['LC_ALL'] = lang + os.environ['LANG'] = lang os.environ['LANGUAGE'] = lang # try default locale first try: From 85c4bad21c03c8bfa07c5d108cb425b3de4aa2a7 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Mon, 14 Oct 2024 13:12:43 +0100 Subject: [PATCH 3/4] Move tests into wheel build stage And update everything else. --- .github/workflows/build-macos.yml | 48 ++++++---------------- .github/workflows/build-manylinux.yml | 57 ++++++--------------------- 2 files changed, 25 insertions(+), 80 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 2c447cb..649dbdd 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -1,12 +1,12 @@ -name: Build MacOS binary wheels +name: build gphoto2 macOS x86_64 on: workflow_dispatch jobs: build: - runs-on: macos-latest + runs-on: macos-13 steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download libgphoto2 run: wget -nv @@ -20,13 +20,19 @@ jobs: --directory $PWD/libgphoto2 --strip-components=1 - name: Build wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.21.3 env: CIBW_ARCHS: x86_64 CIBW_SKIP: pp3* - CIBW_ENVIRONMENT: GPHOTO2_ROOT=$PWD/libgphoto2/local_install + CIBW_ENVIRONMENT: > + GPHOTO2_ROOT=$PWD/libgphoto2/local_install + MACOSX_DEPLOYMENT_TARGET="13.0" + SYSTEM_VERSION_COMPAT=0 + CIBW_TEST_COMMAND: > + python3 -m gphoto2 -v && + python3 -m unittest discover {project}/tests -v CIBW_BEFORE_ALL: > - brew install libexif jpeg-turbo libtool libusb gd gettext && + brew install libexif && pushd $PWD/libgphoto2 && ./configure --prefix=$PWD/local_install --disable-internal-docs \ --enable-vusb \ @@ -36,35 +42,7 @@ jobs: popd - name: Store results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: macos-wheels path: wheelhouse/*.whl - - test: - needs: build - runs-on: macos-latest - strategy: - matrix: - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Fetch wheel files - uses: actions/download-artifact@v4.1.7 - with: - name: macos-wheels - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - architecture: 'x64' - - - name: Install wheel - run: pip3 install --disable-pip-version-check --no-index - --find-links=. gphoto2 - - - name: Test installation - run: python3 -m unittest discover tests -v diff --git a/.github/workflows/build-manylinux.yml b/.github/workflows/build-manylinux.yml index 20d26ee..c878870 100644 --- a/.github/workflows/build-manylinux.yml +++ b/.github/workflows/build-manylinux.yml @@ -1,4 +1,4 @@ -name: Build manylinux binary wheels +name: build gphoto2 linux x86_64 on: workflow_dispatch jobs: @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download libgphoto2 run: wget -nv @@ -20,60 +20,27 @@ jobs: --directory $PWD/libgphoto2 --strip-components=1 - name: Build wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.21.3 env: CIBW_ARCHS: auto64 + CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28 CIBW_BUILD: cp*-manylinux_x86_64 CIBW_ENVIRONMENT: GPHOTO2_ROOT=$PWD/libgphoto2/local_install + CIBW_TEST_COMMAND: > + python3 -m gphoto2 -v && + python3 -m unittest discover {project}/tests -v CIBW_BEFORE_ALL: > - yum install -y libusbx-devel libexif-devel libjpeg-turbo-devel \ - gd-devel libcurl-devel libxml2-devel libtool-ltdl-devel && + yum install -y libusbx-devel libexif-devel libjpeg-turbo-devel + gd-devel libcurl-devel libxml2-devel libtool-ltdl-devel && pushd $PWD/libgphoto2 && - ./configure --prefix=$PWD/local_install --disable-internal-docs \ - --enable-vusb && + ./configure --prefix=$PWD/local_install --disable-internal-docs + --enable-vusb && make && make install && popd - name: Store results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: manylinux-wheels path: wheelhouse/*.whl - - test: - needs: build - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] - os: [ubuntu-latest] - include: - - python-version: '3.6' - os: ubuntu-20.04 - runs-on: ${{ matrix.os }} - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Fetch wheel files - uses: actions/download-artifact@v4.1.7 - with: - name: manylinux-wheels - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - architecture: 'x64' - - - name: Install locales - run: | - sudo apt-get install locales - sudo locale-gen de - - - name: Install wheel - run: pip3 install --disable-pip-version-check --no-index - --find-links=. gphoto2 - - - name: Test installation - run: python3 -m unittest discover tests -v From 89a629b5a28ae23ec7c70331a4a29324cf520c21 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Mon, 14 Oct 2024 13:13:41 +0100 Subject: [PATCH 4/4] Add Github action to build for macOS ARM64 --- .github/workflows/build-macos-arm.yml | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build-macos-arm.yml diff --git a/.github/workflows/build-macos-arm.yml b/.github/workflows/build-macos-arm.yml new file mode 100644 index 0000000..cfb3043 --- /dev/null +++ b/.github/workflows/build-macos-arm.yml @@ -0,0 +1,48 @@ +name: build gphoto2 macOS arm64 +on: workflow_dispatch + +jobs: + build: + runs-on: macos-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Download libgphoto2 + run: wget -nv + https://github.com/gphoto/libgphoto2/releases/download/v2.5.31/libgphoto2-2.5.31.tar.xz + -O libgphoto2.tar.xz + + - name: Extract libgphoto2 + run: | + mkdir $PWD/libgphoto2 + tar xf libgphoto2.tar.xz \ + --directory $PWD/libgphoto2 --strip-components=1 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.3 + env: + CIBW_ARCHS: arm64 + CIBW_SKIP: pp3* + CIBW_ENVIRONMENT: > + GPHOTO2_ROOT=$PWD/libgphoto2/local_install + MACOSX_DEPLOYMENT_TARGET="14.0" + SYSTEM_VERSION_COMPAT=0 + CIBW_TEST_COMMAND: > + python3 -m gphoto2 -v && + python3 -m unittest discover {project}/tests -v + CIBW_BEFORE_ALL: > + brew install libexif libtool gd && + pushd $PWD/libgphoto2 && + ./configure --prefix=$PWD/local_install --disable-internal-docs \ + --enable-vusb \ + CFLAGS="-D_DARWIN_C_SOURCE -I$(brew --prefix)/include" && + make && + make install && + popd + + - name: Store results + uses: actions/upload-artifact@v4 + with: + name: macos-wheels + path: wheelhouse/*.whl