Skip to content

Commit

Permalink
Clean up setup.py
Browse files Browse the repository at this point in the history
Remove unused code, comment to explain what's going on with the dynamic
libraries, fix the auto-detection of the library path when run from the
project directory using `python3 setup.py`.
  • Loading branch information
janden committed Oct 7, 2020
1 parent ef2045f commit e64bd19
Showing 1 changed file with 22 additions and 43 deletions.
65 changes: 22 additions & 43 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,36 @@
# This defines the python module installation.
# Only for double-prec, multi-threaded for now.
# This defines the Python module installation.

# Barnett 3/1/18. Updates by Yu-Hsuan Shih, June 2018.
# win32 mingw patch by Vineet Bansal, Feb 2019.
# attempt ../make.inc reading (failed) and default finufftdir. 2/25/20
# Barnett trying to get sphinx.ext.autodoc to work w/ this, 10/5/20

# Max OSX users: please edit as per below comments, and docs/install.rst

__version__ = '2.0.1'

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import setuptools
import os
import ctypes

from tempfile import mkstemp

# libin to change to python-dotenv or whatever's simplest:
import dotenv # is this part of standard python? (install_requires fails) ?

finufftdir = os.environ.get('FINUFFT_DIR')

# since people might not set it, set to the parent of this script's dir...
if finufftdir==None or finufftdir=='':
finufftdir = os.path.dirname(os.path.dirname(__file__))
# removed: this fails because pip copies this file to /tmp/pip-req-build-*** !

# default compiler choice (note g++ = clang in mac-osx):
os.environ['CC'] = 'gcc'
os.environ['CXX'] = 'g++'
finufft_dir = os.environ.get('FINUFFT_DIR')

# attempt override compiler choice using ../make.inc to match your C++ build
makeinc = finufftdir+"/make.inc"
dotenv.load_dotenv(makeinc, override=True) # modifies os.environ
print('checking CXX var supposedly read from ../make.inc: ',os.environ['CXX'])
# Note: This will not work if run through pip install since setup.py is copied
# to a different location.
if finufft_dir == None or finufft_dir == '':
current_path = os.path.abspath(__file__)
finufft_dir = os.path.dirname(os.path.dirname(current_path))

# in the end avoided code from https://stackoverflow.com/questions/3503719/emulating-bash-source-in-python
#if os.path.isfile(makeinc):
# command = 'env -i bash -c "source %s"' % (makeinc)
# for line in subprocess.getoutput(command).split("\n"):
# if line!='':
# key, value = line.split("=")
# print(key, value)
# os.environ[key] = value
# Set include and library paths relative to FINUFFT root directory.
inc_dir = os.path.join(finufft_dir, 'include')
lib_dir = os.path.join(finufft_dir, 'lib')

inc_dir = finufftdir+"/include"
src_dir = finufftdir+"/src"
lib_dir = finufftdir+"/lib"
finufft_dlib = finufftdir+"/lib/finufft"
finufft_lib = finufftdir+"/lib-static/finufft"
# We specifically link to the dynamic library here through its absolute path
# (that is not through -lfinufft) to ensure that the absolute path of the
# library is encoded in the DT_NEEDED tag. This way, we won't need to have
# libfinufft.so in the LD_LIBRARY_PATH at runtime. The risk with this is that
# if the libfinufft.so is deleted or moved, the Python module will break
# unless LD_LIBRARY_PATH is updated.
finufft_dlib = os.path.join(lib_dir, 'finufft')

# For certain platforms (e.g. Ubuntu 20.04), we need to create a dummy source
# that calls one of the functions in the FINUFFT dynamic library. The reason
Expand Down Expand Up @@ -80,14 +59,14 @@
setup(
name='finufft',
version=__version__,
author='python interfaces by: Jeremy Magland, Daniel Foreman-Mackey, Joakim Anden, Libin Lu, and Alex Barnett',
author='Python interfaces by: Jeremy Magland, Daniel Foreman-Mackey, Joakim Anden, Libin Lu, and Alex Barnett',
author_email='[email protected]',
url='http://github.com/ahbarnett/finufft',
description='python interface to FINUFFT',
long_description='python interface to FINUFFT (Flatiron Institute Nonuniform Fast Fourier Transform) library.',
url='https://github.com/flatironinstitute/finufft',
description='Python interface to FINUFFT',
long_description='Python interface to FINUFFT (Flatiron Institute Nonuniform Fast Fourier Transform) library.',
license="Apache 2",
packages=['finufft'],
install_requires=['numpy','python-dotenv'],
install_requires=['numpy'],
zip_safe=False,
py_modules=['finufft/finufftc'],
ext_modules=[
Expand Down

0 comments on commit e64bd19

Please sign in to comment.