diff --git a/MANIFEST.in b/MANIFEST.in index 1f5744c..9bdc4c9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include *.rst *.md +include *.rst *.md CMakeLists.txt include casacore/.aipsrc graft casacore/data graft doc diff --git a/pyproject.toml b/pyproject.toml index 2669503..054c6bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = [ "build", "cmake>=3.18", "oldest-supported-numpy", + "scikit-build>=0.13", "setuptools", "wheel", ] diff --git a/setup.py b/setup.py index 844b7ec..7a9ff81 100755 --- a/setup.py +++ b/setup.py @@ -2,257 +2,259 @@ """ Setup script for the CASACORE python wrapper. """ +from skbuild import setup + import os -import subprocess -import sys -import warnings -from setuptools import setup, Extension, find_packages, find_namespace_packages -from distutils.sysconfig import get_config_vars -from distutils.command import build_ext as build_ext_module -from distutils import ccompiler -from distutils.version import LooseVersion -import argparse -import ctypes +# import subprocess +# import sys +# import warnings +from setuptools import find_packages, find_namespace_packages +# from distutils.sysconfig import get_config_vars +# from distutils.command import build_ext as build_ext_module +# from distutils import ccompiler +# from distutils.version import LooseVersion +# import argparse +# import ctypes from os.path import join, dirname from casacore import __version__, __mincasacoreversion__ -no_boost_error = """ -Could not find a Python boost library! Please use your package manager to install boost. +# no_boost_error = """ +# Could not find a Python boost library! Please use your package manager to install boost. -Or install it manually: +# Or install it manually: -http://boostorg.github.io/python/doc/html/index.html -""" +# http://boostorg.github.io/python/doc/html/index.html +# """ -no_casacore_error = """Could not find Casacore! +# no_casacore_error = """Could not find Casacore! -Casacore is a critical requirement. Please install Casacore using a package manager or install it manually. -You can find installation instructions on: +# Casacore is a critical requirement. Please install Casacore using a package manager or install it manually. +# You can find installation instructions on: - https://github.com/casacore/casacore +# https://github.com/casacore/casacore -If you have Casacore installed in a non default location, you need to specify the location: +# If you have Casacore installed in a non default location, you need to specify the location: -$ python setup.py build_ext -I/opt/casacore/include:/other/include/path -L/opt/casacore/lib +# $ python setup.py build_ext -I/opt/casacore/include:/other/include/path -L/opt/casacore/lib -Don't give up! -""" +# Don't give up! +# """ -def find_library_file(libname): - """ - Try to get the directory of the specified library. - It adds to the search path the library paths given to distutil's build_ext. - """ - # Use a dummy argument parser to get user specified library dirs - parser = argparse.ArgumentParser(add_help=False) - parser.add_argument("--library-dirs", "-L", default='') - args, unknown = parser.parse_known_args() - lib_dirs = args.library_dirs.split(':') - - if 'LD_LIBRARY_PATH' in os.environ: - lib_dirs += os.environ['LD_LIBRARY_PATH'].split(':') - # Look for Homebrewed libraries - try: - homebrew_prefix = subprocess.run( - ['brew', '--prefix'], - capture_output=True, - check=True, - text=True - ).stdout.strip() - lib_dirs.append(join(homebrew_prefix, 'lib')) - except (subprocess.CalledProcessError, FileNotFoundError): - pass - # Append default search path (not a complete list) - lib_dirs += [join(sys.prefix, 'lib'), - '/usr/local/lib', - '/usr/lib64', - '/usr/lib', - '/usr/lib/x86_64-linux-gnu'] +# def find_library_file(libname): +# """ +# Try to get the directory of the specified library. +# It adds to the search path the library paths given to distutil's build_ext. +# """ +# # Use a dummy argument parser to get user specified library dirs +# parser = argparse.ArgumentParser(add_help=False) +# parser.add_argument("--library-dirs", "-L", default='') +# args, unknown = parser.parse_known_args() +# lib_dirs = args.library_dirs.split(':') - compiler = ccompiler.new_compiler() - return compiler.find_library_file(lib_dirs, libname) +# if 'LD_LIBRARY_PATH' in os.environ: +# lib_dirs += os.environ['LD_LIBRARY_PATH'].split(':') +# # Look for Homebrewed libraries +# try: +# homebrew_prefix = subprocess.run( +# ['brew', '--prefix'], +# capture_output=True, +# check=True, +# text=True +# ).stdout.strip() +# lib_dirs.append(join(homebrew_prefix, 'lib')) +# except (subprocess.CalledProcessError, FileNotFoundError): +# pass +# # Append default search path (not a complete list) +# lib_dirs += [join(sys.prefix, 'lib'), +# '/usr/local/lib', +# '/usr/lib64', +# '/usr/lib', +# '/usr/lib/x86_64-linux-gnu'] + +# compiler = ccompiler.new_compiler() +# return compiler.find_library_file(lib_dirs, libname) def read(fname): return open(join(dirname(__file__), fname)).read() -def find_boost(): - """ - Find the name and path of boost-python - - Returns: - library_name, e.g. 'boost_python-py36' (a guess if boost is not found) - library_dir, e.g. '/opt/local/boost/lib' ('' if boost is not found) - include_dir, e.g. '/opt/local/boost/include' ('' if boost is not found) - """ - short_version = "{}{}".format(sys.version_info[0], sys.version_info[1]) - major_version = str(sys.version_info[0]) - - # Prefer libraries with python version in their name over unversioned variants - boostlibnames = ['boost_python-py' + short_version, - 'boost_python' + short_version, - 'boost_python' + major_version, - 'boost_python', - ] - # The -mt (multithread) extension is used on macOS but not Linux. - # Look for it first to avoid ending up with a single-threaded version. - boostlibnames = sum([[name + '-mt', name] for name in boostlibnames], []) - - for libboostname in boostlibnames: - found_lib = find_library_file(libboostname) - if found_lib: - libdir = dirname(found_lib) - includedir = join(dirname(libdir), "include") - return libboostname, libdir, includedir - - warnings.warn(no_boost_error) - return boostlibnames[0], '', '' - - -def find_casacore_version(): - """ - Find the version of casacore, or None if it's not found - """ - if sys.version_info[0] == 2: - casa_python = 'casa_python' - else: - casa_python = 'casa_python3' - - # Find casacore libpath - libcasacasa = find_library_file('casa_casa') - - casacoreversion = None - if libcasacasa: - # Get version number from casacore - try: - libcasa = ctypes.cdll.LoadLibrary(libcasacasa) - getCasacoreVersion = libcasa.getVersion - getCasacoreVersion.restype = ctypes.c_char_p - casacoreversion = getCasacoreVersion().decode('utf-8') - except: - # getVersion was fixed in casacore 2.3.0 - pass - - return casacoreversion - - -def find_casacore(): - """ - Find the name and path of casacore - - Returns: - library_name, e.g. 'casa_python3' - library_dir, e.g. '/opt/local/casacore/lib' ('' if casacore is not found) - include_dir, e.g. '/opt/local/casacore/include' ('' if casacore is not found) - """ - if sys.version_info[0] == 2: - casa_python = 'casa_python' - else: - casa_python = 'casa_python3' - - # Find casacore libpath - libcasacasa = find_library_file('casa_casa') - - libdir = '' - includedir = '' - if libcasacasa: - libdir = dirname(libcasacasa) - includedir = join(dirname(libdir), "include") - else: - warnings.warn(no_casacore_error) - - return casa_python, libdir, includedir - - -def get_extensions(): - boost_python_libname, boost_python_libdir, boost_python_includedir = find_boost() - casa_python_libname, casa_libdir, casa_includedir = find_casacore() - - extension_metas = ( - # name, sources, depends, libraries - ( - "casacore.fitting._fitting", - ["src/fit.cc", "src/fitting.cc"], - ["src/fitting.h"], - ['casa_scimath', 'casa_scimath_f', boost_python_libname, casa_python_libname], - ), - ( - "casacore.functionals._functionals", - ["src/functional.cc", "src/functionals.cc"], - ["src/functionals.h"], - ['casa_scimath', 'casa_scimath_f', boost_python_libname, casa_python_libname], - ), - ( - "casacore.images._images", - ["src/images.cc", "src/pyimages.cc"], - ["src/pyimages.h"], - ['casa_images', 'casa_coordinates', - 'casa_fits', 'casa_lattices', 'casa_measures', - 'casa_scimath', 'casa_scimath_f', 'casa_tables', 'casa_mirlib', - boost_python_libname, casa_python_libname] - ), - ( - "casacore.measures._measures", - ["src/pymeas.cc", "src/pymeasures.cc"], - ["src/pymeasures.h"], - ['casa_measures', 'casa_scimath', 'casa_scimath_f', 'casa_tables', - boost_python_libname, casa_python_libname] - ), - ( - "casacore.quanta._quanta", - ["src/quanta.cc", "src/quantamath.cc", "src/quantity.cc", - "src/quantvec.cc"], - ["src/quanta.h"], - ["casa_casa", boost_python_libname, casa_python_libname], - ), - ( - "casacore.tables._tables", - ["src/pytable.cc", "src/pytableindex.cc", "src/pytableiter.cc", - "src/pytablerow.cc", "src/tables.cc", "src/pyms.cc"], - ["src/tables.h"], - ['casa_derivedmscal', 'casa_meas', 'casa_ms', 'casa_tables', boost_python_libname, casa_python_libname], - ), - ( - "casacore._tConvert", - ["tests/tConvert.cc"], - [], - [boost_python_libname, casa_python_libname], - ) - ) - - extensions = [] - for meta in extension_metas: - name, sources, depends, libraries = meta - - # Add dependency on casacore libraries to trigger rebuild at casacore update - for library in libraries: - if library and 'casa' in library: - found_lib = find_library_file(library) - if found_lib: - depends = depends + [found_lib] - - library_dirs = [lib for lib in (boost_python_libdir, - casa_libdir) if lib] - include_dirs = [inc for inc in (boost_python_includedir, - casa_includedir) if inc] - - extensions.append(Extension(name=name, sources=sources, - depends=depends, libraries=libraries, - library_dirs=library_dirs, - include_dirs=include_dirs, - # Since casacore 3.0.0 we have to be C++11 - extra_compile_args=['-std=c++11'])) - return extensions - - -# remove the strict-prototypes warning during compilation -(opt,) = get_config_vars('OPT') -os.environ['OPT'] = " ".join( - flag for flag in opt.split() if flag != '-Wstrict-prototypes' -) +# def find_boost(): +# """ +# Find the name and path of boost-python + +# Returns: +# library_name, e.g. 'boost_python-py36' (a guess if boost is not found) +# library_dir, e.g. '/opt/local/boost/lib' ('' if boost is not found) +# include_dir, e.g. '/opt/local/boost/include' ('' if boost is not found) +# """ +# short_version = "{}{}".format(sys.version_info[0], sys.version_info[1]) +# major_version = str(sys.version_info[0]) + +# # Prefer libraries with python version in their name over unversioned variants +# boostlibnames = ['boost_python-py' + short_version, +# 'boost_python' + short_version, +# 'boost_python' + major_version, +# 'boost_python', +# ] +# # The -mt (multithread) extension is used on macOS but not Linux. +# # Look for it first to avoid ending up with a single-threaded version. +# boostlibnames = sum([[name + '-mt', name] for name in boostlibnames], []) + +# for libboostname in boostlibnames: +# found_lib = find_library_file(libboostname) +# if found_lib: +# libdir = dirname(found_lib) +# includedir = join(dirname(libdir), "include") +# return libboostname, libdir, includedir + +# warnings.warn(no_boost_error) +# return boostlibnames[0], '', '' + + +# def find_casacore_version(): +# """ +# Find the version of casacore, or None if it's not found +# """ +# if sys.version_info[0] == 2: +# casa_python = 'casa_python' +# else: +# casa_python = 'casa_python3' + +# # Find casacore libpath +# libcasacasa = find_library_file('casa_casa') + +# casacoreversion = None +# if libcasacasa: +# # Get version number from casacore +# try: +# libcasa = ctypes.cdll.LoadLibrary(libcasacasa) +# getCasacoreVersion = libcasa.getVersion +# getCasacoreVersion.restype = ctypes.c_char_p +# casacoreversion = getCasacoreVersion().decode('utf-8') +# except: +# # getVersion was fixed in casacore 2.3.0 +# pass + +# return casacoreversion + + +# def find_casacore(): +# """ +# Find the name and path of casacore + +# Returns: +# library_name, e.g. 'casa_python3' +# library_dir, e.g. '/opt/local/casacore/lib' ('' if casacore is not found) +# include_dir, e.g. '/opt/local/casacore/include' ('' if casacore is not found) +# """ +# if sys.version_info[0] == 2: +# casa_python = 'casa_python' +# else: +# casa_python = 'casa_python3' + +# # Find casacore libpath +# libcasacasa = find_library_file('casa_casa') + +# libdir = '' +# includedir = '' +# if libcasacasa: +# libdir = dirname(libcasacasa) +# includedir = join(dirname(libdir), "include") +# else: +# warnings.warn(no_casacore_error) + +# return casa_python, libdir, includedir + + +# def get_extensions(): +# boost_python_libname, boost_python_libdir, boost_python_includedir = find_boost() +# casa_python_libname, casa_libdir, casa_includedir = find_casacore() + +# extension_metas = ( +# # name, sources, depends, libraries +# ( +# "casacore.fitting._fitting", +# ["src/fit.cc", "src/fitting.cc"], +# ["src/fitting.h"], +# ['casa_scimath', 'casa_scimath_f', boost_python_libname, casa_python_libname], +# ), +# ( +# "casacore.functionals._functionals", +# ["src/functional.cc", "src/functionals.cc"], +# ["src/functionals.h"], +# ['casa_scimath', 'casa_scimath_f', boost_python_libname, casa_python_libname], +# ), +# ( +# "casacore.images._images", +# ["src/images.cc", "src/pyimages.cc"], +# ["src/pyimages.h"], +# ['casa_images', 'casa_coordinates', +# 'casa_fits', 'casa_lattices', 'casa_measures', +# 'casa_scimath', 'casa_scimath_f', 'casa_tables', 'casa_mirlib', +# boost_python_libname, casa_python_libname] +# ), +# ( +# "casacore.measures._measures", +# ["src/pymeas.cc", "src/pymeasures.cc"], +# ["src/pymeasures.h"], +# ['casa_measures', 'casa_scimath', 'casa_scimath_f', 'casa_tables', +# boost_python_libname, casa_python_libname] +# ), +# ( +# "casacore.quanta._quanta", +# ["src/quanta.cc", "src/quantamath.cc", "src/quantity.cc", +# "src/quantvec.cc"], +# ["src/quanta.h"], +# ["casa_casa", boost_python_libname, casa_python_libname], +# ), +# ( +# "casacore.tables._tables", +# ["src/pytable.cc", "src/pytableindex.cc", "src/pytableiter.cc", +# "src/pytablerow.cc", "src/tables.cc", "src/pyms.cc"], +# ["src/tables.h"], +# ['casa_derivedmscal', 'casa_meas', 'casa_ms', 'casa_tables', boost_python_libname, casa_python_libname], +# ), +# ( +# "casacore._tConvert", +# ["tests/tConvert.cc"], +# [], +# [boost_python_libname, casa_python_libname], +# ) +# ) + +# extensions = [] +# for meta in extension_metas: +# name, sources, depends, libraries = meta + +# # Add dependency on casacore libraries to trigger rebuild at casacore update +# for library in libraries: +# if library and 'casa' in library: +# found_lib = find_library_file(library) +# if found_lib: +# depends = depends + [found_lib] + +# library_dirs = [lib for lib in (boost_python_libdir, +# casa_libdir) if lib] +# include_dirs = [inc for inc in (boost_python_includedir, +# casa_includedir) if inc] + +# extensions.append(Extension(name=name, sources=sources, +# depends=depends, libraries=libraries, +# library_dirs=library_dirs, +# include_dirs=include_dirs, +# # Since casacore 3.0.0 we have to be C++11 +# extra_compile_args=['-std=c++11'])) +# return extensions + + +# # remove the strict-prototypes warning during compilation +# (opt,) = get_config_vars('OPT') +# os.environ['OPT'] = " ".join( +# flag for flag in opt.split() if flag != '-Wstrict-prototypes' +# ) def create_symlink(src_dir, dest_dir): @@ -272,17 +274,20 @@ def create_symlink(src_dir, dest_dir): return dest_dir -class my_build_ext(build_ext_module.build_ext): - def run(self): - casacoreversion = find_casacore_version() - if casacoreversion is not None and LooseVersion(casacoreversion) < LooseVersion(__mincasacoreversion__): - errorstr = "Your casacore version is too old. Minimum is " + __mincasacoreversion__ + \ - ", you have " + casacoreversion - if casacoreversion == "2.5.0": - errorstr += " or 3.0.0 (which shipped in KERN5, incorrectly reporting itself as 2.5.0)" - raise RuntimeError(errorstr) +# class my_build_ext(build_ext_module.build_ext): +# def run(self): +# casacoreversion = find_casacore_version() +# if casacoreversion is not None and LooseVersion(casacoreversion) < LooseVersion(__mincasacoreversion__): +# errorstr = "Your casacore version is too old. Minimum is " + __mincasacoreversion__ + \ +# ", you have " + casacoreversion +# if casacoreversion == "2.5.0": +# errorstr += " or 3.0.0 (which shipped in KERN5, incorrectly reporting itself as 2.5.0)" +# raise RuntimeError(errorstr) + +# build_ext_module.build_ext.run(self) - build_ext_module.build_ext.run(self) +packages=find_packages() + find_namespace_packages(include=["casacore.data.*"]) +print("===> packages =", packages) setup(name='python-casacore', version=__version__, @@ -295,6 +300,7 @@ def run(self): long_description=read('README.rst'), long_description_content_type='text/x-rst', packages=find_packages() + find_namespace_packages(include=["casacore.data.*"]), + # packages=['casacore.fitting', 'casacore.functionals', 'casacore.images', 'casacore.measures', 'casacore.quanta', 'casacore.tables', "casacore.data.*"], include_package_data=True, # We need to bring the casacore data files in scope of the python package. # There is no need to copy the files, creating a symlink suffices. Environment @@ -306,6 +312,6 @@ def run(self): package_data={ "casacore.data": [create_symlink(os.getenv("CASACORE_DATA"), "casacore/data")] }, - ext_modules=get_extensions(), - cmdclass={'build_ext': my_build_ext}, + # ext_modules=get_extensions(), + # cmdclass={'build_ext': my_build_ext}, license='LGPL')