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

Use scikit-build-core and CMake instead of setuptools #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [
'3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8', 'pypy-3.9'
'3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', 'pypy-3.8', 'pypy-3.9'
]
exclude:
- { python-version: "3.7", os: "macos-latest" }
include:
# Python 3.7 is on macos-13 but not macos-latest (macos-14-arm64)
# https://github.com/actions/setup-python/issues/696#issuecomment-1637587760
- { python-version: "3.7", os: "macos-13" }
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
33 changes: 24 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-13, macos-latest, windows-latest]
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm

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

Expand All @@ -30,36 +32,49 @@ jobs:
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm

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

- name: Install build
run: python -m pip install build
- name: Build sdist
run: pipx run build --sdist
run: python -m build --sdist

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

release:
name: Publish distribution 📦 to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/bitstruct
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # for action-gh-release

steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ docs/_build/

# PyBuilder
target/
*~
*~

src/bitstruct/_version.py
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.15...3.26)

project(
${SKBUILD_PROJECT_NAME}
LANGUAGES C
VERSION ${SKBUILD_PROJECT_VERSION})

find_package(
Python
COMPONENTS
Interpreter
Development.Module
${SKBUILD_SABI_COMPONENT}
REQUIRED)

if("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
message(STATUS "PyPy detected. Skip compilation of C-extension.")
return()
endif()

if(NOT CMAKE_C_COMPILER)
message(STATUS "C compiler not found. Skip compilation of C-extension.")
return()
endif()

if(NOT "${SKBUILD_SABI_COMPONENT}" STREQUAL "")
# placeholder for stable abi builds
set(PY_ABI_OPTIONS "WITH_SOABI" "USE_SABI" "3.11")
else()
set(PY_ABI_OPTIONS "")
endif()

python_add_library(c
MODULE
src/bitstruct/c.c
src/bitstruct/bitstream.c
${PY_ABI_OPTIONS})

install(TARGETS c DESTINATION bitstruct)
3 changes: 0 additions & 3 deletions Makefile

This file was deleted.

8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import sys
import os
import shlex
from importlib.metadata import version as get_version

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -59,10 +59,10 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = bitstruct.__version__
# The full version, including alpha/beta/rc tags.
release = bitstruct.__version__
release: str = get_version("bitstruct")
# The short X.Y version.
version: str = ".".join(release.split('.')[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
20 changes: 8 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = 'setuptools.build_meta'
requires = ["setuptools >= 68.0"]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "bitstruct"
Expand Down Expand Up @@ -36,17 +36,13 @@ 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.scikit-build]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["src/bitstruct/_version.py"]
wheel.packages = ["src/bitstruct"]

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

[tool.setuptools.package-data]
"*" = [
"**/py.typed",
"**.pyi",
]
[tool.setuptools_scm] # Section required
write_to = "src/bitstruct/_version.py"

[tool.cibuildwheel]
test-requires = "pytest"
Expand Down
21 changes: 0 additions & 21 deletions setup.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/bitstruct/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
__version__ = '8.19.0'

import binascii
import re
import struct
from io import BytesIO

from bitstruct._version import __version__


class Error(Exception):
pass
Expand Down
Loading