From b7ee51eb2a5d5eb14680f470d12c1b60db30e412 Mon Sep 17 00:00:00 2001 From: Chris Barnes Date: Fri, 18 Jun 2021 09:40:19 -0400 Subject: [PATCH] PEP-518 build specification (#6) * 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 --- .travis.yml | 5 +---- README.md | 10 ++++++---- pyproject.toml | 3 +++ requirements.txt | 6 ++++++ setup.py | 12 +++++------- tests/conftest.py | 9 +++++++++ 6 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 pyproject.toml create mode 100644 tests/conftest.py diff --git a/.travis.yml b/.travis.yml index 92f41e7..17bcb23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 8ace4b3..3d6e2bf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3872003 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "numpy", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 8dbecfc..6dada00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,8 @@ numpy cython + +# dev + +pytest +coveralls +pytest-cov diff --git a/setup.py b/setup.py index 87774a6..6d8e942 100644 --- a/setup.py +++ b/setup.py @@ -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() @@ -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()) @@ -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={ @@ -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", ) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..0085b8a --- /dev/null +++ b/tests/conftest.py @@ -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)]