From a538248db772d104bb4f51fde3fdf466544a360f Mon Sep 17 00:00:00 2001 From: Jacob Wilkins Date: Fri, 15 Nov 2024 12:28:28 +0000 Subject: [PATCH] Migrate to CI buildwheel entirely --- .../workflows/build_upload_pypi_wheels.yml | 47 ++++++++++--------- .github/workflows/run_tests.yml | 3 ++ build_utils/version.py | 4 +- meson.build | 3 +- pyproject.toml | 1 + tox.ini | 5 +- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build_upload_pypi_wheels.yml b/.github/workflows/build_upload_pypi_wheels.yml index db6a1fe43..29cdb8513 100644 --- a/.github/workflows/build_upload_pypi_wheels.yml +++ b/.github/workflows/build_upload_pypi_wheels.yml @@ -14,18 +14,22 @@ jobs: include: - os: windows-latest wheelname: win + cibw_archs: "AMD64" - os: macos-13 - wheelname: macos-intel + wheelname: macosx + cibw_archs: "x86_64" - os: macos-latest - wheelname: macos-arm + wheelname: macosx + cibw_archs: "arm64" - os: ubuntu-latest wheelname: manylinux + cibw_archs: "x86_64" - python-version: '3.10' - manylinux-version-tag: cp310 + version-tag: cp310 - python-version: '3.11' - manylinux-version-tag: cp311 + version-tag: cp311 - python-version: '3.12' - manylinux-version-tag: cp312 + version-tag: cp312 fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -38,6 +42,7 @@ jobs: python-version: ${{ matrix.python-version }} channels: conda-forge,defaults channel-priority: true + - name: Install llvm on Macos if: startsWith(matrix.os, 'macos') shell: bash -l {0} @@ -57,28 +62,25 @@ jobs: run: | echo "CC=${MSVC_BIN}\cl.exe" >> $GITHUB_ENV echo "CC_LD=${MSVC_BIN}\link.exe" >> $GITHUB_ENV + - name: Update Python pip, build, wheel, and twine shell: bash -l {0} run: | python -m pip install --upgrade pip build wheel twine - - name: Build Python wheel - if: matrix.os != 'ubuntu-latest' - shell: bash -l {0} + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.3 env: - NUMPY_VERSION: 2.0 - run: | - # Build against lowest required Numpy version - python -m pip install numpy==${NUMPY_VERSION} - python -m build -o wheelhouse --wheel . + CIBW_BUILD_FRONTEND: build + CIBW_BUILD: ${{ matrix.version-tag }}-* + CIBW_ARCHS: ${{ matrix.cibw_archs }} + + CIBW_CONFIG_SETTINGS_WINDOWS: "setup-args=--vsenv" + CIBW_REPAIR_WHEEL_COMMAND_MACOS: "" + + CIBW_TEST_EXTRAS: "test,brille,phonopy_reader,matplotlib" + CIBW_TEST_COMMAND: pytest {package}/tests_and_analysis/test - - name: Build manylinux Python wheel - if: matrix.os == 'ubuntu-latest' - uses: pypa/cibuildwheel@v2.12.0 - env: - CIBW_BUILD: ${{ matrix.manylinux-version-tag}}-manylinux* - CIBW_BEFORE_BUILD: python -m pip install numpy==2.0 - CIBW_ARCHS: x86_64 with: output-dir: wheelhouse @@ -98,8 +100,9 @@ jobs: - name: Upload wheels as build artifacts uses: actions/upload-artifact@v4 with: - name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }} - path: wheelhouse/*-${{ matrix.wheelname }}*.whl + name: wheel-${{ matrix.wheelname }}-${{ matrix.python-version }}-${{ matrix.cibw_archs }} + path: wheelhouse/*-${{ matrix.wheelname }}*_${{ matrix.cibw_archs }}.whl + if-no-files-found: error publish: if: github.event_name == 'release' diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 93bd1e785..dc6e4ac14 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -50,11 +50,13 @@ jobs: run: | echo "CC=${MSVC_BIN}\cl.exe" >> $GITHUB_ENV echo "CC_LD=${MSVC_BIN}\link.exe" >> $GITHUB_ENV + - name: Update pip and install dependencies shell: bash -l {0} run: | python -m pip install --upgrade pip python -m pip install -r tests_and_analysis/ci_requirements.txt + - name: Run tests, skip Python 3.11 unless workflow dispatch if: github.event_name != 'workflow_dispatch' env: @@ -65,6 +67,7 @@ jobs: if: github.event_name == 'workflow_dispatch' shell: bash -l {0} run: python -m tox + - name: Upload test results if: always() uses: actions/upload-artifact@v4 diff --git a/build_utils/version.py b/build_utils/version.py index c3cd4f918..cab731833 100644 --- a/build_utils/version.py +++ b/build_utils/version.py @@ -14,8 +14,8 @@ version += f"+{dirty[0]}.{dirty[1]}{'.dirty' if len(dirty) > 2 else ''}" break - except (OSError, subprocess.CalledProcessError): - continue + except (OSError, subprocess.CalledProcessError) as err: + print(f"Tried {gitcmd}, returned: {err}", file=sys.stderr) else: # Can't use git version_file = Path(__file__).parent.parent / "euphonic" / "version.py" version = version_file.read_text().split("=")[1].strip('"\n ') diff --git a/meson.build b/meson.build index d183edfcc..366fcc7f2 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,8 @@ project('euphonic', 'c', version: run_command('python', 'build_utils/version.py', check: true).stdout().strip(), - meson_version: '>=1.6') + meson_version: '>=1.6', + ) build = get_option('python_only') ? disabler() : [] diff --git a/pyproject.toml b/pyproject.toml index 25cf3a3db..6aec791d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ documentation = "https://euphonic.readthedocs.io/en/stable/" matplotlib = ["matplotlib>=3.8.0"] phonopy_reader = ["h5py>=3.6.0", "PyYAML>=6.0"] brille = ["brille>=0.7.0"] +test = ["mock", "pytest~=7.0", "coverage", "pytest-mock", "pytest-lazy-fixture", "pytest-xvfb"] [project.scripts] euphonic-brille-convergence = "euphonic.cli.brille_convergence:main" diff --git a/tox.ini b/tox.ini index 9607f2834..564e4db76 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,8 @@ install_command = --upgrade \ --upgrade-strategy eager \ {opts} \ - {packages} + {packages} \ + --config-setting=setup-args='--vsenv' deps = numpy -r{toxinidir}/tests_and_analysis/tox_requirements.txt @@ -88,7 +89,7 @@ commands = [testenv:py310-minrequirements-linux] whitelist_externals = rm install_command = - python -m pip install --force-reinstall {opts} {packages} + python -m pip install --force-reinstall {opts} {packages} --config-setting=setup-args='--vsenv' platform = linux: linux deps =