From 5f7c4bcb61d4c80c94b16c4e51ade1fbbc8c7238 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 7 Jan 2020 14:33:37 +0000 Subject: [PATCH 1/5] Updated infrastructure to use pyproject.toml, tox, and Azure Pipelines --- .gitignore | 4 ++++ .travis.yml | 31 ------------------------ MANIFEST.in | 1 + appveyor.yml | 41 ------------------------------- azure-pipelines.yml | 37 ++++++++++++++++++++++++++++ fast_histogram/__init__.py | 3 +-- pyproject.toml | 6 +++++ setup.cfg | 23 ++++++++++++++++++ setup.py | 49 +++++++------------------------------- tox.ini | 39 ++++++++++++++++++++++++++++++ 10 files changed, 119 insertions(+), 115 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml create mode 100644 azure-pipelines.yml create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 41f9e35..b18c8c1 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,7 @@ htmlcov # PyCharm .idea + +.tox +.tmp +fast_histogram/version.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 47597e4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: c - -sudo: false - -os: - - linux - - osx - -env: - global: - - CONDA_DEPENDENCIES="numpy pytest nomkl" - - PIP_DEPENDENCIES="hypothesis[numpy]" - matrix: - - PYTHON_VERSION=2.7 NUMPY_VERSION=1.10 - - PYTHON_VERSION=2.7 NUMPY_VERSION=1.11 - - PYTHON_VERSION=3.5 NUMPY_VERSION=1.12 - - PYTHON_VERSION=3.6 NUMPY_VERSION=1.13 - - PYTHON_VERSION=3.6 NUMPY_VERSION=1.14 - - PYTHON_VERSION=3.7 NUMPY_VERSION=1.15 - - # Do a build without Numpy to make sure it's automatically installed - - PYTHON_VERSION=3.6 CONDA_DEPENDENCIES="pytest" - -install: - - git clone git://github.com/astropy/ci-helpers.git - - source ci-helpers/travis/setup_conda.sh - -script: - - LC_ALL=C python setup.py check --restructuredtext - - python setup.py build_ext --inplace - - pytest fast_histogram -p no:warnings --hypothesis-show-statistics diff --git a/MANIFEST.in b/MANIFEST.in index a3db2a9..abc6afb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include LICENSE include README.rst include CHANGES.rst +include pyproject.toml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index dc4bd1b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,41 +0,0 @@ -environment: - - global: - PYTHON: "C:\\conda" - MINICONDA_VERSION: "latest" - CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci-helpers\\appveyor\\windows_sdk.cmd" - PYTHON_ARCH: "64" # needs to be set for CMD_IN_ENV to succeed. If a mix - # of 32 bit and 64 bit builds are needed, move this - # to the matrix section. - - CONDA_DEPENDENCIES: "cython numpy pytest" - PIP_DEPENDENCIES: "hypothesis[numpy]" - - matrix: - - PYTHON_VERSION: "2.7" - NUMPY_VERSION: "1.10" - - PYTHON_VERSION: "2.7" - NUMPY_VERSION: "1.11" - - PYTHON_VERSION: "3.5" - NUMPY_VERSION: "1.12" - - PYTHON_VERSION: "3.6" - NUMPY_VERSION: "1.13" - - PYTHON_VERSION: "3.6" - NUMPY_VERSION: "1.14" - - PYTHON_VERSION: "3.7" - NUMPY_VERSION: "1.15" - -platform: - -x64 - -install: - - "git clone git://github.com/astropy/ci-helpers.git" - - "powershell ci-helpers/appveyor/install-miniconda.ps1" - - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - - "activate test" - -build: false - -test_script: - - "%CMD_IN_ENV% python setup.py build_ext --inplace" - - "%CMD_IN_ENV% pytest fast_histogram -p no:warnings --hypothesis-show-statistics" diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..3caf296 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,37 @@ +resources: + repositories: + - repository: OpenAstronomy + type: github + endpoint: astrofrog + name: OpenAstronomy/azure-pipelines-templates + ref: master + +jobs: + +- template: run-tox-env.yml@OpenAstronomy + parameters: + + coverage: codecov + + envs: + + - linux: py36-test-numpy113 + - linux: py36-test-numpy114 + - linux: py36-test-numpy115 + - linux: py37-test-numpy116 + - linux: py37-test-numpy117 + - linux: py38-test-numpy118 + + - macos: py36-test-numpy113 + - macos: py36-test-numpy114 + - macos: py36-test-numpy115 + - macos: py37-test-numpy116 + - macos: py37-test-numpy117 + - macos: py38-test-numpy118 + + - windows: py36-test-numpy113 + - windows: py36-test-numpy114 + - windows: py36-test-numpy115 + - windows: py37-test-numpy116 + - windows: py37-test-numpy117 + - windows: py38-test-numpy118 diff --git a/fast_histogram/__init__.py b/fast_histogram/__init__.py index a7c72e0..2274b92 100644 --- a/fast_histogram/__init__.py +++ b/fast_histogram/__init__.py @@ -1,3 +1,2 @@ from .histogram import * - -__version__ = "0.8.dev0" +from .version import version as __version__ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..03b6c62 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = ["setuptools", + "setuptools_scm", + "wheel", + "oldest-supported-numpy"] +build-backend = 'setuptools.build_meta' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..1440391 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,23 @@ +[metadata] +name = fast-histogram +url = https://github.com/astrofrog/fast-histogram +author = Thomas Robitaille +author_email = thomas.robitaille@gmail.com +license = BSD +description = Fast simple 1D and 2D histograms +long_description = file: README.rst + +[options] +zip_safe = False +packages = find: +setup_requires = + setuptools_scm +install_requires = + numpy +python_requires = >=3.6 + +[options.extras_require] +test = + pytest + pytest-cov + hypothesis[numpy]<4 diff --git a/setup.py b/setup.py index 8eb2c96..80a6869 100644 --- a/setup.py +++ b/setup.py @@ -1,47 +1,14 @@ +#!/usr/bin/env python + import os -import io import sys +import numpy + from setuptools import setup from setuptools.extension import Extension -from setuptools.command.build_ext import build_ext - - -class build_ext_with_numpy(build_ext): - def run(self): - import numpy - self.include_dirs.append(numpy.get_include()) - build_ext.run(self) - - -extensions = [Extension("fast_histogram._histogram_core", - [os.path.join('fast_histogram', '_histogram_core.c')])] - -with io.open('README.rst', encoding='utf-8') as f: - LONG_DESCRIPTION = f.read() - -try: - import numpy -except ImportError: - # We include an upper limit to the version because setup_requires is - # honored by easy_install not pip, and the former doesn't ignore pre- - # releases. It's not an issue if the package is built against 1.15 and - # then 1.16 gets installed after, but it still makes sense to update the - # upper limit whenever a new version of Numpy is released. - setup_requires = ['numpy<1.16'] -else: - setup_requires = [] -setup(name='fast-histogram', - version='0.8.dev0', - description='Fast simple 1D and 2D histograms', - long_description=LONG_DESCRIPTION, - setup_requires=setup_requires , - install_requires=['numpy'], - author='Thomas Robitaille', - author_email='thomas.robitaille@gmail.com', - license='BSD', - url='https://github.com/astrofrog/fast-histogram', - packages=['fast_histogram', 'fast_histogram.tests'], - ext_modules=extensions, - cmdclass={'build_ext': build_ext_with_numpy}) +setup(use_scm_version={'write_to': os.path.join('fast_histogram', 'version.py')}, + ext_modules=[Extension("fast_histogram._histogram_core", + [os.path.join('fast_histogram', '_histogram_core.c')], + include_dirs=[numpy.get_include()])]) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c39d3f5 --- /dev/null +++ b/tox.ini @@ -0,0 +1,39 @@ +[tox] +envlist = + py{27, 35, 36,37,38}-test + style +requires = + setuptools >= 30.3.0 + pip >= 19.3.1 +isolated_build = true + +[testenv] +changedir = + test: .tmp/{envname} + build_docs: docs +description = + test: run tests with pytest + build_docs: invoke sphinx-build to build the HTML docs + all: run tests with all optional dependencies + dev: run tests with numpy and astropy dev versions +deps = + numpy110: numpy==1.10.* + numpy111: numpy==1.11.* + numpy112: numpy==1.12.* + numpy113: numpy==1.13.* + numpy114: numpy==1.14.* + numpy115: numpy==1.15.* + numpy116: numpy==1.16.* + numpy117: numpy==1.17.* + numpy118: numpy==1.18.* +extras = + test +commands = + pip freeze + pytest --pyargs fast_histogram {posargs} + +[testenv:style] +skip_install = true +description = invoke style checks on package code +deps = flake8 +commands = flake8 fast_histogram From 7cdbc7e3bc6a9929b0989a3af6c484ea025159e4 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 7 Jan 2020 15:25:37 +0000 Subject: [PATCH 2/5] Updated tests to fix compatibility with latest version of hypothesis --- CHANGES.rst | 3 +- fast_histogram/tests/test_histogram.py | 63 +++++++++++++++++--------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6792fd5..99a5b58 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,8 @@ 0.8 (unreleased) ---------------- -- No changes yet. +- Fixed compatibility of test suite with latest version of the + hypothesis package. [#40] 0.7 (2019-01-09) ---------------- diff --git a/fast_histogram/tests/test_histogram.py b/fast_histogram/tests/test_histogram.py index 342d273..9a7a48f 100644 --- a/fast_histogram/tests/test_histogram.py +++ b/fast_histogram/tests/test_histogram.py @@ -2,7 +2,7 @@ import pytest -from hypothesis import given, settings, example, assume +from hypothesis import given, settings, assume from hypothesis import strategies as st from hypothesis.extra.numpy import arrays @@ -14,27 +14,34 @@ # comparing to Numpy) test cases. -@given(size=st.integers(0, 100), +@given(values=arrays(dtype='f4', 'f8', '= xmin) + # FIXME: for now use < since that's what our algorithm does + inside = (x < xmax) & (x >= xmin) if weights: assume(np.allclose(np.sum(w[inside]), np.sum(reference))) else: @@ -56,13 +64,16 @@ def test_1d_compare_with_numpy(size, nx, xmin, xmax, weights, dtype): # for 1D arrays. Since this is a summation variable it makes sense to # return 64-bit, so rather than changing the behavior of histogram1d, we # cast to 32-bit float here. - if 'f4' in dtype: - fast = fast.astype(np.float32) + if x.dtype.kind == 'f' and x.dtype.itemsize == 4: + rtol = 1e-7 + else: + rtol = 1e-14 - np.testing.assert_equal(fast, reference) + np.testing.assert_allclose(fast, reference, rtol=rtol) -@given(size=st.integers(0, 100), +@given(values=arrays(dtype='f4', 'f8', '= xmin) & (y <= ymax) & (y >= ymin) + # bug report https://github.com/numpy/numpy/issues/9435. + # FIXME: for now use < since that's what our algorithm does + inside = (x < xmax) & (x >= xmin) & (y < ymax) & (y >= ymin) if weights: assume(np.allclose(np.sum(w[inside]), np.sum(reference))) else: @@ -104,7 +118,12 @@ def test_2d_compare_with_numpy(size, nx, xmin, xmax, ny, ymin, ymax, weights, dt fast = histogram2d(x, y, bins=(nx, ny), weights=w, range=((xmin, xmax), (ymin, ymax))) - np.testing.assert_equal(fast, reference) + if x.dtype.kind == 'f' and x.dtype.itemsize == 4: + rtol = 1e-7 + else: + rtol = 1e-14 + + np.testing.assert_allclose(fast, reference, rtol=rtol) def test_nd_arrays(): From 7e9850bda244c1ab2b65d887d7532d3ccdb2f154 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 7 Jan 2020 15:26:47 +0000 Subject: [PATCH 3/5] Don't pin hypothesis version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 1440391..b56915f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,4 +20,4 @@ python_requires = >=3.6 test = pytest pytest-cov - hypothesis[numpy]<4 + hypothesis[numpy] From c6dfa33faf5c5068e61048d7073fa99bad8a51a3 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 7 Jan 2020 15:35:18 +0000 Subject: [PATCH 4/5] Reduce max_examples --- fast_histogram/tests/test_histogram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast_histogram/tests/test_histogram.py b/fast_histogram/tests/test_histogram.py index 9a7a48f..f4c86a6 100644 --- a/fast_histogram/tests/test_histogram.py +++ b/fast_histogram/tests/test_histogram.py @@ -21,7 +21,7 @@ xmax=st.floats(-1e10, 1e10), weights=st.booleans(), dtype=st.sampled_from(['>f4', 'f8', 'f4', 'f8', ' Date: Tue, 7 Jan 2020 15:38:04 +0000 Subject: [PATCH 5/5] Run 32-bit tests on Azure --- .circleci/config.yml | 75 -------------------------------------------- azure-pipelines.yml | 7 +++++ 2 files changed, 7 insertions(+), 75 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index d7380a8..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,75 +0,0 @@ -version: 2 - -jobs: - - # Run the tests with 32-bit Python - 32bit: - docker: - - image: quay.io/pypa/manylinux1_i686 - steps: - - checkout - - run: - name: Install dependencies - command: /opt/python/cp36-cp36m/bin/pip install numpy pytest hypothesis[numpy] - - run: - name: Build extension - command: /opt/python/cp36-cp36m/bin/python setup.py build_ext --inplace - - run: - name: Run tests - command: /opt/python/cp36-cp36m/bin/pytest fast_histogram -p no:warnings --hypothesis-show-statistics - - # The following tests are to make sure that we deal correctly with numpy - # as a build requirement. - numpy: - docker: - - image: ubuntu:16.04 - steps: - - checkout - - run: - name: Install Python - command: | - apt-get update - apt-get install -y python3 python3-dev python3-pip python3-wheel - - run: - name: Install virtualenv - command: pip3 install virtualenv - - run: - name: Make temporary directory for testing imports - command: mkdir tmp - - run: - name: Test default install - command: | - virtualenv default - source default/bin/activate - pip3 install . - cd tmp - python3 -c 'import fast_histogram' - cd .. - - run: - name: Test install with pre-existing Numpy - command: | - virtualenv pre - source pre/bin/activate - pip3 install numpy==1.12.1 - pip3 install . - cd tmp - python3 -c 'import fast_histogram' - cd .. - # The following doesn't work, but could work one day when we implement - # pyproject.toml with the oldest numpy version for each Python version. - # - run: - # name: Test install with pinned Numpy - # command: | - # virtualenv pinned - # source pinned/bin/activate - # pip3 install . numpy==1.12.1 - # cd tmp - # python3 -c 'import fast_histogram' - # cd .. - -workflows: - version: 2 - tests_and_docs: - jobs: - - 32bit - - numpy diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3caf296..db05022 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,6 +15,13 @@ jobs: envs: + - linux32: py36-test-numpy113 + - linux32: py36-test-numpy114 + - linux32: py36-test-numpy115 + - linux32: py37-test-numpy116 + - linux32: py37-test-numpy117 + # - linux32: py38-test-numpy118 + - linux: py36-test-numpy113 - linux: py36-test-numpy114 - linux: py36-test-numpy115