diff --git a/.gitignore b/.gitignore index 1800114..fc868db 100644 --- a/.gitignore +++ b/.gitignore @@ -171,4 +171,21 @@ cython_debug/ .ruff_cache/ # PyPI configuration file -.pypirc \ No newline at end of file +.pypirc + +# CMake stuff +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +CMakeUserPresets.json + +# VSCode/ium stuff +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..829d820 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.17.2...3.29) +project(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran) + +find_package(Python COMPONENTS Development.Module NumPy REQUIRED) + +# F2PY include path +execute_process( + COMMAND "${Python_EXECUTABLE}" -c + "import numpy.f2py; print(numpy.f2py.get_include())" + OUTPUT_VARIABLE F2PY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + +# fortranobject object library +add_library(fortranobject OBJECT "${F2PY_INCLUDE_DIR}/fortranobject.c") +target_link_libraries(fortranobject PUBLIC Python::NumPy) +target_include_directories(fortranobject PUBLIC "${F2PY_INCLUDE_DIR}") +set_property(TARGET fortranobject PROPERTY POSITION_INDEPENDENT_CODE ON) + +# Auto-generate wrappers +add_custom_command( + OUTPUT bicubicmodule.c bicubic-f2pywrappers.f + DEPENDS lensit/bicubic/bicubic.f90 + COMMAND "${Python_EXECUTABLE}" -m numpy.f2py + "${CMAKE_CURRENT_SOURCE_DIR}/lensit/bicubic/bicubic.f90" + -m bicubic --lower + VERBATIM) + +# Compile extension in the right namespace +python_add_library( + bicubic MODULE + "${CMAKE_CURRENT_BINARY_DIR}/bicubicmodule.c" + "${CMAKE_CURRENT_BINARY_DIR}/bicubic-f2pywrappers.f" + "${CMAKE_CURRENT_SOURCE_DIR}/lensit/bicubic/bicubic.f90" + WITH_SOABI) + +target_link_libraries(bicubic PRIVATE fortranobject) + + +# Automatically install to correct package dir +install(TARGETS bicubic + LIBRARY DESTINATION lensit/bicubic) + +message(STATUS "Installing to: ${CMAKE_INSTALL_PREFIX}") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..99fcff6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[build-system] +requires = [ + "scikit-build-core", + "cmake>=3.18", + "ninja", + "numpy" +] +build-backend = "scikit_build_core.build" + +[project] +name = "lensit" +version = "0.0.0" +dependencies = [ + "numpy", + "scipy", + "pyfftw", + "finufft", + "six" +] +authors = [ + {name = "Julien Carron", email="to.jcarron@gmail.com"} +] +description = "CMB lensing flat-sky quadratic and iterative estimation tools" +readme = "README.md" +license = "MIT-0" +license-files = ["LICENSE.txt"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering :: Astronomy", + "Programming Language :: Python :: 3", +] + +[project.optional-dependencies] +dev = ["pytest"] +extra = ["mpi4py"] + +[project.urls] +Documentation = "https://lensit.readthedocs.io/" +Repository = "https://github.com/carronj/LensIt" +Issues = "https://github.com/carronj/LensIt/issues" + + +[tool.scikit-build] +wheel.packages = ["lensit"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index f503579..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy<=1.22 -scipy -pyfftw -finufft -setuptools<=64 diff --git a/setup.py b/setup.py deleted file mode 100644 index 428176e..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -import setuptools -from numpy.distutils.core import setup -from numpy.distutils.misc_util import Configuration - -with open("README.md", "r") as fh: - long_description = fh.read() - - -def configuration(parent_package='', top_path=''): - config = Configuration('', parent_package, top_path) - config.add_extension('lensit.bicubic.bicubic', ['lensit/bicubic/bicubic.f90']) - return config - -setup( - name='lensit', - packages=['lensit', 'lensit.qcinv', 'lensit.ffs_covs', 'lensit.ffs_deflect', - 'lensit.pbs', 'lensit.misc', 'lensit.pseudocls', 'lensit.ffs_iterators'], - data_files=[('lensit/data/cls', ['lensit/data/cls/fiducial_flatsky_lensedCls.dat', - 'lensit/data/cls/fiducial_flatsky_lenspotentialCls.dat', - 'lensit/data/cls/fiducial_params_tensor.ini', - 'lensit/data/cls/fiducial_tensCls.dat'])], - url='https://github.com/carronj/lensit', - author='Julien Carron', - author_email='to.jcarron@gmail.com', - description='CMB lensing flat-sky quadratic and iterative estimation tools', - install_requires=['numpy', 'pyfftw', 'scipy'], #skipped mpi4py for travis - long_description=long_description, - configuration=configuration) -