From 773435f92743cf4494f6ff84ffe24b8197786c86 Mon Sep 17 00:00:00 2001 From: Drew Oldag <47493171+drewoldag@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:50:33 -0700 Subject: [PATCH] Adding workflow to publish to PyPI (#42) * Updating pyproject.toml and rewriting publish-to-pypi.yml. * Working to get builds to pass. * Focusing just on linux for now. * Adding cmake to dev dependencies, install cmake before build. * Remove cibw before_build requirement, move cmake to build-system requires. * Increase logging to help debug the problem. * Stab in the dark to get pybind installed locally. * Attempting to explicitly define the OS/python versions to build. * Attempting to update xcode version for OSX build. * Trying to install libomp.h But there are warnings that this might not be the best thing to do. * Running just linux and windows. * Recursively pull in repos. * Remove windows, add M1 mac. * Trying to help find omp.h * Giving older mac osx a try. * Focus exclusively on linux for now. * Updating project name to test publishing. * Using clang compiler in CMakeLists.txt and building mac OSs. * Attempting to use g++ as the compiler. * Stabbing in the dark, trying to get llvm to work for mac. * Removing attempts for mac builds, leaving linux builds. --- .github/workflows/publish-to-pypi.yml | 132 +++++++++++++++++++++++--- pyproject.toml | 4 +- setup.py | 2 +- 3 files changed, 121 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 6f9f295b..c36e44db 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -9,6 +9,7 @@ name: Upload Python Package on: + workflow_dispatch: release: types: [published] @@ -16,24 +17,125 @@ permissions: contents: read jobs: - deploy: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # os: [ubuntu-latest, windows-latest, macos-latest, macos-14] + include: + # Linux 64 bit manylinux2014 + # - os: ubuntu-latest + # python: 39 + # platform_id: manylinux_x86_64 + # manylinux_image: manylinux2014 + - os: ubuntu-latest + python: 310 + platform_id: manylinux_x86_64 + manylinux_image: manylinux2014 + # - os: ubuntu-latest + # python: 311 + # platform_id: manylinux_x86_64 + # manylinux_image: manylinux2014 + # - os: ubuntu-latest + # python: 312 + # platform_id: manylinux_x86_64 + # manylinux_image: manylinux2014 + + # MacOS x86_64 + # - os: macos-latest + # python: 39 + # platform_id: macosx_x86_64 + # - os: macos-latest + # python: 310 + # platform_id: macosx_x86_64 + # - os: macos-latest + # python: 311 + # platform_id: macosx_x86_64 + # - os: macos-latest + # python: 312 + # platform_id: macosx_x86_64 + + # MacOS arm64 + # - os: macos-14 + # python: 39 + # platform_id: macosx_arm64 + # - os: macos-14 + # python: 310 + # platform_id: macosx_arm64 + # - os: macos-14 + # python: 311 + # platform_id: macosx_arm64 + # - os: macos-14 + # python: 312 + # platform_id: macosx_arm64 + + steps: + - name: Checkout LePhare + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Attempt to install XCode version + uses: maxim-lobanov/setup-xcode@v1 + if: matrix.os == 'macos-14' + with: + xcode-version: '15.1' + + - name: Build wheels + uses: pypa/cibuildwheel@v2.17.0 + env: + # CIBW_ARCHS_MACOS: auto universal2 + CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} + CIBW_ARCHS: all + CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }} + CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }} + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: wheelhouse/*.whl + + build_sdist: + name: Make SDist runs-on: ubuntu-latest - permissions: - id-token: write steps: - uses: actions/checkout@v4 with: - submodules: recursive - - name: Set up Python - uses: actions/setup-python@v5 + fetch-depth: 0 # Optional, use if you use setuptools_scm + submodules: true # Optional, use if you have submodules + + - name: Build SDist + run: pipx run build --sdist + + - name: Upload SDist + uses: actions/upload-artifact@v4 with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@release/v1 + name: cibw-sdist + path: dist/*.tar.gz + + upload_pypi: + name: Upload to test-pypi + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + environment: test-pypi + permissions: + id-token: write + # if: github.event_name == 'release' && github.event.action == 'published' + # # or, alternatively, urpload to PyPI on evey tag starting with 'v' (remove on: release above to use this) + # # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - name: Download distribution files + uses: actions/download-artifact@v4 + with: + # unpacks all CIBW artifacts into dist/ + pattern: cibw-* + path: dist + merge-multiple: true + + - name: Upload to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index dc2c8830..464f1d18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "lephare" +name = "lephare-dev" license = {file = "LICENSE"} readme = "README.md" authors = [ @@ -39,6 +39,8 @@ dev = [ requires = [ "setuptools>=62", # Used to build and package the Python project "setuptools_scm>=6.2", # Gets release version from git. Makes it available programmatically + "pybind11>=2.11", # Used to create Python bindings for C++ code + "cmake", # Used to build C++ code ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 944f86b7..b1fa8dd5 100644 --- a/setup.py +++ b/setup.py @@ -85,7 +85,7 @@ def run(self): setup( - name="lephare", + name="lephare-dev", version="2.0.0", author="Johann Cohen-Tanugi", author_email="johann.cohentanugi@gmail.com",