From 9d5b0fa056abe68d215c8cb5549df4281b811f89 Mon Sep 17 00:00:00 2001 From: Etienne Doumazane Date: Tue, 6 May 2025 10:48:52 +0200 Subject: [PATCH] [FEAT: build] add provisional pyproject.toml and build configuration for pip install --- ClearMap3pip.yml | 11 +++++ build_ext_custom.py | 66 ++++++++++++++++++++++++++++ pyproject.toml | 103 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 ClearMap3pip.yml create mode 100644 build_ext_custom.py create mode 100644 pyproject.toml diff --git a/ClearMap3pip.yml b/ClearMap3pip.yml new file mode 100644 index 00000000..5b54ed27 --- /dev/null +++ b/ClearMap3pip.yml @@ -0,0 +1,11 @@ +name: ClearMap3pip +channels: + - conda-forge +dependencies: + - python=3.11 + - pip + - graph-tool<=2.45 + - mkl<2024.1 +variables: + PYTHONNOUSERSITE: 1 + TMPDIR: /data/tmp diff --git a/build_ext_custom.py b/build_ext_custom.py new file mode 100644 index 00000000..fc67c8db --- /dev/null +++ b/build_ext_custom.py @@ -0,0 +1,66 @@ +# build_ext_custom.py +from setuptools.command.build_ext import build_ext as _build_ext +from setuptools.extension import Extension +from Cython.Build import cythonize +import numpy as np +import os +import subprocess +from pathlib import Path +import platform + +os_name = platform.system().lower() + +DEFAULT_COMPILE_ARGS = [] +DEFAULT_LIBRARIES = [] +DEFAULT_LINK_ARGS = [] + +if not os_name.startswith('windows'): + DEFAULT_COMPILE_ARGS += ['-w', '-O3'] + DEFAULT_LIBRARIES += ['m'] + +if os_name.startswith('linux'): + try: + out = subprocess.check_output(['gcc', '--help=common']).decode('utf-8') + if '-flarge-source-files' in out: + DEFAULT_COMPILE_ARGS += ['-flarge-source-files'] + except Exception: + pass + +USE_OPENMP = True +if os_name.startswith('darwin'): + try: + cpp_version = subprocess.check_output(['c++', '--version']).decode('ascii') + USE_OPENMP = 'g++' in cpp_version + except Exception: + USE_OPENMP = False + +extra_args = ['-fopenmp'] if USE_OPENMP else [] +if os_name.startswith('windows'): + extra_args = [arg.replace('-f', '/') for arg in extra_args] + DEFAULT_COMPILE_ARGS = [arg.replace('-m', '/') for arg in DEFAULT_COMPILE_ARGS] + DEFAULT_LINK_ARGS = [arg.replace('-m', '/') for arg in DEFAULT_LINK_ARGS] + +extra_link_args = extra_args +compile_args = DEFAULT_COMPILE_ARGS + extra_args +link_args = DEFAULT_LINK_ARGS + extra_link_args + + +extension_paths = [str(p) for p in Path('ClearMap').rglob('*.pyx') + if not any(excl in str(p) for excl in ['_Old', '_Todo', 'StatisticsPointListCode', 'flow', 'OrientationCode'])] + +extensions = [ + Extension( + name=os.path.splitext(p)[0].replace(os.sep, '.'), + sources=[p], + libraries=DEFAULT_LIBRARIES, + language='c++', + include_dirs=[np.get_include(), os.path.dirname(os.path.abspath(p))], + extra_compile_args=compile_args, + extra_link_args=link_args + ) for p in extension_paths +] + +ext_modules = cythonize(extensions, quiet=True) + +class build_ext(_build_ext): + pass diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..ab7b691e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,103 @@ +# pyproject.toml for ClearMap using setuptools and PEP 621 + +[build-system] +requires = [ + "setuptools>=61", + "wheel", + "cython", + "numpy" +] +build-backend = "setuptools.build_meta" + +[project] +name = "ClearMap" +version = "3.0.0" +description = "3D cell counting and vasculature analysis for lightsheet microscopy" +license = "MIT" +license-files = ["LICENSE", "LICENSE.txt"] +authors = [ + {name = "Christoph Kirst"}, + {name = "Sophie Skriabine"}, + {name = "Charly Rousseau"}, + {name = "Etienne Doumazane"}, + {name = "Gael Cousin"}, +] +dependencies = [ + "cython", + "ipython", + "jupyter", + "ipywidgets", + "numpy", + "scipy", + "pandas<2", + "pyarrow", + "scikit-image", + "scikit-learn", + "opencv-python", + "configobj", + "natsort", + "tqdm", + "matplotlib", + "seaborn", + "tifffile", + "pyqt5<6", + "pyqtwebengine", + "qtpy", + "pyqtgraph==0.12.*", + "pygments", + "qdarkstyle", + "vispy", + "pyvista", + "vtk", + "PyOpenGL", + "napari", + "python-igraph", + "torch<=2.2", + "xmltodict", + "psutil", + "mpld3", + "lxml<5.2", + "itk-elastix", +] +requires-python = ">=3.8" + +[project.urls] +Homepage = "https://github.com/ClearAnatomics/ClearMap" + +[project.optional-dependencies] +# Define extras if needed later + +[project.scripts] +cell_map = "ClearMap.Scripts.cell_map_new_api:main" +clearmap-utils = "ClearMap.Scripts.clearmap_utils:main" + +[project.gui-scripts] +clearmap-ui = "ClearMap.gui.run_gui:entry_point" + +[tool.setuptools] +packages = ["ClearMap"] + +[tool.setuptools.package-data] +"ClearMap.config" = ["*.cfg"] +"ClearMap.gui" = [ + "creator/*.ui", + "creator/*.qrc", + "creator/graphics_resources/*.png", + "creator/graphics_resources/*.jpg", + "creator/graphics_resources/*.svg", + "creator/icons/*.png", + "creator/icons/*.jpg", + "creator/icons/*.svg" +] + +[tool.setuptools.data-files] +"" = ["start_gui.sh"] +"ClearMap/External/elastix" = [] +"ClearMap/External/geodesic_distance" = [] +"ClearMap/Resources" = [] +"ClearMap/ImageProcessing/Skeletonization" = [] +"ClearMap/ImageProcessing/Binary" = [] +"ClearMap/ImageProcessing/machine_learning/vessel_filling/resources" = [] + +[tool.setuptools.cmdclass] +build_ext = "build_ext_custom.build_ext"