mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 15:21:11 +00:00
- remove distutils deps - add pyproject.toml - add MANIFEST.in - update install instructions
136 lines
5.4 KiB
Python
136 lines
5.4 KiB
Python
#+
|
|
# VIDE -- Void IDentification and Examination -- ./setup.py
|
|
# Copyright (C) 2010-2014 Guilhem Lavaux
|
|
# Copyright (C) 2011-2014 P. M. Sutter
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License.
|
|
#
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
#+
|
|
|
|
import os
|
|
import sys
|
|
import shutil
|
|
import stat
|
|
import pathlib
|
|
import struct
|
|
from sysconfig import get_config_var
|
|
from setuptools import find_packages, setup, Extension
|
|
from setuptools.command.build_ext import build_ext
|
|
from setuptools.command.install_lib import install_lib
|
|
from setuptools.command.install_scripts import install_scripts
|
|
|
|
BITS = struct.calcsize("P") * 8
|
|
PACKAGE_NAME = "vide"
|
|
|
|
class CMakeExtension(Extension):
|
|
def __init__(self, name, sources=["dummy_extension/empty.c"]):
|
|
super().__init__(name=name, sources=sources)
|
|
self.SOURCE_DIR = str(pathlib.Path().absolute())
|
|
|
|
class InstallCMakeLibs(install_lib):
|
|
def run(self):
|
|
self.announce("Moving library files", level=3)
|
|
super().run()
|
|
|
|
class InstallScripts(install_scripts):
|
|
def run(self):
|
|
# Move the generated script from the build directory to the final installation directory
|
|
build_temp = self.get_finalized_command('build_ext').build_temp
|
|
generated_script = os.path.join(build_temp, 'vide_prepare_simulation')
|
|
|
|
if os.path.exists(generated_script):
|
|
target_script_dir = os.path.join(self.install_dir, 'bin')
|
|
os.makedirs(target_script_dir, exist_ok=True)
|
|
shutil.copy(generated_script, target_script_dir)
|
|
super().run()
|
|
|
|
class BuildCMakeExt(build_ext):
|
|
def run(self):
|
|
for extension in self.extensions:
|
|
if extension.name == 'vide':
|
|
self.package = 'vide'
|
|
self.build_cmake(extension)
|
|
super().run()
|
|
|
|
def build_cmake(self, extension: Extension):
|
|
self.announce("Preparing the build environment", level=3)
|
|
|
|
# Ensure absolute paths are used
|
|
package_dir = os.path.abspath(os.path.join(self.build_lib, 'vide'))
|
|
extension.build_dir = os.path.abspath(self.build_temp)
|
|
extension.bin_dir = str(pathlib.Path(os.path.join(extension.build_dir, 'private_install')).absolute())
|
|
SOURCE_DIR = os.path.abspath(extension.SOURCE_DIR) # Absolute path to source directory
|
|
|
|
extension_path = pathlib.Path(self.get_ext_fullpath(extension.name))
|
|
|
|
# Make sure necessary directories exist
|
|
os.makedirs(extension.build_dir, exist_ok=True)
|
|
os.makedirs(extension_path.parent.absolute(), exist_ok=True)
|
|
|
|
# Write the cython code if necessary
|
|
cython_code = os.path.join(str(extension.build_dir), 'mycython')
|
|
with open(cython_code, mode="wt") as ff:
|
|
ff.write(f"#!{sys.executable}\n"
|
|
"from Cython.Compiler.Main import setuptools_main\n"
|
|
"setuptools_main()")
|
|
os.chmod(cython_code, stat.S_IXUSR | stat.S_IWUSR | stat.S_IRUSR | stat.S_IRGRP)
|
|
|
|
self.announce("Configuring cmake project", level=3)
|
|
|
|
# Ensure the cmake command has the correct source directory
|
|
c_compiler = os.environ.get('CC', get_config_var("CC"))
|
|
cxx_compiler = os.environ.get('CXX', get_config_var("CXX"))
|
|
|
|
self.spawn(['cmake', '-H' + SOURCE_DIR, '-B' + self.build_temp,
|
|
'-DENABLE_OPENMP=ON', '-DINTERNAL_BOOST=ON', '-DINTERNAL_EIGEN=ON',
|
|
'-DINTERNAL_HDF5=ON', '-DINTERNAL_NETCDF=ON', '-DINTERNAL_GSL=ON',
|
|
'-DBUILD_PYTHON=ON', '-DINSTALL_PYTHON_LOCAL=OFF',
|
|
'-DCOSMOTOOL_PYTHON_PACKAGING=ON',
|
|
f"-DCYTHON={cython_code}",
|
|
'-DINSTALL_CTOOLS_IN_PYTHON=ON',
|
|
f"-DCMAKE_C_COMPILER={c_compiler}", f"-DCMAKE_CXX_COMPILER={cxx_compiler}",
|
|
f"-DPYTHON_SITE_PACKAGES={extension.bin_dir}",
|
|
f"-DPYTHON_EXECUTABLE={sys.executable}"])
|
|
|
|
self.announce("Building binaries", level=3)
|
|
self.spawn(["cmake", "--build", self.build_temp, "--target", "all", "--config", "Release", "--", "VERBOSE=1"])
|
|
self.spawn(["cmake", "--build", self.build_temp, "--target", "install", "--config", "Release", "--", "VERBOSE=1"])
|
|
|
|
vide_extension = CMakeExtension(name="vide")
|
|
|
|
setup(
|
|
name='vide',
|
|
version='2.0',
|
|
packages=find_packages('python_tools'),
|
|
package_dir={'': 'python_tools'},
|
|
ext_modules=[vide_extension],
|
|
cmdclass={
|
|
'build_ext': BuildCMakeExt,
|
|
'install_lib': InstallCMakeLibs,
|
|
'install_scripts': InstallScripts,
|
|
},
|
|
data_files=[
|
|
('share/vide/data', ['data/file1.dat', 'data/file2.dat']),
|
|
],
|
|
install_requires=[
|
|
'scipy',
|
|
'astropy',
|
|
'extension-helpers',
|
|
'netCDF4',
|
|
'healpy',
|
|
],
|
|
description='The VIDE pipeline analysis for Cosmic Voids',
|
|
long_description=open("./README.md", 'r').read(),
|
|
long_description_content_type="text/markdown",
|
|
)
|