Skip to content

Commit

Permalink
improved package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme1 committed Nov 30, 2024
1 parent 170eee4 commit db8f9a8
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ imops/src/_fast*.pyx
dist/
*.so
.vscode/
.idea/
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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/*
2 changes: 1 addition & 1 deletion _build_utils.py → imops/_build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions imops/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 2 additions & 10 deletions imops/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 9 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'},
{name = 'vovaf709', email = '[email protected]'},
{name = 'talgat', email = '[email protected]'},
{name = 'alexeybelkov', email='[email protected]'}
{ name = 'maxme1', email = '[email protected]' },
{ name = 'vovaf709', email = '[email protected]' },
{ name = 'talgat', email = '[email protected]' },
{ name = 'alexeybelkov', email = '[email protected]' }
]
classifiers = [
'Development Status :: 5 - Production/Stable',
Expand Down Expand Up @@ -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'] }
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit db8f9a8

Please sign in to comment.