Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cython backend #5

Merged
merged 5 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 88 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- uses: pre-commit/action@v2.0.3
python-version: "3.10"
- uses: pre-commit/action@v3.0.0

# Make sure commit messages follow the conventional commits convention:
# https://www.conventionalcommits.org
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
- uses: wagoid/commitlint-github-action@v5.3.1

test:
strategy:
Expand All @@ -43,22 +43,29 @@ jobs:
- "3.11"
os:
- ubuntu-latest
- windows-latest
- macOS-latest
extension:
- "skip_cython"
- "use_cython"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- uses: snok/install-poetry@v1.3.3
- name: Install Dependencies
run: poetry install
run: |
if [ "${{ matrix.extension }}" = "skip_cython" ]; then
SKIP_CYTHON=1 poetry install --only=main,dev
else
poetry install --only=main,dev
fi
shell: bash
- name: Test with Pytest
run: poetry run pytest --cov-report=xml
shell: bash
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down Expand Up @@ -89,3 +96,75 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}

build_wheels:
needs: [release]

name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-11
- ubuntu-20.04
- windows-2022

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: "main"

# Used to host cibuildwheel
- name: Set up Python
uses: actions/setup-python@v4

- name: Install python-semantic-release
run: python -m pip install python-semantic-release

- name: Get Release Tag
id: release_tag
shell: bash
run: |
echo "::set-output name=newest_release_tag::$(semantic-release print-version --current)"

- uses: actions/checkout@v3
with:
ref: "v${{ steps.release_tag.outputs.newest_release_tag }}"
fetch-depth: 0

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.12.0

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
# to supply options, put them in 'env', like:
env:
CIBW_SKIP: cp36-* pp36-*
CIBW_BEFORE_ALL_LINUX: apt-get install -y gcc || yum install -y gcc || apk add gcc
CIBW_BUILD_VERBOSITY: 3
REQUIRE_CYTHON: 1

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

upload_pypi:
needs: [build_wheels]
runs-on: ubuntu-latest
environment: release

steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@v1.5.0
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

# To test: repository_url: https://test.pypi.org/legacy/
35 changes: 35 additions & 0 deletions build_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Build optional cython modules."""

import os
from distutils.command.build_ext import build_ext


class BuildExt(build_ext):
def build_extensions(self): # type: ignore
try:
super().build_extensions()
except Exception: # nosec
pass


def build(setup_kwargs): # type: ignore
if os.environ.get("SKIP_CYTHON", False):
return
try:
from Cython.Build import cythonize

setup_kwargs.update(
dict(
ext_modules=cythonize(
[
"src/chacha20poly1305_reuseable/__init__.py",
],
compiler_directives={"language_level": "3"}, # Python 3
),
cmdclass=dict(build_ext=BuildExt),
)
)
except Exception:
if os.environ.get("REQUIRE_CYTHON"):
raise
pass
Loading