Skip to content

Commit

Permalink
add sdist + release change
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGupta2012 committed Nov 26, 2024
1 parent d1305c8 commit 3dc92bc
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 16 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:
branches: ['main']
workflow_dispatch:

# Reference: https://github.com/scikit-learn/scikit-learn/blob/main/.github/workflows/wheels.yml
# Reference: https://github.com/scikit-learn/scikit-learn/blob/main/.github/workflows
jobs:
build:
build_wheels:
if: github.event.pull_request.draft == false
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
# Thus, the matrix.python is not required here, only for setting up builds
python-version: "3.11"

- name: Build and Test the package
- name: Build and Test Wheels
env:
# since cibuildwheel builds for all python versions >= current version, we need to
# restrict it to the one used in this job
Expand All @@ -114,15 +114,35 @@ jobs:
if: ${{ matrix.os == 'macos-14' && matrix.python == 311 }}
uses: actions/upload-artifact@v4
with:
name: built-package-${{ matrix.python }}-${{ matrix.os }}
name: package-wheel-cp${{ matrix.python }}-${{ matrix.os }}
path: dist/*.whl

build_sdist:
name: Source distribution
runs-on: ubuntu-latest

steps:
- name: Checkout Pyqasm
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build source distribution
run: bash bin/build_sdist.sh

- name: Test source distribution
run: bash bin/test_sdist.sh


# We need a separate job for coverage as the build job is run inside a docker container.
# Since coverage uses generated files after running the tests, we need to run the tests on
# Since coverage uses files generated after running the tests, we need to run the tests on
# the host machine
code-coverage:
if: ${{ github.event.pull_request.draft == false }}
needs: build
needs: build_wheels
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -141,10 +161,10 @@ jobs:
- name: Download built package
uses: actions/download-artifact@v4
with:
name: built-package-${{ matrix.python }}-${{ matrix.os }}
name: package-wheel-cp${{ matrix.python }}-${{ matrix.os }}
path: dist

- name: Install and Test package wheel with extras
- name: Install and Test wheel with extras
run: |
pip install setuptools
for wheel in dist/*.whl; do
Expand Down
147 changes: 140 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,157 @@ on:
workflow_dispatch:

jobs:
build_wheels:
if: github.event.pull_request.draft == false
runs-on: ${{ matrix.os }}
strategy:

# Ensure that a wheel builder finishes even if another fails
fail-fast: false

matrix:
include:
# Windows 64 bit
- os: windows-latest
python: 310
platform_id: win_amd64
- os: windows-latest
python: 311
platform_id: win_amd64
- os: windows-latest
python: 312
platform_id: win_amd64
- os: windows-latest
python: 313
platform_id: win_amd64

# Linux 64 bit 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
- os: ubuntu-latest
python: 313
platform_id: manylinux_x86_64
manylinux_image: manylinux2014

# MacOS x86_64
- os: macos-13
python: 310
platform_id: macosx_x86_64
- os: macos-13
python: 311
platform_id: macosx_x86_64
- os: macos-13
python: 312
platform_id: macosx_x86_64
- os: macos-13
python: 313
platform_id: macosx_x86_64

# MacOS 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
- os: macos-14
python: 313
platform_id: macosx_arm64


steps:
- name: Checkout Pyqasm
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build and Test Wheels
env:
CIBW_BUILD: "cp${{ matrix.python }}-${{ matrix.platform_id }}"
CIBW_ARCHS_LINUX: x86_64
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_BEFORE_BUILD: bash {project}/bin/cibw/pre_build.sh
CIBW_BEFORE_TEST: bash {project}/bin/cibw/pre_test.sh
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: bash {project}/bin/cibw/test_wheel.sh {project}
CIBW_BUILD_VERBOSITY: 1

run: bash bin/cibw/build_wheels.sh

- name: Upload built wheels
uses: actions/upload-artifact@v4
with:
name: package-wheel-cp${{ matrix.python }}-${{ matrix.os }}
path: dist/*.whl

build_sdist:
name: Source distribution
runs-on: ubuntu-latest

steps:
- name: Checkout Pyqasm
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build source distribution
run: bash bin/build_sdist.sh

- name: Test source distribution
run: bash bin/test_sdist.sh

- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: package-sdist
path: dist/*.tar.gz

pypi-publish:
name: Build dist & upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: release

steps:
- uses: actions/checkout@v4
- name: Checkout Pyqasm
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
fetch-depth: 1
# pattern should match the upload artifact naming convention
# of the previous jobs
pattern: package-*
path: dist
# put all files in single directory
merge-multiple: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build binary wheel + source tarball
python-version: '3.11'
run: |
python3 -m pip install --upgrade pip build
python3 -m build
python -m pip install --upgrade pip
python -m pip install twine
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Success: no issues found in 2 source files
- Migrated `pyqasm.linalg._kronecker_factor` to `pyqasm.linalg_cy` with ~60% speedup
- Migrated `pyqasm.linalg._so4_to_so2()` to to `pyqasm.linalg_cy` with ~5% speedup
- Changed source code directory from `./pyqasm` to `./src/pyqasm` to prevents conflicts between the local source directory and the installed package in site-packages, ensuring Python's module resolution prioritizes the correct version. Required for local testing with new Cython build step ([#83](https://github.com/qBraid/pyqasm/pull/83))
- Updated the build process for `pyqasm` due to Cython integration. Wheels are now built for each platform and uploaded to PyPI along with the source distributions ([#88](https://github.com/qBraid/pyqasm/pull/88))
### Deprecated
Expand Down
34 changes: 34 additions & 0 deletions bin/build_sdist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Copyright (C) 2024 qBraid
#
# This file is part of the pyqasm
#
# Pyqasm is free software released under the GNU General Public License v3
# or later. You can redistribute and/or modify it under the terms of the GPL v3.
# See the LICENSE file in the project root or <https://www.gnu.org/licenses/gpl-3.0.html>.
#
# THERE IS NO WARRANTY for the pyqasm, as per Section 15 of the GPL v3.

set -e
set -x

# Move up 1 level to create the virtual
# environment outside of the source folder
cd ..

python -m venv build_env
source build_env/bin/activate

python -m pip install numpy cython
python -m pip install twine build

cd pyqasm
python -m build --sdist --outdir dist

# Check whether the source distribution will render correctly
twine check dist/*.tar.gz

# Deactivate the virtual environment and remove it
deactivate
rm -rf build_env
35 changes: 35 additions & 0 deletions bin/test_sdist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Copyright (C) 2024 qBraid
#
# This file is part of the pyqasm
#
# Pyqasm is free software released under the GNU General Public License v3
# or later. You can redistribute and/or modify it under the terms of the GPL v3.
# See the LICENSE file in the project root or <https://www.gnu.org/licenses/gpl-3.0.html>.
#
# THERE IS NO WARRANTY for the pyqasm, as per Section 15 of the GPL v3.

set -e
set -x

# Move up 1 level to create the virtual
# environment outside of the source folder
cd ..

python -m venv test_env
source test_env/bin/activate

# Install the source distribution
python -m pip install pyqasm/dist/*.tar.gz

# Install test and CLI extra
pip install pytest
pip install "typer>=0.12.1" typing-extensions "rich>=10.11.0"

# Run the tests on the installed source distribution
pytest pyqasm/tests

# Deactivate the virtual environment and remove it
deactivate
rm -rf build_env
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pyqasm = "pyqasm.cli.main:app"

[tool.black]
line-length = 100
target-version = ["py311", "py312", "py313"]
target-version = ["py310", "py311", "py312", "py313"]

[tool.isort]
profile = "black"
Expand Down

0 comments on commit 3dc92bc

Please sign in to comment.