pycbc icon indicating copy to clipboard operation
pycbc copied to clipboard

PyCBC missing runtime requirement on setuptools

Open duncanmmacleod opened this issue 2 years ago • 4 comments

I think pycbc should have a runtime requirement on setuptools due to the use of pkg_resources in pycbc.waveform:

https://github.com/gwastro/pycbc/blob/3135d11ad886c6dd66a2b0150f01b0d677ca0e56/pycbc/waveform/init.py#L11

where retrieve_waveform_plugins is defined as:

https://github.com/gwastro/pycbc/blob/3135d11ad886c6dd66a2b0150f01b0d677ca0e56/pycbc/waveform/plugin.py#L61-L64

Without setuptools, you end up with a ModuleNotFoundError:

+ pycbc_live --help
Traceback (most recent call last):
  File "/home/conda/feedstock_root/build_artifacts/pycbc_1646827324458/_test_env/bin/pycbc_live", line 21, in <module>
    from pycbc import fft, version, waveform, scheme, makedir
  File "/home/conda/feedstock_root/build_artifacts/pycbc_1646827324458/_test_env/lib/python3.7/site-packages/pycbc/waveform/__init__.py", line 11, in <module>
    retrieve_waveform_plugins()
  File "/home/conda/feedstock_root/build_artifacts/pycbc_1646827324458/_test_env/lib/python3.7/site-packages/pycbc/waveform/plugin.py", line 64, in retrieve_waveform_plugins
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

duncanmmacleod avatar Mar 09 '22 20:03 duncanmmacleod

@duncanmmacleod I think you are right. Can you clarify how this environment can exist though? I guess we should not rely on this, but is it possible to have a python env without pip / setuptools installed anymore? What does that look like?

ahnitz avatar Mar 10 '22 05:03 ahnitz

Also, not for self, that the suggestion normally is to use importlib.resources (new in python 3.7) which we now can do as we've dropped python3.6 support. That may be the better route here.

https://docs.python.org/3/library/importlib.html#module-importlib.resources

ahnitz avatar Mar 10 '22 05:03 ahnitz

@ahnitz, my example comes from a conda environment. python itself does not depend on pip or setuptools (why would it?) so it can be constructed fairly naturally.

However, most of the time conda itself will artifically inject a dependency between python and pip, see https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#add-pip-python-dependency

duncanmmacleod avatar Mar 10 '22 09:03 duncanmmacleod

Ok, we'll need to rerquire setuptools as we still support python3.7 and the stdlib approach above doesn't work with the APIs we need until python 3.8. See https://docs.python.org/3/library/importlib.metadata.html

ahnitz avatar Mar 12 '22 06:03 ahnitz