diff options
Diffstat (limited to 'Python')
-rwxr-xr-x | Python/pywarpx/_libwarpx.py | 12 | ||||
-rw-r--r-- | Python/setup.py | 51 |
2 files changed, 49 insertions, 14 deletions
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py index 2560da235..f8f57bd85 100755 --- a/Python/pywarpx/_libwarpx.py +++ b/Python/pywarpx/_libwarpx.py @@ -59,10 +59,18 @@ else: _libc = ctypes.CDLL(_find_library('c')) +# macOS/Linux use .so, Windows uses .pyd +# https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll +if os.name == 'nt': + mod_ext = "pyd" +else: + mod_ext = "so" +libname = "libwarpx{0}.{1}".format(geometry_dim, mod_ext) + try: - libwarpx = ctypes.CDLL(os.path.join(_get_package_root(), "libwarpx%s.so"%geometry_dim)) + libwarpx = ctypes.CDLL(os.path.join(_get_package_root(), libname)) except OSError: - raise Exception('libwarpx%s.so was not installed. It can be installed by running "make" in the Python directory of WarpX'%geometry_dim) + raise Exception('"%s" was not installed. It can be installed by running "make" in the Python directory of WarpX' % libname) # WarpX can be compiled using either double or float libwarpx.warpx_Real_size.restype = ctypes.c_int diff --git a/Python/setup.py b/Python/setup.py index a91c46c9f..ddce8235a 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -12,27 +12,54 @@ setup.py file for WarpX """ -import sys import argparse +import os +import sys from setuptools import setup argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument('--with-libwarpx', type=str, default=None, help='Install libwarpx with the given value as DIM. This option is only used by the makefile.') +argparser.add_argument('--with-libwarpx', type=str, default=None, help='Install libwarpx with the given value as DIM. This option is only used by the GNU makefile build system.') +argparser.add_argument('--with-lib-dir', type=str, default=None, help='Install with all libwarpx* binaries found in a directory.') args, unknown = argparser.parse_known_args() sys.argv = [sys.argv[0]] + unknown +allowed_dims = ["2d", "3d", "rz"] + +# Allow to control options via environment vars. +# Work-around for https://github.com/pypa/setuptools/issues/1712 +PYWARPX_LIB_DIR = os.environ.get('PYWARPX_LIB_DIR') + if args.with_libwarpx: - package_data = {'pywarpx' : ['libwarpx%s.so'%args.with_libwarpx]} + # GNUmake + if args.with_libwarpx not in allowed_dims: + print("WARNING: '%s' is not an allowed WarpX DIM" % args.with_libwarpx) + package_data = {'pywarpx' : ['libwarpx%s.so' % args.with_libwarpx]} + data_files = [] +elif args.with_lib_dir or PYWARPX_LIB_DIR: + # CMake and Package Managers + package_data = {'pywarpx' : []} + lib_dir = args.with_lib_dir if args.with_lib_dir else PYWARPX_LIB_DIR + my_path = os.path.dirname(os.path.realpath(__file__)) + for dim in allowed_dims: + lib_name = 'libwarpx%s.so' % dim + lib_path = os.path.join(lib_dir, lib_name) + link_name = os.path.join(my_path, "pywarpx", lib_name) + if os.path.isfile(link_name): + os.remove(link_name) + if os.path.isfile(lib_path) and os.access(lib_path, os.R_OK): + os.symlink(lib_path, link_name) + package_data['pywarpx'].append(lib_name) else: package_data = {} -setup (name = 'pywarpx', - version = '20.12', - packages = ['pywarpx'], - package_dir = {'pywarpx':'pywarpx'}, - description = """Wrapper of WarpX""", - package_data = package_data, - install_requires=['numpy', 'picmistandard==0.0.12', 'periodictable'], - python_requires = '>=3.6' - ) +setup(name = 'pywarpx', + version = '20.12', + packages = ['pywarpx'], + package_dir = {'pywarpx': 'pywarpx'}, + description = """Wrapper of WarpX""", + package_data = package_data, + install_requires = ['numpy', 'picmistandard==0.0.12', 'periodictable'], + python_requires = '>=3.6', + zip_safe=False +) |