From db8f9a864049dece2758fe9fc3ea6bbddf63030a Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 30 Nov 2024 11:19:19 +0100 Subject: [PATCH] improved package structure --- .github/workflows/lint.yml | 27 ++++++++++++++++++++++++ .github/workflows/tests.yml | 11 ---------- .gitignore | 1 + MANIFEST.in | 2 +- _build_utils.py => imops/_build_utils.py | 2 +- imops/compat.py | 11 ++++++++-- imops/morphology.py | 12 ++--------- pyproject.toml | 20 ++++++++---------- setup.py | 9 ++++---- 9 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/lint.yml rename _build_utils.py => imops/_build_utils.py (98%) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..7b50bf31 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lint + +on: [ pull_request ] + +env: + MODULE_NAME: imops + +jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Check python code style + run: | + pip install -r requirements-linters.txt + flake8 . + isort --check . + black --check . + - name: Check Cython code style + run: | + pip install cython-lint + cython-lint imops/src diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 627ada08..634a26d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,17 +43,6 @@ jobs: echo $MODULE_PARENT echo "MODULE_PARENT=$(echo $MODULE_PARENT)" >> $GITHUB_ENV - - name: Check python code style - run: | - pip install -r requirements-linters.txt - flake8 . - isort --check . - black --check . - - name: Check Cython code style - run: | - pip install cython-lint - cython-lint imops/src - - name: Test with pytest run: | pytest tests -m "not nonumba" --junitxml=reports/junit-${{ matrix.python-version }}.xml --cov="$MODULE_PARENT/$MODULE_NAME" --cov-report=xml --cov-branch diff --git a/.gitignore b/.gitignore index 87e1733b..8d93aa0a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ imops/src/_fast*.pyx dist/ *.so .vscode/ +.idea/ diff --git a/MANIFEST.in b/MANIFEST.in index d25ac5dc..c77969d0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ include *.md include requirements.txt include pyproject.toml -include _build_utils.py recursive-include imops *.py recursive-include imops/cpp *.h *.hpp *.cpp +exclude tests/* diff --git a/_build_utils.py b/imops/_build_utils.py similarity index 98% rename from _build_utils.py rename to imops/_build_utils.py index 59292e31..12c61668 100644 --- a/_build_utils.py +++ b/imops/_build_utils.py @@ -66,7 +66,7 @@ def get_ext_modules(): modules = ['backprojection', 'measure', 'morphology', 'numeric', 'radon', 'zoom', 'convex_hull'] modules_to_link_against_numpy_core_math_lib = ['numeric'] - src_dir = Path(__file__).parent / name / 'src' + src_dir = Path(__file__).parent / 'src' for module in modules: # Cython extension and .pyx source file names must be the same to compile # https://stackoverflow.com/questions/8024805/cython-compiled-c-extension-importerror-dynamic-module-does-not-define-init-fu diff --git a/imops/compat.py b/imops/compat.py index 07a8a1df..0d0b2eed 100644 --- a/imops/compat.py +++ b/imops/compat.py @@ -9,6 +9,13 @@ from numpy import VisibleDeprecationWarning try: - from scipy.ndimage._morphology import _ni_support + from scipy.ndimage._morphology._ni_support import _normalize_sequence as normalize_sequence except ImportError: - from scipy.ndimage.morphology import _ni_support + from scipy.ndimage.morphology._ni_support import _normalize_sequence as normalize_sequence + +try: + from scipy.spatial import QhullError +except ImportError: + from scipy.spatial.qhull import QhullError + +from scipy.ndimage._nd_image import euclidean_feature_transform # noqa diff --git a/imops/morphology.py b/imops/morphology.py index 0be6a6c1..39d45a13 100644 --- a/imops/morphology.py +++ b/imops/morphology.py @@ -4,15 +4,7 @@ import numpy as np from edt import edt from scipy.ndimage import distance_transform_edt as scipy_distance_transform_edt, generate_binary_structure -from scipy.ndimage._nd_image import euclidean_feature_transform from scipy.spatial import ConvexHull - - -try: - from scipy.spatial import QhullError -except ImportError: - from scipy.spatial.qhull import QhullError # Old scipy has another structure - from skimage.morphology import ( binary_closing as scipy_binary_closing, binary_dilation as scipy_binary_dilation, @@ -23,7 +15,7 @@ from .backend import BackendLike, Cython, Scipy, resolve_backend from .box import add_margin, box_to_shape, mask_to_box, shape_to_box -from .compat import _ni_support +from .compat import QhullError, euclidean_feature_transform, normalize_sequence from .crop import crop_to_box from .pad import restore_crop from .src._convex_hull import _grid_points_in_poly, _left_right_bounds, _offset_unique @@ -499,7 +491,7 @@ def distance_transform_edt( if image.dtype != bool: image = np.atleast_1d(np.where(image, 1, 0)) if sampling is not None: - sampling = _ni_support._normalize_sequence(sampling, image.ndim) + sampling = normalize_sequence(sampling, image.ndim) sampling = np.asarray(sampling, dtype=np.float64) if not sampling.flags.contiguous: sampling = sampling.copy() diff --git a/pyproject.toml b/pyproject.toml index eed6e582..2f7a669b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,17 +4,17 @@ build-backend = 'setuptools.build_meta' [project] name = 'imops' -dynamic = ['version'] +dynamic = ['dependencies', 'version'] description = 'Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines' readme = 'README.md' requires-python = '>=3.7' license = { file = 'LICENSE' } keywords = ['image processing', 'fast', 'ndarray', 'data pipelines'] authors = [ - {name = 'maxme1', email = 'max@aumi.ai'}, - {name = 'vovaf709', email = 'vovaf709@yandex.ru'}, - {name = 'talgat', email = 'saparov2130@gmail.com'}, - {name = 'alexeybelkov', email='fpmbelkov@gmail.com'} + { name = 'maxme1', email = 'max@aumi.ai' }, + { name = 'vovaf709', email = 'vovaf709@yandex.ru' }, + { name = 'talgat', email = 'saparov2130@gmail.com' }, + { name = 'alexeybelkov', email = 'fpmbelkov@gmail.com' } ] classifiers = [ 'Development Status :: 5 - Production/Stable', @@ -51,23 +51,21 @@ line_length = 120 lines_after_imports = 2 profile = 'black' combine_as_imports = true -skip_glob=['.asv/*', '.eggs/*'] +skip_glob = ['.asv/*', '.eggs/*'] [tool.cython-lint] max-line-length = 120 -[tool.setuptools] -py-modules = ['_build_utils'] - [tool.setuptools.cmdclass] -build_py = "_build_utils.PyprojectBuild" +build_py = "imops._build_utils.PyprojectBuild" [tool.setuptools.packages.find] include = ['imops'] +exclude = ['tests'] [tool.setuptools.package-data] imops = ['py.typed'] [tool.setuptools.dynamic] -version = {attr = 'imops.__version__.__version__'} +version = { attr = 'imops.__version__.__version__' } dependencies = { file = ['requirements.txt'] } diff --git a/setup.py b/setup.py index e6e3c50e..a2fee0c8 100644 --- a/setup.py +++ b/setup.py @@ -23,13 +23,14 @@ long_description = file.read() version = runpy.run_path(root / name / '__version__.py')['__version__'] -scope = {'__file__': __file__} -exec((root / '_build_utils.py').read_text(), scope) +build_utils = root / name / '_build_utils.py' +scope = {'__file__': str(build_utils)} +exec(build_utils.read_text(), scope) ext_modules = scope['get_ext_modules']() setup( name=name, - packages=find_packages(include=(name,)), + packages=find_packages(include=(name,), exclude=('tests', 'tests.*')), include_package_data=True, version=version, description='Efficient parallelizable algorithms for multidimensional arrays to speed up your data pipelines', @@ -51,8 +52,8 @@ extras_require={'numba': ['numba'], 'all': ['numba']}, setup_requires=[ 'setuptools<69.0.0', - 'Cython>=3.0.0,<4.0.0', 'numpy<3.0.0', + 'Cython>=3.0.0,<4.0.0', 'pybind11', ], ext_modules=ext_modules,