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

Build and upload binary wheels in CI #36

Merged
merged 19 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
39 changes: 7 additions & 32 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,20 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
fail-fast: false
matrix:
python-version: ['3.7', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install pytest
python -m pip install .
- name: Test
run: |
python setup.py build_ext -b .
python -m unittest

release:
needs: [test]
runs-on: ubuntu-20.04
if: startsWith(github.ref, 'refs/tags')

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install pypa/build
run: |
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: |
git clean -dfx
python -m build --sdist --outdir dist/ .
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
skip_existing: true
password: ${{ secrets.pypi_password }}
python -m pytest -v --assert=plain ./tests
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build & Release

on:
release:
types: [ published ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? How do I trigger this workflow? I usually want to publish to PyPI on all tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread what you said earlier to be honest. So this workflow would be triggered whenever you publish a new release here on GitHub. But i just noticed, that you don't do that 😄
image

I'll change that back so it is triggered by tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the solution from here
Hopefully that works.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try it out. I'll merge!


jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false

steps:
- uses: actions/checkout@v4

# Used to host cibuildwheel
- uses: actions/setup-python@v4
with:
python-version: "3.10"

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

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse

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

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

release:
name: Publish distribution 📦 to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
with:
skip_existing: true
password: ${{ secrets.pypi_password }}
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include LICENSE
include Makefile
include bitstruct/c.c
include bitstruct/bitstream.[hc]
include src/bitstruct/c.c
include src/bitstruct/bitstream.[hc]
recursive-include docs *.bat
recursive-include docs *.py
recursive-include docs *.rst
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test:
python3 setup.py build_ext -b .
python3 -m pip install -e .
python3 -m unittest
1 change: 0 additions & 1 deletion bitstruct/version.py

This file was deleted.

55 changes: 55 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[build-system]
build-backend = 'setuptools.build_meta'
requires = ["setuptools >= 68.0"]

[project]
name = "bitstruct"
description = """This module performs conversions between Python values \
and C bit field structs represented as Python \
byte strings."""
readme = "README.rst"
requires-python = ">=3.7"
license = { text = "MIT" }
keywords = [
"bit field",
"bit parsing",
"bit unpack",
"bit pack",
]
authors = [
{ name = "Erik Moqvist", email = "[email protected]" },
{ name = "Ilya Petukhov" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = []
dynamic = ["version"]

[project.urls]
Documentation = "https://bitstruct.readthedocs.io/en/latest/"
Issues = "https://github.com/eerimoq/bitstruct/issues"
Source = "https://github.com/eerimoq/bitstruct"
Homepage = "https://github.com/eerimoq/bitstruct"

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.dynamic]
version = {attr = "bitstruct.__version__"}

[tool.setuptools.package-data]
"*" = [
"**/py.typed",
"**.pyi",
]

[tool.cibuildwheel]
test-requires = "pytest"
test-command = "pytest -v --assert=plain {project}/tests"
build-frontend = "build"
skip = "pp*"
66 changes: 12 additions & 54 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,19 @@
#!/usr/bin/env python

import sys
import re
import setuptools
import platform
from setuptools import find_packages


def find_version():
return re.search(r"^__version__ = '(.*)'$",
open('bitstruct/version.py', 'r').read(),
re.MULTILINE).group(1)


def is_cpython_3():
if platform.python_implementation() != 'CPython':
return False

if sys.version_info[0] < 3:
return False

return True
import setuptools

if platform.python_implementation() == "CPython":
ext_modules = [
setuptools.Extension(
"bitstruct.c",
sources=[
"src/bitstruct/c.c",
"src/bitstruct/bitstream.c",
],
)
]

def setup(ext_modules):
setuptools.setup(
name='bitstruct',
version=find_version(),
description=('This module performs conversions between Python values '
'and C bit field structs represented as Python '
'byte strings.'),
long_description=open('README.rst', 'r').read(),
author='Erik Moqvist, Ilya Petukhov',
author_email='[email protected]',
license='MIT',
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
],
keywords=['bit field', 'bit parsing', 'bit unpack', 'bit pack'],
url='https://github.com/eerimoq/bitstruct',
packages=find_packages(exclude=['tests']),
ext_modules=ext_modules,
test_suite="tests")


if is_cpython_3():
try:
setup([setuptools.Extension('bitstruct.c',
sources=[
'bitstruct/c.c',
'bitstruct/bitstream.c'
])])
except:
print('WARNING: Failed to build the C extension.')
setup([])
else:
print('INFO: C extension only implemented in CPython 3.')
setup([])
)
Loading