-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.py
More file actions
86 lines (75 loc) · 3.17 KB
/
setup.py
File metadata and controls
86 lines (75 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#
# @ 2023. Triad National Security, LLC. All rights reserved.
#
# This program was produced under U.S. Government contract 89233218CNA000001
# for Los Alamos National Laboratory (LANL), which is operated by Triad
# National Security, LLC for the U.S. Department of Energy/National Nuclear
# Security Administration. All rights in the program are reserved by Triad
# National Security, LLC, and the U.S. Department of Energy/National Nuclear
# Security Administration. The Government is granted for itself and others acting
# on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this
# material to reproduce, prepare derivative works, distribute copies to the
# public, perform publicly and display publicly, and to permit others to do so.
#
# Author: Yu Zhang <zhy@lanl.gov>
#
import os, sys
from setuptools import setup, find_packages
from setuptools import Extension
from setuptools.command.build_ext import build_ext as _build_ext
import subprocess
class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
import builtins
builtins.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
super().__init__(name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
# Check if CMake build is requested
if os.getenv('BUILD_LIB', '0') == '1':
self.build_cmake()
else:
print("Skipping CMake build. Set BUILD_LIB=1 to enable.")
def build_cmake(self):
# Define the build directory and the install directory
build_dir = os.path.join(os.getcwd(), "openms/lib/build")
install_dir = os.path.join(os.getcwd(), "openms/lib/deps/")
# Ensure the directories exist
os.makedirs(build_dir, exist_ok=True)
os.makedirs(install_dir, exist_ok=True)
# Run CMake with the specified installation prefix
subprocess.check_call([
"cmake",
self.extensions[0].sourcedir,
f"-DCMAKE_INSTALL_PREFIX={install_dir}"
], cwd=build_dir)
# Build and install the project
subprocess.check_call(["make"], cwd=build_dir)
subprocess.check_call(["make", "install"], cwd=build_dir)
def build_extensions(self):
# Standard extension build (e.g., Cython or pure Python)
for ext in self.extensions:
if isinstance(ext, CMakeExtension):
continue # Skip CMake extensions
_build_ext.build_extensions(self)
setup(
name="openms",
version="0.2.0",
description="An open-source multiscale solver for coupled Maxwell-Schrödinger equations.",
packages=find_packages(),
ext_modules=[CMakeExtension("openms_lib", sourcedir="./openms/lib")],
cmdclass={"build_ext": CMakeBuild},
extras_require={ # optional package for extra features
"mpi": ["mpi4py"], # TBA
"gpu": ["cupy"], # TBA
"test": ["pytest"], # for test
"all": ["mpi4py"] # TBA
},
)