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

Github Actions and PyPI Wheels #22

Open
wants to merge 23 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
15 changes: 15 additions & 0 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM quay.io/pypa/manylinux2010_x86_64
MAINTAINER Dilawar Singh <[email protected]>

ENV PATH=$PATH:/usr/local/bin

# Read PYPI_PASSWORD
ARG PYPI_PASSWORD
ENV PYPI_PASSWORD=$PYPI_PASSWORD

RUN git config --global user.name "Dilawar Singh"
RUN git config --global user.email "[email protected]"
WORKDIR /root
ADD . /root/
RUN ls -ltrh
CMD cd .ci && PYPI_PASSWORD=$PYPI_PASSWORD ./build_wheels_linux.sh
20 changes: 20 additions & 0 deletions .ci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
all : wheels

LABEL:="dilawars/manylinux2010-conan:latest"

build : ./Dockerfile ./build_wheels_linux.sh
mkdir -p $(HOME)/wheelhouse
# Generate version.
(cd .. && docker build \
--rm \
-t $(LABEL) \
-f .ci/Dockerfile \
--build-arg PYPI_PASSWORD=$(PYPI_PASSWORD) . | tee log )

wheels : ./Dockerfile ./build_wheels_linux.sh build
mkdir -p $(HOME)/wheelhouse
# Generate version.
docker run -e PYPI_PASSWORD=$(PYPI_PASSWORD) $(LABEL)

test:
docker run -it $(LABEL) bash
63 changes: 63 additions & 0 deletions .ci/build_wheels_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
set -e
set -x

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Place to store wheels.
WHEELHOUSE=${1-$HOME/wheelhouse}
echo "Path to store wheels : $WHEELHOUSE"
rm -rf $WHEELHOUSE && mkdir -p $WHEELHOUSE

PYDIR37=/opt/python/cp37-cp37m/
PYDIR38=/opt/python/cp38-cp38/
PYDIR39=/opt/python/cp39-cp39/

for PYDIR in $PYDIR39 $PYDIR38 $PYDIR37; do

export PATH=$PYDIR/bin:$PATH
PYTHON=$PYDIR/bin/python

# dependencies
$PYTHON -m pip install auditwheel pytest
(
cd ..
rm -rf build || echo "Failed to delete build"

$PYTHON -m pip install conan

rm -rf $(conan config home) || echo "Failed to remove conan old home"

PYLIB=$(ls -d $PYDIR/lib/python3.*)
PYINDIR=$(ls -d $PYDIR/include/python3.*)
$PYTHON setup.py build_ext \
--cmake-extra-args \
"-DPython3_EXECUTABLE=$PYTHON -DPython3_INCLUDE_DIR=$PYINDIR -DPython3_LIBRARY=$PYLIB"
$PYTHON setup.py bdist_wheel --skip-build -d .
$PYTHON -m auditwheel repair *.whl -w $WHEELHOUSE/

# install and test it
$PYTHON -m pip install *.whl
$PYTHON -c 'import krbalancing; print(dir(krbalancing))'
$PYTHON -c 'import krbalancing; print(krbalancing.__version__ )'

# remove the old wheel
rm -rf *.whl
ls -lh $WHEELHOUSE/*.whl
)
done

PYTHON=$PYDIR38/bin/python
$PYTHON -m pip install twine

ls -lh $WHEELHOUSE/*.whl

# If successful, upload using twine.
if [ -n "$PYPI_PASSWORD" ]; then
$PYTHON -m twine upload $WHEELHOUSE/krbalancing*.whl \
--user __token__ \
--password $PYPI_PASSWORD \
--skip-existing
else
echo "PYPI password is not set. Not uploading...."
fi
48 changes: 48 additions & 0 deletions .ci/build_wheels_osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -e
set -x

brew install cmake || echo "Failed to install cmake"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

WHEELHOUSE=$HOME/wheelhouse
rm -rf $WHEELHOUSE && mkdir -p $WHEELHOUSE


# Always prefer brew version.
PYTHON=$(which python)

if [ ! -f $PYTHON ]; then
echo "Not found $PYTHON"
exit -1
fi

$PYTHON -m pip install setuptools --upgrade
$PYTHON -m pip install wheel --upgrade
$PYTHON -m pip install delocate --upgrade
$PYTHON -m pip install twine --upgrade
$PYTHON -m pip install pytest --upgrade
$PYTHON -m pip install conan --upgrade

(
cd ..
$PYTHON setup.py bdist_wheel -d .
delocate-wheel -w $WHEELHOUSE -v *.whl
ls $WHEELHOUSE/krbalancing*.whl
(
$PYTHON --version
$PYTHON -m pip install $WHEELHOUSE/krbalancing*.whl
$PYTHON -c 'import krbalancing; print(krbalancing.__version__ )'
$PYTHON -m pip uninstall -y krbalancing
)
)

if [ -n "$PYPI_PASSWORD" ]; then
echo "Did you test the wheels?"
$PYTHON -m twine upload \
-u __token__ -p $PYPI_PASSWORD \
--skip-existing \
$WHEELHOUSE/krbalancing*.whl
fi
41 changes: 41 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Linux Build

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: "Setup Python ${{ matrix.python-version }}"
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: install
run: |
sudo apt -y update
sudo apt -y install cmake
- name: configure
run: |
cmake --version
PYTHON=$(which python)
$PYTHON -c "import sys; print(sys.version)"
$PYTHON -m pip install setuptools wheel twine
$PYTHON -m pip install conan
- name: make
run: |
python setup.py install --user
python -c "import krbalancing; print(krbalancing.__file__); print(krbalancing.__version__)"
python setup.py sdist -d .
- name: upload sdist
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m twine upload \
-u __token__ -p $PYPI_PASSWORD --skip-existing \
krbalancing*.tar.gz \
32 changes: 32 additions & 0 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: OSX Build

on:
push:
branches:
- master
tags:
- 'v**'
pull_request:
branches:
- master

jobs:
build:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: "Setup Python ${{ matrix.python-version }}"
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: build, test and deploy
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
brew install gcc
brew install libomp
cd .ci && PYPI_PASSWORD=$PYPI_PASSWORD ./build_wheels_osx.sh
24 changes: 24 additions & 0 deletions .github/workflows/wheels_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Linux Wheels

on:
push:
branches:
- master
tags:
- 'v**'
pull_request:
branches:
- master

jobs:
wheel:
runs-on: ubuntu-latest
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
steps:
- uses: actions/checkout@v2
- name: Building wheel in ManuLinux container
run: |
ls -ltR
export PYPI_PASSWORD=$PYPI_PASSWORD
cd .ci && make wheels
44 changes: 44 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Windows Build

on:
push:
branches:
- master
tags:
- 'v**'
pull_request:
branches:
- master

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.7,3.8,3.9]
steps:
- uses: actions/checkout@v2
- name: "Setup Python ${{ matrix.python-version }}"
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# Runs a set of commands using the runners shell
- name: Build using MSVS
shell: bash
run: |
mkdir build
cd build
PYTHON=$(which python)
$PYTHON -m pip install pip --upgrade
$PYTHON -m pip install numpy pytest setuptools conan
cmake -DPython3_EXECUTABLE=$PYTHON ..
cmake --build . --config Release
ctest -C Release
- name: Upload to PyPI
shell: bash
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
cd build
python -m pip install twine --upgrade
python -m twine upload -u __token__ -p "$PYPI_PASSWORD" *.whl --skip-existing || echo "Failed to upload"
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# NOTE: This should be called by setup.py file.
#

cmake_minimum_required(VERSION 3.12)
project(krbalancing)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

set(CMAKE_CXX_STANDARD 11)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
find_package(OpenMP REQUIRED)

include(${CMAKE_SOURCE_DIR}/cmake/conan.cmake)


execute_process(COMMAND ${Python3_EXECUTABLE} setup.py --version
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_PROJECT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS " project version ${CMAKE_PROJECT_VERSION}")
add_definitions(-DCMAKE_PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\")

# pybind11 config file has a bug that makes is impossible to use with
# conan_cmake_configure.
# https://github.com/conan-io/conan-center-index/pull/4445
conan_cmake_configure(REQUIRES
# pybind11/2.6.1
eigen/3.3.9
GENERATORS cmake_find_package)
# find_package(pybind11 REQUIRED)

conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conan-center
SETTINGS ${settings})

find_package(Eigen3 REQUIRED)


# hack around pybind11 bug
# https://github.com/conan-io/conan-center-index/pull/4445
conan_cmake_run(REQUIRES pybind11/2.6.1
BASIC_SETUP NO_OUTPUT_DIRS CMAKE_TARGETS
BUILD missing)


pybind11_add_module(krbalancing src/krbalancing.cpp)
target_link_libraries(krbalancing PRIVATE Eigen3::Eigen CONAN_PKG::pybind11)
target_link_libraries(krbalancing PRIVATE OpenMP::OpenMP_CXX)
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include src/krbalancing.hpp
include src/krbalancing.cpp
include setup.py
include CMakeLists.txt
include README.md
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
[![Linux Build](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/linux.yml/badge.svg)](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/linux.yml)
[![Windows Build](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/windows.yml/badge.svg)](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/windows.yml)
[![OSX Build](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/osx.yml/badge.svg)](https://github.com/dilawar/Knight-Ruiz-Matrix-balancing-algorithm/actions/workflows/osx.yml)
[![PyPI version](https://badge.fury.io/py/krbalancing.svg)](https://badge.fury.io/py/krbalancing)

# Knight-Ruiz-Matrix-balancing-algorithm

This is a c++ extension for python which computes K.R. balanced matrices. The code is a conversion of the original code (https://doi.org/10.1093/imanum/drs019) from Matlab to c++.
This is a c++ extension for python which computes K.R. balanced matrices. The
code is a conversion of the original code
(https://doi.org/10.1093/imanum/drs019) from Matlab to c++.


# Changelog

- 2021-04-13: Added github actions to create wheel for Linux, Windows and OSX. Few small tweaks for MSVS build.
Loading