diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 29074ae..c7b66aa 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c4a5bc..fa3b8a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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" @@ -30,8 +32,9 @@ 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: @@ -39,27 +42,39 @@ jobs: 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: diff --git a/.gitignore b/.gitignore index 548ecc6..c70a1d0 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ docs/_build/ # PyBuilder target/ -*~ \ No newline at end of file +*~ + +src/bitstruct/_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..aecfebc --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/Makefile b/Makefile deleted file mode 100644 index d310ed1..0000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -test: - python3 -m pip install -e . - python3 -m unittest diff --git a/docs/conf.py b/docs/conf.py index bd06f9c..03002ce 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 964835c..72898f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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" diff --git a/setup.py b/setup.py deleted file mode 100755 index 2e9eac1..0000000 --- a/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -import platform - -import setuptools - -if platform.python_implementation() == "CPython": - ext_modules = [ - setuptools.Extension( - "bitstruct.c", - sources=[ - "src/bitstruct/c.c", - "src/bitstruct/bitstream.c", - ], - ) - ] -else: - ext_modules = [] - -setuptools.setup( - ext_modules=ext_modules, -) diff --git a/src/bitstruct/__init__.py b/src/bitstruct/__init__.py index efb4dda..66921cf 100644 --- a/src/bitstruct/__init__.py +++ b/src/bitstruct/__init__.py @@ -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