Skip to content

Commit

Permalink
Merge pull request #11 from jingpengw/master
Browse files Browse the repository at this point in the history
release the package to pypi
  • Loading branch information
funkey authored Jun 18, 2021
2 parents 8ccd0b3 + b7ee51e commit a14f1a2
Show file tree
Hide file tree
Showing 12 changed files with 8,676 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ build
*checkpoints*
*.nfs
*.sw[pmno]
waterz/evaluate.cpp
jwu/
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
language: python

python:
- '3.7'
- '3.8'
- '3.9'

services:
- docker

env:
- DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64 PLAT=manylinux1_x86_64
- DOCKER_IMAGE=quay.io/pypa/manylinux1_i686 PRE_CMD=linux32 PLAT=manylinux1_i686
- DOCKER_IMAGE=quay.io/pypa/manylinux2010_x86_64 PLAT=manylinux2010_x86_64

before_install:
- docker pull $DOCKER_IMAGE

install:
- sudo find /usr -name '*.pyc' -delete
- sudo apt update
- sudo apt install libboost-dev
- pip install -r requirements.txt
- pip install .

script:
- pytest --cov-append --cov=./waterz ./tests --verbose

after_success:
- coveralls
- chmod +x ./travis/build-wheels.sh
- docker run --rm -e PLAT=$PLAT -v `pwd`:/io $DOCKER_IMAGE $PRE_CMD /io/travis/build-wheels.sh
- ls wheelhouse/
- |
if [[ $TRAVIS_TAG ]]; then
echo "upload wheel file."
python -m pip install twine
python -m twine upload wheelhouse/waterz*.whl
fi
notifications:
email: false
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
include requirements.txt
include README.md

recursive-include waterz *.hpp
recursive-include waterz *.pyx
recursive-include waterz *.h
recursive-include waterz *.h

include waterz/frontend_agglomerate.cpp
include waterz/evaluate.cpp
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[![Build Status](https://travis-ci.org/jingpengw/waterz.svg?branch=master)](https://travis-ci.org/jingpengw/waterz)
[![PyPI version](https://badge.fury.io/py/waterz.svg)](https://badge.fury.io/py/waterz)

<!--
the coerage is not working on c++ code, so the coverage is 0 now!
[![Coverage Status](https://coveralls.io/repos/github/jingpengw/waterz/badge.svg?branch=master)](https://coveralls.io/github/jingpengw/waterz?branch=master)
-->

# waterz

Pronounced *water-zed*. A simple watershed and region agglomeration library for
Expand All @@ -7,9 +15,23 @@ Based on the watershed implementation of [Aleksandar Zlateski](https://bitbucket

# Installation

`python setup.py install`
Install c++ dependencies:

```
sudo apt install libboost-dev
```

Install from PyPI

```
pip install waterz
```

install from local version

Requires `numpy` and `cython`.
```
pip install .
```

# Usage

Expand All @@ -24,3 +46,14 @@ thresholds = [0, 100, 200]
segmentations = waterz.agglomerate(affinities, thresholds)
```

# Development
## Release to pypi
We use travis to create release

upgrade the version number in the `setup.py` file, then
```
git tag v0.9.5
git push origin v0.9.5
```
the travis build system will get a `TRAVIS_TAG` variable, and triger the `twine upload` command.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "numpy", "wheel"]
build-backend = "setuptools.build_meta"
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
numpy
cython

# dev

pytest
coveralls
pytest-cov
82 changes: 55 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
from setuptools import setup
from setuptools import setup, find_packages
from setuptools.extension import Extension
from Cython.Build import cythonize
import numpy
from setuptools.command.build_ext import build_ext as _build_ext
# from Cython.Build import cythonize
import os
import builtins

VERSION = '0.9.5'

PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))


with open(os.path.join(PACKAGE_DIR, "README.md"), "r") as fh:
long_description = fh.read()


class build_ext(_build_ext):
"""We assume no numpy at the begining
https://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py
"""
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
builtins.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())


source_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'waterz')
include_dirs = [
source_dir,
os.path.join(source_dir, 'backend'),
# os.path.dirname(get_python_inc()),
numpy.get_include(),
# numpy.get_include(),
]
extensions = [
Extension(
'waterz.evaluate',
sources=['waterz/evaluate.pyx', 'waterz/frontend_evaluate.cpp'],
sources=['waterz/evaluate.cpp', 'waterz/frontend_evaluate.cpp'],
include_dirs=include_dirs,
language='c++',
extra_link_args=['-std=c++11'],
extra_compile_args=['-std=c++11', '-w'])
]


setup(
name='waterz',
version='0.8',
description='Simple watershed and agglomeration for affinity graphs.',
url='https://github.com/funkey/waterz',
author='Jan Funke',
author_email='[email protected]',
license='MIT',
requires=['cython','numpy'],
packages=['waterz'],
package_data={
'': [
'waterz/*.h',
'waterz/*.hpp',
'waterz/*.cpp',
'waterz/*.cpp',
'waterz/*.pyx',
'waterz/backend/*.hpp',
]
},
include_package_data=True,
zip_safe=False,
ext_modules=cythonize(extensions)
name='waterz',
version=VERSION,
description='Simple watershed and agglomeration for affinity graphs.',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/funkey/waterz',
author='Jan Funke, Jingpeng Wu',
author_email='[email protected]',
license='MIT',
cmdclass={'build_ext': build_ext},
setup_requires=['numpy'],
install_requires=['numpy', 'cython'],
tests_require=['pytest'],
packages=find_packages(),
package_data={
'': ['*.pyx', '*.hpp', '*.cpp', '*.h', '*.py', 'backend/*.hpp'],
'backend': ['*.hpp']
},
zip_safe=False,
ext_modules=extensions,
classifiers=[
"Programming Language :: Python :: 3",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
requires_python=">=3.6, <4",
)
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
from pathlib import Path

# waterz is not locally importable;
# this snippet forces the tests to use the installed version.
# See here for more details:
# https://stackoverflow.com/questions/67176036/how-to-prevent-pytest-using-local-module
project_dir = str(Path(__file__).resolve().parent.parent)
sys.path = [p for p in sys.path if not p.startswith(project_dir)]
27 changes: 27 additions & 0 deletions tests/test_evaluate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
import waterz as wz
from math import isclose


def test_evaluate():
# make the random value consistent with different runs
np.random.seed(0)

seg = np.random.randint(500, size=(3, 3, 3), dtype=np.uint64)
scores = wz.evaluate(seg, seg)
assert scores['voi_split'] == 0.0
assert scores['voi_merge'] == 0.0
assert scores['rand_split'] == 1.0
assert scores['rand_merge'] == 1.0

seg2 = np.random.randint(500, size=(3,3,3), dtype=np.uint64)
scores = wz.evaluate(seg, seg2)
#print('scores: ', scores)
# Note that these values are from the first run
# I have not double checked that this is correct or not.
# This assertion only make sure that future changes of
# code will not change the result of the evaluation
assert isclose(scores['rand_split'], 0.8181818181818182)
assert isclose(scores['rand_merge'], 0.8709677419354839)
assert isclose(scores['voi_split'], 0.22222222222222232)
assert isclose(scores['voi_merge'], 0.14814814814814792)
22 changes: 22 additions & 0 deletions travis/build-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e -x

# Install a system package required by our library
#yum check-update
yum install -y boost-devel

# Compile wheels
for PYBIN in /opt/python/*/bin; do
"${PYBIN}/pip" install -r /io/requirements.txt
"${PYBIN}/pip" wheel /io/ -w wheelhouse/
done

# Bundle external shared libraries into the wheels
for whl in wheelhouse/*.whl; do
auditwheel repair "$whl" --plat $PLAT -w /io/wheelhouse/
done

# Install packages and test
for PYBIN in /opt/python/*/bin/; do
"${PYBIN}/pip" install waterz --no-index -f /io/wheelhouse
done
Loading

0 comments on commit a14f1a2

Please sign in to comment.