diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3ae456b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.15...3.26) + +project(sdtw) + +find_package(PythonExtensions REQUIRED) +find_package(Cython REQUIRED) + +# Add NumPy include directory +execute_process( + COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy as np; print(np.get_include())" + OUTPUT_VARIABLE NUMPY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +include_directories(${NUMPY_INCLUDE_DIR}) + +add_subdirectory(sdtw) diff --git a/README.rst b/README.rst index b5a6a0e..e4f4802 100644 --- a/README.rst +++ b/README.rst @@ -84,9 +84,7 @@ or, if `git` is unavailable, `download as a ZIP from GitHub =42", + "scikit-build>=0.13", + "cmake>=3.18", + "ninja", + "cython", + "numpy", +] +build-backend = "setuptools.build_meta" diff --git a/sdtw/CMakeLists.txt b/sdtw/CMakeLists.txt new file mode 100644 index 0000000..0c60e0e --- /dev/null +++ b/sdtw/CMakeLists.txt @@ -0,0 +1,5 @@ +add_cython_target(soft_dtw_fast soft_dtw_fast.pyx) +add_library(soft_dtw_fast MODULE ${soft_dtw_fast}) +python_extension_module(soft_dtw_fast) + +install(TARGETS soft_dtw_fast LIBRARY DESTINATION sdtw) diff --git a/sdtw/setup.py b/sdtw/setup.py deleted file mode 100644 index c718096..0000000 --- a/sdtw/setup.py +++ /dev/null @@ -1,21 +0,0 @@ -import os.path - -import numpy - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration('sdtw', parent_package, top_path) - - config.add_extension('soft_dtw_fast', sources=['soft_dtw_fast.c'], - include_dirs=[numpy.get_include()]) - - config.add_subpackage('tests') - - return config - - -if __name__ == '__main__': - from numpy.distutils.core import setup - setup(**configuration(top_path='').todict()) diff --git a/sdtw/soft_dtw_fast.pyx b/sdtw/soft_dtw_fast.pyx index 854f2c4..27ced87 100644 --- a/sdtw/soft_dtw_fast.pyx +++ b/sdtw/soft_dtw_fast.pyx @@ -5,7 +5,7 @@ # cython: cdivision=True # cython: boundscheck=False # cython: wraparound=False - +# cython: language_level=3str import numpy as np cimport numpy as np np.import_array() diff --git a/setup.py b/setup.py index 7a01142..991c57f 100644 --- a/setup.py +++ b/setup.py @@ -1,65 +1,20 @@ -from __future__ import print_function -import os.path -import sys -import setuptools -from numpy.distutils.core import setup - - -try: - import numpy -except ImportError: - print('numpy is required during installation') - sys.exit(1) - - -DISTNAME = 'soft-dtw' +from skbuild import setup +DISTNAME = 'softdtw' DESCRIPTION = "Python implementation of soft-DTW" -LONG_DESCRIPTION = open('README.rst').read() -MAINTAINER = 'Mathieu Blondel' -MAINTAINER_EMAIL = '' -URL = 'https://github.com/mblondel/soft-dtw/' +MAINTAINER = 'Mathieu Blondel,Cesar Rodas' +MAINTAINER_EMAIL = 'cesar_rodas@outlook.com' LICENSE = 'Simplified BSD' -DOWNLOAD_URL = 'https://github.com/mblondel/soft-dtw/' +PACKAGES=['sdtw'] VERSION = '0.1.dev0' - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration(None, parent_package, top_path) - - config.add_subpackage('sdtw') - - return config - - -if __name__ == '__main__': - old_path = os.getcwd() - local_path = os.path.dirname(os.path.abspath(sys.argv[0])) - - os.chdir(local_path) - sys.path.insert(0, local_path) - - setup(configuration=configuration, - name=DISTNAME, - maintainer=MAINTAINER, - include_package_data=True, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - license=LICENSE, - url=URL, - version=VERSION, - download_url=DOWNLOAD_URL, - long_description=LONG_DESCRIPTION, - zip_safe=False, # the package can run out of an .egg file - classifiers=[ - 'Intended Audience :: Science/Research', - 'Intended Audience :: Developers', 'License :: OSI Approved', - 'Programming Language :: C', 'Programming Language :: Python', - 'Topic :: Software Development', - 'Topic :: Scientific/Engineering', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', 'Operating System :: Unix', - 'Operating System :: MacOS' - ] - ) +CMAKE_INSTALL_DIR='sdtw' +setup( + name=DISTNAME, + version=VERSION, + description=DESCRIPTION, + author=MAINTAINER, + license=LICENSE, + packages=PACKAGES, + python_requires=">=3.7", + cmake_install_dir=CMAKE_INSTALL_DIR, + cmake_args=["-DCMAKE_BUILD_TYPE=Release"], # Adjust as needed + )