brandon-rhodes / python-jplephem

Python version of NASA DE4xx ephemerides, the basis for the Astronomical Alamanac
MIT License
111 stars 29 forks source link

Numpy requirement unclear in metadata #34

Closed thatch closed 4 years ago

thatch commented 4 years ago

Hi Brandon,

This report is a bit vague, for which I apologize in advance.

In the 2.9 sdist, the include PKG-INFO is metadata 1.1 which has a field Requres, which checks out.

Metadata-Version: 1.1
...
Requires: numpy

If I use pip wheel . (actually as part of further automation) I end up with a wheel whose METADATA file is

Metadata-Version: 2.1
...
Requires: numpy

while it should be Requires-Dist per 1.2 or 2.1 metadata version. Moving the setup.py to use setuptools and changing requires to install_requires makes it produce a consistent metadata

Metadata-Version: 2.1
...
Requires-Dist: numpy

While I suspect this is a bug/interaction in pip or wheel, I'm wondering if there's a specific reason to stay on distutils in 2019?

thatch commented 4 years ago

This also appears to affect the json endpoint on pypi that poetry uses for resolving dependencies, https://pypi.org/pypi/jplephem/json

brandon-rhodes commented 4 years ago

While I suspect this is a bug/interaction in pip or wheel, I'm wondering if there's a specific reason to stay on distutils in 2019?

The jplephem library intends to support bare Python 2.7 installs without 3rd party tools, which means that setuptools would not be available. (I also like to remain 2.6 compatible when possible, but I note that jplephem does not explicitly advertise 2.6 compatibility nor test for it from what I can see.) Some tools use a try…except in their setup.py, but this has the unhappy result that a different dist is produced depending on circumstances.

What error is resulting from the distutils compatibility — is your install tool ignoring the requirement?

thatch commented 4 years ago

Yes, while jplephem gets installed, the metadata doesn't record the dependency on numpy. You don't need any of my code to repro, this appears to happen with standard tools like pip 19.1.1 (on Fedora with its standard python 3.7.5):

python -m venv tmp
source tmp/bin/activate
pip install jplephem
python -c 'import jplephem'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "[edited]/tmp/lib64/python3.7/site-packages/jplephem/__init__.py", line 410, in <module>
    from .ephem import Ephemeris, DateError
  File "[edited]/tmp/lib64/python3.7/site-packages/jplephem/ephem.py", line 13, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'
thatch commented 4 years ago

This doesn't appear to be wheel-specific; the only setuptools bug I can find related to this is https://github.com/pypa/setuptools/issues/1396 which sounds like they'd prefer an error. I can work around this by accepting an amgalmation of metadata 1.2 and 2.1, but your users likely aren't.

brandon-rhodes commented 4 years ago

After an overly busy December, I now have time to sit down and get this resolved. I am currently unable to reproduce the problem, though. Using a fresh virtual environment, I ran the commands:

$ pip install pip==19.1.1
Collecting pip==19.1.1
  Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.3.1
    Uninstalling pip-19.3.1:
      Successfully uninstalled pip-19.3.1
Successfully installed pip-19.1.1
$ pip --version
pip 19.1.1 from /home/brandon/.v/t/lib/python3.7/site-packages/pip (python 3.7)
$ python --version
Python 3.7.3
$ pip install ~/jplephem/dist/jplephem-2.12.tar.gz
Processing /home/brandon/jplephem/dist/jplephem-2.12.tar.gz
Collecting numpy (from jplephem==2.12)
  Downloading https://files.pythonhosted.org/packages/63/0c/0261693cc3ad8e2b66e66dc2d2676a2cc17d3efb1c58a70db73754320e47/numpy-1.18.1-cp37-cp37m-manylinux1_x86_64.whl (20.1MB)
     |################################| 20.1MB 3.7MB/s 
Building wheels for collected packages: jplephem
  Building wheel for jplephem (setup.py) ... done
  Stored in directory: /home/brandon/.cache/pip/wheels/28/9d/1d/4bc9ca2fe3002c652e29deb993aaf9a815e249d8b2f9b64a48
Successfully built jplephem
Installing collected packages: numpy, jplephem
Successfully installed jplephem-2.12 numpy-1.18.1
WARNING: You are using pip version 19.1.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I get the same correct behavior if I pip install jplephem and let jplephem download from PyPI.

I have never personally encountered a pip that did not install NumPy when installing jplephem, and am not sure how to diagnose your situation. Could you show the output of the pip command when you run it?

thatch commented 4 years ago

I'll need to poke into the Fedora environment more, because I can't repro on Arch either: http://ix.io/277s

brandon-rhodes commented 4 years ago

Thank you for checking Arch to add another data point! I'll watch the issue for an update once you figure out what's happening on Fedora.

thatch commented 4 years ago

I think I know what's going on here. The environment on fedora used a bandersnatch that was probably behind by a day or so, so didn't have 2.10 yet when I reported the issue. (note "In the 2.9 sdist" in the OP)

I can repro installing jplephem==2.9 on Arch, and this is fixed by your commit https://github.com/brandon-rhodes/python-jplephem/commit/4bc4e355e867609adafccd16e50bd98f186c8cc9 which made it into 2.10. I think it's all good now.

brandon-rhodes commented 4 years ago

Thanks so much for checking back in and not leaving the issue dangling! I'm glad the library is working for you now.