Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation does not bootstrap properly #58

Open
evertrol opened this issue Apr 25, 2018 · 1 comment
Open

Installation does not bootstrap properly #58

evertrol opened this issue Apr 25, 2018 · 1 comment

Comments

@evertrol
Copy link
Contributor

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="kylebarbary@gmail.com",
+      install_requires=['numpy', 'Cython'],
       ext_modules=extensions)
@kbarbary
Copy link
Owner

This makes sense. In the past (before wheels) I guess this wasn't an issue because no one ever wanted to let pip compile numpy from source!

Care to turn this into a PR? (maybe add a comment explaining why we branch on the command line arguments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants