You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
setup.py imports numpy, but in a clean environment, this is not installed, and setup.py (or pip) will fail. pip can install NumPy (and Cython) automatically, but only if given as a requirement in setup.py, and if numpy is conditionally imported.
A possible solution, albeit not pretty, is given in the diff below.
There may be various other, cleaner solutions (this solution is a few years old by now, copied-pasted from some old code I have lying around). The given solution avoids the numpy import for a selected few commands, which happen to be (among others) commands that pip uses to determine the package requirements from the install_requires parameter in setup().
It can be argued that NumPy and Cython should simply have been installed before installing sep, but it's nice, for example, to just run pip install sep in a virtual-env without requiring to run any other installation commands.
The use of Miniconda in the Travis and Appveyor tests hides this issue, so if this were fixed, the Travis and Appveyor tests should possibly also be adjusted, possibly using a bare-bones Python version instead.
diff --git a/setup.py b/setup.py
index dd78691..e9bd205 100755
--- a/setup.py
+++ b/setup.py
@@ -1,11 +1,12 @@
#!/usr/bin/env python
import os
+import sys
from glob import glob
from distutils.core import setup
from distutils.extension import Extension
+from distutils.dist import Distribution
import re
-import numpy
if os.path.exists("sep.pyx"):
USE_CYTHON = True
@@ -14,14 +15,21 @@ else:
USE_CYTHON = False
fname = "sep.c"
-sourcefiles = [fname] + glob(os.path.join("src", "*.c"))
-headerfiles = glob(os.path.join("src", "*.h"))
-include_dirs=[numpy.get_include(), "src"]
-extensions = [Extension("sep", sourcefiles, include_dirs=include_dirs,
- depends=headerfiles)]
-if USE_CYTHON:
- from Cython.Build import cythonize
- extensions = cythonize(extensions)
+if (any('--' + opt in sys.argv for opt in Distribution.display_option_names +
+ ['help-commands', 'help']) or len(sys.argv) == 1
+ or sys.argv[1] in ('egg_info', 'clean', 'help')):
+ extensions=[]
+else:
+ import numpy
+
+ sourcefiles = [fname] + glob(os.path.join("src", "*.c"))
+ headerfiles = glob(os.path.join("src", "*.h"))
+ include_dirs=[numpy.get_include(), "src"]
+ extensions = [Extension("sep", sourcefiles, include_dirs=include_dirs,
+ depends=headerfiles)]
+ if USE_CYTHON:
+ from Cython.Build import cythonize
+ extensions = cythonize(extensions)
# Synchronize version from code.
version = re.findall(r"__version__ = \"(.*?)\"", open(fname).read())[0]
@@ -38,7 +46,7 @@ classifiers = [
"Topic :: Scientific/Engineering :: Astronomy",
"Intended Audience :: Science/Research"]
-setup(name="sep",
+setup(name="sep",
version=version,
description=description,
long_description=long_description,
@@ -47,4 +55,5 @@ setup(name="sep",
url="https://github.com/kbarbary/sep",
author="Kyle Barbary",
author_email="[email protected]",
+ install_requires=['numpy', 'Cython'],
ext_modules=extensions)
The text was updated successfully, but these errors were encountered:
setup.py
importsnumpy
, but in a clean environment, this is not installed, andsetup.py
(orpip
) will fail.pip
can install NumPy (and Cython) automatically, but only if given as a requirement insetup.py
, and ifnumpy
is conditionally imported.A possible solution, albeit not pretty, is given in the diff below.
There may be various other, cleaner solutions (this solution is a few years old by now, copied-pasted from some old code I have lying around). The given solution avoids the
numpy
import for a selected few commands, which happen to be (among others) commands thatpip
uses to determine the package requirements from theinstall_requires
parameter insetup()
.It can be argued that NumPy and Cython should simply have been installed before installing sep, but it's nice, for example, to just run
pip install sep
in a virtual-env without requiring to run any other installation commands.The use of Miniconda in the Travis and Appveyor tests hides this issue, so if this were fixed, the Travis and Appveyor tests should possibly also be adjusted, possibly using a bare-bones Python version instead.
The text was updated successfully, but these errors were encountered: