Skip to content
Snippets Groups Projects
Commit baddf731 authored by Corné Lukken's avatar Corné Lukken
Browse files

Initial binary wheel setup

parent 044146b4
Branches
Tags
1 merge request!1Initial binary wheel setup
Pipeline #52936 failed
Pipeline: Python Binary Wheel Package

#52937

    Showing
    with 173 additions and 69 deletions
    [submodule "{{cookiecutter.project_slug}}/cmake/cmake-extra-utils"]
    path = {{cookiecutter.project_slug}}/cmake/cmake-extra-utils
    url = https://github.com/LecrisUT/CMakeExtraUtils.git
    # Example Python Package
    ![Build status](https://git.astron.nl/templates/python-package/badges/main/pipeline.svg)
    ![Test coverage](https://git.astron.nl/templates/python-package/badges/main/coverage.svg)
    An example repository of an CI/CD pipeline for building, testing and publishing a python package.
    If you find some missing functionality with regards to CI/CD, testing, linting or something else, feel free to make a merge request with the proposed changes.
    # Example Python Binary Extension Wheel Package
    ![Build status](https://git.astron.nl/templates/python-binary-wheel-package/badges/main/pipeline.svg)
    ![Test coverage](https://git.astron.nl/templates/python-binary-wheel-package/badges/main/coverage.svg)
    An example repository of an CI/CD pipeline for building, testing and publishing
    a python package that uses binary extensions compiled as wheels.
    If you find some missing functionality with regards to CI/CD, testing, linting
    or something else, feel free to make a merge request with the proposed changes.
    ### Features:
    - Compile C / C++11 and bind with Python
    - Easily define any C / C++ dependency to be included using `before-all = "apt / yum xxx"`
    https://cibuildwheel.readthedocs.io/en/stable/options/#examples
    - Automatic versioning using semantic version tags (`git tag vX.X.X`)
    - Versions from `setuptools-scm` in Python are bound and forwarded to the
    C / C++ extension using the `DynamicVersion` git submodule.
    - Run any task performed by CI/CD locally such as:
    - linting (`tox -e black`, `tox -e pylint`, `tox -e pep8`)
    - automatically format code (`tox -e format`)
    - unit tests (`tox -e py37`)
    - code coverage (`tox -e coverage`)
    - building & packaging (`tox -e build-local`, `tox -e build-ci-linux`)
    - Automatically publish new releases to the gitlab package repository
    - CI/CD uses [docker base image](docker/ci-runner/Dockerfile) to speed up pipeline
    ## How to apply this template
    This templates uses `cookiecutter` which can be
    This templates uses `cookiecutter` which can be installed easily:
    ```bash
    pip install --user cookiecutter
    ......@@ -18,7 +37,7 @@ pip install --user cookiecutter
    Then you can create an instance of your template with:
    ```bash
    cookiecutter https://git.astron.nl/templates/python-package.git
    cookiecutter https://git.astron.nl/templates/python-binary-wheel-package.git
    # Next follow a set of prompts (such as the name and description of the package)
    ```
    ......
    {
    "project_name": "My Awesome App",
    "project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
    "project_url": "git.astron.nl/{{cookiecutter.project_slug}}",
    "description": "An example package for CI/CD working group"
    }
    node: $Format:%H$
    node-date: $Format:%cI$
    describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
    ref-names: $Format:%D$
    .git_archival.txt export-subst
    ......@@ -6,8 +6,11 @@ dist/*
    coverage.xml
    htmlcov/*
    # Setuptools SCM
    {{cookiecutter.project_slug}}/_version.py
    # Tox
    .tox
    # setuptools-scm
    src/python_binary_wheel/_version.py
    # IDE configuration
    .vscode
    ......
    cmake_minimum_required(VERSION 3.15...3.26)
    # Include submodule to dynamically determine version
    set(
    CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-extra-utils/cmake"
    )
    # Include script
    include(DynamicVersion)
    dynamic_version(
    ${SKBUILD_PROJECT_NAME}
    PROJECT_PREFIX PROJECT_VERSION_
    PROJECT_SOURCE $ENV{DYNAMIC_VERSION_SOURCE}
    )
    # Get project name from scikit-build-core and version DynamicVersion
    project(${SKBUILD_PROJECT_NAME} VERSION ${PROJECT_VERSION})
    # Get required packages
    find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
    find_package(pybind11 CONFIG REQUIRED)
    # Build our Pythonextension
    python_add_library(_core MODULE src/main.cpp WITH_SOABI)
    target_link_libraries(_core PRIVATE pybind11::headers)
    # Emit Python determined version as definition
    target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
    # Install the library into the build directory
    install(TARGETS _core DESTINATION python_binary_wheel)
    include LICENSE
    include README.md
    include CMakeLists.txt
    recursive-include docs *
    recursive-include docker *
    recursive-exclude tests *
    # {{cookiecutter.project_name}}
    <!-- TODO: replace -->
    ![Build status](https://git.astron.nl/templates/python-package/badges/main/pipeline.svg)
    ![Test coverage](https://git.astron.nl/templates/python-package/badges/main/coverage.svg)
    ![Build status]({{cookiecutter.project_url}}/badges/main/pipeline.svg)
    ![Test coverage]({{cookiecutter.project_url}}/badges/main/coverage.svg)
    <!-- ![Latest release](https://git.astron.nl/templates/python-package/badges/main/release.svg) -->
    An example repository of an CI/CD pipeline for building, testing and publishing a python package.
    {{cookiecutter.description}}
    ## Installation
    ```
    ......
    cibuildwheel >= 2.12.3 # BSD
    tox >= 4.0 # ?
    build >= 0.8.0 # MIT
    Subproject commit 26450da9dceea86a809fe1a38c095a0c988a6159
    [build-system]
    requires = [
    "setuptools>=45",
    "setuptools_scm[toml]>=6.2",
    "wheel"
    "scikit-build-core>=0.3.3",
    "pybind11",
    "setuptools_scm[toml]>=6.2"
    ]
    build-backend = "setuptools.build_meta"
    build-backend = "scikit_build_core.build"
    [project]
    name = "{{cookiecutter.project_slug}}"
    dynamic = ["version"]
    description="{{cookiecutter.description}}"
    readme = "README.md"
    requires-python = ">=3.7"
    classifiers = [
    "Development Status :: 4 - Beta",
    "License :: OSI Approved :: MIT License",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    ]
    [tool.scikit-build]
    experimental=true
    wheel.expand-macos-universal-tags = true
    metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
    sdist.include = ["src/{{cookiecutter.project_slug}}/_version.py"]
    [tool.setuptools_scm]
    write_to = "{{cookiecutter.project_slug}}/_version.py"
    write_to = "src/{{cookiecutter.project_slug}}/_version.py"
    [tool.cibuildwheel]
    skip = "pp*"
    build-verbosity = 1
    [tool.cibuildwheel.macos]
    archs = ["x86_64", "universal2", "arm64"]
    [tool.cibuildwheel.linux]
    archs = ["x86_64", "i686"]
    [tool.cibuildwheel.windows]
    archs = ["AMD64", "x86"]
    [tool.pylint]
    ignore = "_version.py"
    [metadata]
    name = {{cookiecutter.project_slug}}
    description = An example package for CI/CD working group
    long_description = file: README.md
    long_description_content_type = text/markdown
    url = https://git.astron.nl/templates/python-package
    license = Apache License 2.0
    classifiers =
    Development Status :: 3 - Alpha
    Environment :: Web Environment
    Intended Audience :: Developers
    Intended Audience :: Science/Research
    License :: OSI Approved :: Apache Software License
    Operating System :: OS Independent
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
    Programming Language :: Python :: 3.10
    Programming Language :: Python :: 3.11
    Topic :: Internet :: WWW/HTTP
    Topic :: Internet :: WWW/HTTP :: Dynamic Content
    Topic :: Scientific/Engineering
    Topic :: Scientific/Engineering :: Astronomy
    [options]
    include_package_data = true
    packages = find:
    python_requires = >=3.7
    install_requires =
    importlib-metadata>=0.12, <5.0;python_version<"3.8"
    numpy
    [flake8]
    max-line-length = 88
    extend-ignore = E203
    import setuptools
    setuptools.setup()
    #include <pybind11/pybind11.h>
    #define STRINGIFY(x) #x
    #define MACRO_STRINGIFY(x) STRINGIFY(x)
    int add(int i, int j) {
    return i + j;
    }
    namespace py = pybind11;
    PYBIND11_MODULE(_core, m) {
    m.doc() = R"pbdoc(
    Pybind11 example plugin
    -----------------------
    .. currentmodule:: python_binary_wheel
    .. autosummary::
    :toctree: _generate
    add
    subtract
    )pbdoc";
    m.def("add", &add, R"pbdoc(
    Add two numbers
    Some other explanation about the add function.
    )pbdoc");
    m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
    Subtract two numbers
    Some other explanation about the subtract function.
    )pbdoc");
    }
    [tox]
    # Generative environment list to test all supported Python versions
    envlist = py3{7,8,9,10},black,pep8,pylint
    envlist = py3{8,9,10,11},black,pep8,pylint
    minversion = 3.18.0
    [testenv]
    usedevelop = True
    package = wheel
    wheel_build_env = .pkg
    package = sdist # 'Source' package required for binary extension
    use_develop = False # use_develop implies 'editable' package, not possible
    setenv =
    LANGUAGE=en_US
    ......@@ -40,7 +39,11 @@ commands =
    format: {envpython} -m autopep8 -v -aa --in-place --recursive tests
    format: {envpython} -m black -v .
    [testenv:build]
    usedevelop = False
    commands = {envpython} -m build
    [testenv:{build-local,build-ci-linux}]
    deps =
    -r{toxinidir}/tests/requirements.txt
    -r{toxinidir}/build-requirements.txt
    skip_install = True
    commands =
    build-local: {envpython} -m build
    build-ci-linux: {envpython} -m cibuildwheel --platform linux --output-dir dist
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment