Skip to content

Commit

Permalink
PEP-518 build specification (#6)
Browse files Browse the repository at this point in the history
* PEP-518 build system specification

This allows waterz to specify its own build-time dependencies, which
means it can be installed directly using pip without any of those
dependencies already installed.

This is useful for downstream users for whom waterz is one of many
dependencies; they can just stick it in their requirements.txt file and
not have to worry about pre-installing dependencies.

* Allow tests to run against installed version

Pytest, by default, mangles sys.path to test against the local version.
This doesn't work with libraries which need to be compiled.
So, this explicitly removes the local version from the path.

* Replace __builtins__ with builtins

__builtins__ is a dict, not a module. __builtin__ was the module to use
in py2. builtins is the module to use in py3.

* Decouple requirements.txt and install_requires

requirements.txt is designed for setting up a reproducible development environment;
install_requires for flexible, minimal runtime dependencies.

* Use pip install in readme, travis etc.

* fix typo in pyproject

* add required python version
  • Loading branch information
clbarnes authored Jun 18, 2021
1 parent d771387 commit b7ee51e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ install:
- sudo apt update
- sudo apt install libboost-dev
- pip install -r requirements.txt
- python setup.py install
- pip install pytest
- pip install coveralls
- pip install pytest-cov
- pip install .

script:
- pytest --cov-append --cov=./waterz ./tests --verbose
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ Based on the watershed implementation of [Aleksandar Zlateski](https://bitbucket
# Installation

Install c++ dependencies:

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

Install from pipy
Install from PyPI

```
pip install waterz
```

install manually
install from local version

```
pip install -r requirements.txt
python setup.py install
pip install .
```

# Usage
Expand Down
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"
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
numpy
cython

# dev

pytest
coveralls
pytest-cov
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
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, "requirements.txt")) as f:
requirements = f.read().splitlines()
requirements = [l for l in requirements if not l.startswith('#')]


with open(os.path.join(PACKAGE_DIR, "README.md"), "r") as fh:
long_description = fh.read()
Expand All @@ -24,7 +21,7 @@ class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
builtins.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())

Expand Down Expand Up @@ -59,7 +56,7 @@ def finalize_options(self):
license='MIT',
cmdclass={'build_ext': build_ext},
setup_requires=['numpy'],
install_requires=requirements,
install_requires=['numpy', 'cython'],
tests_require=['pytest'],
packages=find_packages(),
package_data={
Expand All @@ -73,5 +70,6 @@ def finalize_options(self):
"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)]

0 comments on commit b7ee51e

Please sign in to comment.