diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index daf18f4b2..f84b55925 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -56,25 +56,46 @@ on: - published jobs: - deploy: - runs-on: ubuntu-latest + build_wheels: + name: Build wheels on ${{ matrix.python }} - ${{matrix.os}} + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-22.04, macos-11, windows-2022] + python: ["cp39", "cp310", "cp311"] steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - name: Build Wheels + uses: pypa/cibuildwheel@v2.16.1 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_sdist: + name: Build Source Distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + run: pipx run build --sdist + - uses: actions/upload-artifact@v3 with: - python-version: '3.x' - # - name: Install dependencies - # run: | - # python -m pip install --upgrade pip - # python -m pip install build - # - name: Build package - # run: python -m build - # - name: Publish package to test.pypi - # uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # user: __token__ - # password: ${{ secrets.PYPI_API_JPMC_OSS }} - # print_hash: true + path: dist/*.tar.gz + upload_pypi: + needs: [build_sdist, build_wheels] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TEST_API_JPMC_OSS }} diff --git a/.github/workflows/pypi-test-publish.yml b/.github/workflows/pypi-test-publish.yml index 2b5e0c94b..2fe0e23df 100644 --- a/.github/workflows/pypi-test-publish.yml +++ b/.github/workflows/pypi-test-publish.yml @@ -1,30 +1,53 @@ -name: Upload Python Package to PyPI +name: Upload Python Package to PyPI Test on: - release: - types: - - published + workflow_dispatch: + pull_request: + jobs: - deploy: + build_wheels: + name: Build wheels on ${{ matrix.python }} - ${{matrix.os}} + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-22.04, macos-11, windows-2022] + python: ["cp39", "cp310", "cp311"] + + steps: + - uses: actions/checkout@v4 + - name: Build Wheels + uses: pypa/cibuildwheel@v2.16.1 + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_sdist: + name: Build Source Distribution runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + run: pipx run build --sdist + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + upload_pypi: + needs: [build_sdist, build_wheels] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 + - uses: actions/download-artifact@v3 with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install build - - name: Build package - run: python -m build - - name: Publish package to test.pypi - uses: pypa/gh-action-pypi-publish@release/v1 + name: artifact + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.PYPI_TEST_API_JPMC_OSS }} repository-url: https://test.pypi.org/legacy/ - print_hash: true + skip-existing: true \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 03d6b6ff0..494d17e8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,8 +58,7 @@ solvers = [ [build-system] requires = ["setuptools>=45", -"wheel", -"setuptools_scm[toml]>=6.2",] +"wheel"] build-backend = "setuptools.build_meta" [tool.black] diff --git a/qokit/fur/c/csim/src/diagonal.c b/qokit/fur/c/csim/src/diagonal.c index cdba26356..151a82cbb 100644 --- a/qokit/fur/c/csim/src/diagonal.c +++ b/qokit/fur/c/csim/src/diagonal.c @@ -4,8 +4,6 @@ ****************************************/ #include #include -#include - #include diff --git a/setup.py b/setup.py index 0302bc5ad..853c89c04 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,11 @@ # // SPDX-License-Identifier: Apache-2.0 # // Copyright : JP Morgan Chase & Co ############################################################################### -from setuptools import setup, find_packages, Extension +from setuptools import setup, find_packages, Extension, Distribution from setuptools.command.build_ext import build_ext import subprocess import os +import sys environment_variable_name = "QOKIT_NO_C_ENV" @@ -17,9 +18,15 @@ if environment_variable_value is not None: QOKIT_NO_C_ENV = True +path = "./qokit/fur/c/csim/src/" + +sources = [os.path.join(path, "diagonal.c"), os.path.join(path, "fur.c"), os.path.join(path, "qaoa_fur.c")] + extensions = [] if not QOKIT_PYTHON_ONLY: - extensions.append(Extension("simulator", sources=["qokit/fur/c/csim/src/*.c"], include_dirs=["simulator"])) + extensions.append( + Extension("simulator", sources=sources, include_dirs=[os.path.join(path, "")], extra_compile_args=["/d2FH4-"] if sys.platform == "win32" else []) + ) class SimulatorBuild(build_ext): @@ -28,7 +35,7 @@ def run(self): if not QOKIT_PYTHON_ONLY: if QOKIT_NO_C_ENV: raise Exception("No C/C++ enviroment setup") - subprocess.call(["make", "-C", "qokit/fur/c/csim/src"]) + subprocess.call(["make", "-C", path]) super().run except Exception as e: print("No C/C++ enviroment setup to compile the C simulator. Installing Python Simulator") @@ -40,6 +47,6 @@ def run(self): setup( ext_modules=extensions, - cmdclass={"build_ext": SimulatorBuild}, + cmdclass={"build_ext": SimulatorBuild} if sys.platform == "win32" else {}, packages=find_packages(), )