diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..6d436b24 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,125 @@ +name: CI + +on: + push: + branches: + - master + tags: + - '*' + pull_request: + branches: + - master + +env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + +jobs: + cpp_edlib: + name: "Check that CPP edlib correctly builds and passes tests." + strategy: + matrix: + os: [ubuntu-20.04, macos-11] + compiler: [gcc-10, clang-10] + exclude: + - os: macos-11 + compiler: gcc-10 + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install system dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y ${{ matrix.compiler }} valgrind + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Python packages + run: | + python3 -m pip install --upgrade pip setuptools meson ninja + + - name: Set C/CPP compiler to use + run: | + if [ ${{ matrix.compiler }} == "clang-10" ]; then + export CC=clang-10 && export CXX=clang++-10 + fi + if [ ${{ matrix.compiler }} == "gcc-10" ]; then + export CC=gcc-10 && export CXX=g++-10 + fi + + - name: Build binaries and libraries and test them (with Meson) + run: | + make CXXFLAGS="-Werror" LIBRARY_TYPE=static BUILD_DIR=meson-build-static + make CXXFLAGS="-Werror" LIBRARY_TYPE=shared BUILD_DIR=meson-build-shared + + # Check for memory leaks. + # I run this only on linux because osx returns errors from + # system libraries, which I would have to supress. + if [ ${{ runner.os }} == "Linux" ]; then + make check-memory-leaks BUILD_DIR=meson-build-static + fi + + - name: Build binaries and libraries and test them (with CMake) + run: | + mkdir -p build && cd build + CXXFLAGS="-Werror" cmake -GNinja .. + ninja -v + bin/runTests + + python_edlib: + name: "Build, test and possibly deploy python bindings for edlib" + strategy: + matrix: + include: + - os: ubuntu-20.04 + deploy-sdist: true + - os: macos-11 + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: bindings/python + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python3 -m pip install cibuildwheel==2.10.2 + + - name: Build edlib python module + run: | + make build + + - name: Test edlib python module + run: | + python3 test.py + + - name: Build distributables (sdist and wheels) + run: | + make sdist + + CIBW_SKIP="cp27-* pp* *-manylinux_i686" \ + CIBW_TEST_COMMAND="python3 {project}/test.py" \ + python3 -m cibuildwheel --output-dir wheelhouse + + - name: Deploy to PyPI + if: github.ref_type == 'tag' + run: | + python3 -m pip install twine + + python3 -m twine upload wheelhouse/*.whl + + if [ ${{ matrix.deploy-sdist }} == "true" ]; then + python3 -m twine upload dist/edlib-*.tar.gz + fi diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore index 2f22afa8..7ee6660c 100644 --- a/bindings/python/.gitignore +++ b/bindings/python/.gitignore @@ -1,5 +1,6 @@ build/ dist/ +wheelhouse/ *.egg-info/ edlib/ edlib.c @@ -7,4 +8,5 @@ edlib.*.so .eggs/ *.bycython.* README.rst -README.html \ No newline at end of file +README.html +.venv diff --git a/bindings/python/Makefile b/bindings/python/Makefile index 940cd5bb..2b9ff35d 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -35,6 +35,13 @@ sdist: edlib pyedlib.bycython.cpp setup.py README.rst MANIFEST.in publish: clean sdist twine upload dist/* +wheels: edlib README.rst + python -m pip install cibuildwheel==2.10.2 + + CIBW_SKIP="cp27-* pp* *-manylinux_i686" \ + CIBW_TEST_COMMAND="python3 {project}/test.py" \ + python -m cibuildwheel --output-dir wheelhouse + clean: rm -rf edlib dist edlib.egg-info build rm -f edlib.c *.bycython.* edlib.*.so diff --git a/bindings/python/README.md b/bindings/python/README.md index 5f0e1d20..55e71027 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -4,6 +4,25 @@ This README contains only development information, you can check out full README README.rst is not commited to git because it is generated from [README-tmpl.rst](./README-tmpl.rst). +## Setup + +Ensure you have the version of python you want to use installed. You can use `pyenv` to manage python versions and pick specific one, if needed. + +Let's now say that `python` is pointing to the python version you want to use. +What you will most likely want to do now is run (from this dir, bindings/python/): +```sh +python -m venv .venv +``` +to create the virtual environment if you don't have it yet, and then +```sh +source .venv/bin/activate +``` +to activate it. + +This virtual environment will ensure all the python packages are installed locally for this project, and that local python packages are used. +You will want to keep this virtual environment activated for the rest of the commands in this README. + +Actual installation of python deps (packages) is not done by the "requirements.txt" as is typical for python projects, but by the `Makefile`: read on for the details on how to build with it. ## Building