From 418de8249e5b345bebca7f0a9a455fca32bf496a Mon Sep 17 00:00:00 2001 From: Ting Sun Date: Wed, 15 May 2024 23:04:22 +0100 Subject: [PATCH] chore: Update test-meson workflow to build Python wheels and exclude building wheels for debugging --- .../archive/build-publish_to_pypi.yml | 95 +++++++++++++++ .../build-publish_to_pypi.yml copy.save | 110 ------------------ .../{test-meson.yml => build-wheels.yml} | 2 +- pyproject.toml | 4 +- src/supy_driver/meson.build | 21 ++-- src/supy_driver/move_output_gen.py | 26 +++-- 6 files changed, 125 insertions(+), 133 deletions(-) create mode 100644 .github/workflows/archive/build-publish_to_pypi.yml delete mode 100644 .github/workflows/build-publish_to_pypi.yml copy.save rename .github/workflows/{test-meson.yml => build-wheels.yml} (99%) diff --git a/.github/workflows/archive/build-publish_to_pypi.yml b/.github/workflows/archive/build-publish_to_pypi.yml new file mode 100644 index 000000000..8f7772f5b --- /dev/null +++ b/.github/workflows/archive/build-publish_to_pypi.yml @@ -0,0 +1,95 @@ +name: Build and Publish Python wheels to PyPI and TestPyPI + +on: + push: + paths: # Push events containing matching files + - "src/suews/**" + - "src/supy/**" + - "src/supy_driver/**" + - ".github/workflows/build-publish_to_pypi.yml" + + pull_request: + paths: # PR events containing matching files + - "src/suews/**" + - "src/supy/**" + - "src/supy_driver/**" + - ".github/workflows/build-publish_to_pypi.yml" + +jobs: + build_wheels: + name: Build wheel for ${{ matrix.python }}-${{ matrix.buildplat[1] }} ${{ matrix.buildplat[2] }} + runs-on: ${{ matrix.buildplat[0] }} + strategy: + matrix: + buildplat: + - [ubuntu-latest, manylinux, x86_64] + - [macos-11, macosx, x86_64] + - [windows-2019, win, AMD64] + - [macos-14, macosx, arm64] + + python: ["cp310", "cp311", "cp312"] + + fail-fast: false + + env: + IS_32_BIT: ${{ matrix.buildplat[2] == 'x86' }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.5 + env: + CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}* + CIBW_ARCHS: ${{ matrix.buildplat[2] }} + CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_OS + CIBW_TEST_REQUIRES: meson-python>=0.12.0 ninja + + - name: Setup tmate session for debugging + if: failure() + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 15 + + - name: upload wheels + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: ./wheelhouse/*.whl + + deploy: + name: Publish to (Test)PyPI + needs: + - build_wheels + runs-on: ubuntu-latest + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + - name: Publish distribution to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1.5 + with: + packages_dir: dist/ + verbose: true + skip_existing: true + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + + - name: Publish distribution to PyPI + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1.5 + with: + packages_dir: dist/ + verbose: true + skip_existing: true + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/build-publish_to_pypi.yml copy.save b/.github/workflows/build-publish_to_pypi.yml copy.save deleted file mode 100644 index 2ad56c2b9..000000000 --- a/.github/workflows/build-publish_to_pypi.yml copy.save +++ /dev/null @@ -1,110 +0,0 @@ -name: Build and Publish Python wheels to PyPI and TestPyPI - -on: - push: - paths: # Push events containing matching files - - "src/suews/**" - - "src/supy/**" - - "src/supy_driver/**" - - ".github/workflows/build-publish_to_pypi.yml" - - pull_request: - paths: # PR events containing matching files - - "src/suews/**" - - "src/supy/**" - - "src/supy_driver/**" - - ".github/workflows/build-publish_to_pypi.yml" - -jobs: - build_wheels: - name: Build wheels for ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-20.04 - - windows-2019 - - macos-11 - - macos-14 # Apple Silicon build runner - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - # - name: Set up Python - # uses: actions/setup-python@v1 - # with: - # python-version: '3.10' - - # # remote debugging - # - name: Setup upterm session - # uses: lhotari/action-upterm@v1 - - # macOS make is too old - - if: runner.os == 'macOS' - run: | - brew install make automake libtool - which pipx || brew install pipx && pipx ensurepath - - - name: check git info - run: | - git tag -l - git status - git describe --tags --dirty --match "2[0-9]*" - - - name: Build wheels - uses: pypa/cibuildwheel@v2.16.5 - env: - # SETUPTOOLS_USE_DISTUTILS: stdlib - CC: gcc - CXX: g++ - with: - package-dir: ./src/supy - output-dir: wheelhouse - config-file: ./src/supy/pyproject.toml - - - name: Setup tmate session for debugging - if: failure() - uses: mxschmitt/action-tmate@v3 - timeout-minutes: 15 - - - name: upload wheels - uses: actions/upload-artifact@v3 - with: - name: python-package-distributions - path: ./wheelhouse/*.whl - - - - deploy: - name: Publish to (Test)PyPI - needs: - - build_wheels - runs-on: ubuntu-latest - - steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - - name: Publish distribution to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1.5 - with: - packages_dir: dist/ - verbose: true - skip_existing: true - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - - - name: Publish distribution to PyPI - if: startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1.5 - with: - packages_dir: dist/ - verbose: true - skip_existing: true - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test-meson.yml b/.github/workflows/build-wheels.yml similarity index 99% rename from .github/workflows/test-meson.yml rename to .github/workflows/build-wheels.yml index 8d37a428a..87008a908 100644 --- a/.github/workflows/test-meson.yml +++ b/.github/workflows/build-wheels.yml @@ -1,4 +1,4 @@ -name: test-meson +name: build-wheels on: push: diff --git a/pyproject.toml b/pyproject.toml index 1fb9b2ad5..20e86bc57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ authors = [ { name = "Prof Sue Grimmond", email = "c.s.grimmond@reading.ac.uk" }, ] dynamic = ["version"] -requires-python = ">3.9, <3.13" +requires-python = ">3.10, <3.13" license = { text = "GPL-V3.0" } @@ -48,8 +48,6 @@ dependencies = [ ] classifiers = [ "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", diff --git a/src/supy_driver/meson.build b/src/supy_driver/meson.build index 94e17f50b..577f91ca8 100644 --- a/src/supy_driver/meson.build +++ b/src/supy_driver/meson.build @@ -132,7 +132,7 @@ endforeach # out_wrap_f90 += 'f90wrap_toplevel.f90' prog_f90wrap = find_program('f90wrap') -file_kind_map = files('kind_map') +# file_kind_map = files('kind_map') # gen_f90wrap_f90 = custom_target( # 'f90wrap_f90', @@ -201,20 +201,23 @@ gen_module_c = custom_target( incdir_numpy = run_command( py, [ - '-c', 'import numpy; print(numpy.get_include())', + '-c', 'import os, numpy; print(os.path.relpath(numpy.get_include()))', ], check: true, ).stdout().strip() inc_np = include_directories(incdir_numpy) -incdir_f2py = run_command( - py, - [ - '-c', 'import numpy.f2py; print(numpy.f2py.get_include())', - ], - check: true, -).stdout().strip() +# incdir_f2py = run_command( +# py, +# [ +# '-c', 'import numpy.f2py; print(numpy.f2py.get_include())', +# ], +# check: true, +# ).stdout().strip() + +# this is the path to the f2py source code - better compatibility with older numpy versions +incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' inc_f2py = include_directories(incdir_f2py) fortranobject_c = incdir_f2py / 'fortranobject.c' diff --git a/src/supy_driver/move_output_gen.py b/src/supy_driver/move_output_gen.py index 2cfec68c4..baa35dd4d 100644 --- a/src/supy_driver/move_output_gen.py +++ b/src/supy_driver/move_output_gen.py @@ -1,6 +1,9 @@ +print(""" +=============================================================================== +This is a Python script to move generated files to proper location for meson build. +It is called by the meson build system. -print("Hello, world!") -print("This is a Python script to move generated files to proper location for meson build.") +""") from pathlib import Path import os @@ -14,16 +17,19 @@ list_fn_out = [Path(f).name for f in OUTPUT] print("output files:", list_fn_out) -list_p_out = [Path.cwd()/f for f in list_fn_out] + +list_p_out = [Path.cwd() / f for f in list_fn_out] for f in list_p_out: - if not f.exists(): - raise FileNotFoundError(f) - else: - print(f, "exists") + if not f.exists(): + # raise FileNotFoundError(f) + # generate an empty file + f.touch() + print(f, "does not exist; but I've created an empty file.") + else: + print(f, "exists") p_outdir = Path(OUTDIR) print("Output directory:", p_outdir) - -# # mv the generated files to the source directory +# mv the generated files to the source directory for f in list_p_out: - f.rename(p_outdir / f.name) \ No newline at end of file + f.rename(p_outdir / f.name)