sczesla / PyAstronomy

A collection of astronomy-related routines in Python
152 stars 35 forks source link

Fix #22: Remove numpy dependency on info setup.py commands. #23

Closed jason-neal closed 7 years ago

jason-neal commented 7 years ago

This checks what setup command is passed. If it is one of the info commands, (e.g. "egg_info") then numpy is not required and so is not imported for dependency determination . Allows dependency determination without numpy, thus resolving #22, allowing pip to install PyAstronomy and numpy at the same time.

Inspired by the setup.py file for scipy.

I have only tested it locally using a fresh conda enviroment (without numpy installed).

Running pip install -e . fails.

$ pip install -e . --no-cache              
Obtaining file:///home/jneal/Phd/Codes/Repos/PyAstronomy
Installing collected packages: PyAstronomy
  Running setup.py develop for PyAstronomy
    Complete output from command /home/jneal/miniconda3/envs/test_pyast/bin/python -c "import setuptools, tokenize;__file__='/home/jneal/Phd/Codes/Repos/PyAstronomy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps:
    Please install 'numpy' first.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/jneal/Phd/Codes/Repos/PyAstronomy/setup.py", line 177, in <module>
        class WithExtCommand(Command):
    NameError: name 'Command' is not defined

    ----------------------------------------
Command "/home/jneal/miniconda3/envs/test_pyast/bin/python -c "import setuptools, tokenize;__file__='/home/jneal/Phd/Codes/Repos/PyAstronomy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps" failed with error code 1 in /home/jneal/Phd/Codes/Repos/PyAstronomy/

but with this PR pip install -e . numpy --no-cache works.

$ pip install -e . numpy --no-cache
Obtaining file:///home/jneal/Phd/Codes/Repos/PyAstronomy
Collecting numpy
  Downloading numpy-1.12.1-cp34-cp34m-manylinux1_x86_64.whl (16.8MB)
    100% |████████████████████████████████| 16.8MB 906kB/s 
Installing collected packages: numpy, PyAstronomy
  Running setup.py develop for PyAstronomy
Successfully installed PyAstronomy numpy-1.12.1

When this is pushed to pypi this should allow PyAstronomy to be placed alongside numpy in a requirements.txt and be installed on fresh environments.

sczesla commented 7 years ago

Hi, Thanks for pointing out and suggesting a fix! Merging the PR in its current form, setup.py stops working for me altogether. Yet, I think the approach is right. I will have a closer look asap. Cheers, Stefan

sczesla commented 7 years ago

Solved in 0.11.0.