spacetelescope / stsynphot_refactor

Synthetic photometry using Astropy for HST and JWST
http://stsynphot.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
14 stars 10 forks source link

fix for `collections` import deprecation #163

Closed zacharyburnett closed 2 years ago

zacharyburnett commented 2 years ago

Description

Direct import from collections is deprecated in Python 3.10. This causes the environment testing in https://github.com/spacetelescope/spacetelescope-env-distribution to fail:

/usr/share/miniconda/envs/spacetelescope-env-Linux-py3.10-latest/lib/python3.10/site-packages/stsynphot/commissioning/utils.py:6: in <module>
[29](https://github.com/spacetelescope/spacetelescope-env-distribution/runs/7429139594?check_suite_focus=true#step:11:30)
    from collections import Iterable
[30](https://github.com/spacetelescope/spacetelescope-env-distribution/runs/7429139594?check_suite_focus=true#step:11:31)
E   ImportError: cannot import name 'Iterable' from 'collections' (/usr/share/miniconda/envs/spacetelescope-env-Linux-py3.10-latest/lib/python3.10/collections/__init__.py)

https://github.com/spacetelescope/spacetelescope-env-distribution/runs/7429139594?check_suite_focus=true#step:11:31

The solution is to import from collections.abc instead.

codecov[bot] commented 2 years ago

Codecov Report

Merging #163 (7c007f9) into master (272061b) will not change coverage. The diff coverage is 50.00%.

@@           Coverage Diff           @@
##           master     #163   +/-   ##
=======================================
  Coverage   84.87%   84.87%           
=======================================
  Files          13       13           
  Lines        1633     1633           
=======================================
  Hits         1386     1386           
  Misses        247      247           
Impacted Files Coverage Δ
stsynphot/commissioning/utils.py 29.82% <50.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 272061b...7c007f9. Read the comment docs.

pllim commented 2 years ago

Good catch but I have a question as stated in the code comment.

Also, why is your test suite importing from the commissioning folder?

zacharyburnett commented 2 years ago

Also, why is your test suite importing from the commissioning folder?

It looks like this is happening during pytest test discovery, as I called pytest --pyargs stsynphot to test the package within the environment. So, when it collects tests from commissioning/tests, it runs through import of commissioning/__init__.py -> commissioning/utils.py -> this error

pllim commented 2 years ago

To exclude commissioning folder, please see the tox.ini defined in this repo. Your test suite needs to pick this up:

https://github.com/spacetelescope/stsynphot_refactor/blob/272061b0f5db3dcffa41857bab9cc8dd31a22cd0/setup.cfg#L4