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

[5.0RC1] utils.minversion("astropy", "5.0") doesn't work (and seems unneeded?) #12377

Closed
olebole opened this issue Nov 3, 2021 · 7 comments · Fixed by #12383
Closed

[5.0RC1] utils.minversion("astropy", "5.0") doesn't work (and seems unneeded?) #12377

olebole opened this issue Nov 3, 2021 · 7 comments · Fixed by #12383
Assignees
Milestone

Comments

@olebole
Copy link
Member

olebole commented Nov 3, 2021

Description

When building the Debian package, the tests are run on the built but not installed package. In this case, I get the following error:

cd '/build/astropy-5.0~rc1/.pybuild/cpython3_3.9/build'; python3.9 -m pytest 
[…]
astropy/utils/introspection.py:157: in minversion
    module_version = metadata.version(module_name)
/usr/lib/python3.9/importlib/metadata.py:551: in version
    return distribution(distribution_name).version
/usr/lib/python3.9/importlib/metadata.py:524: in distribution
    return Distribution.from_name(distribution_name)
/usr/lib/python3.9/importlib/metadata.py:187: in from_name
    raise PackageNotFoundError(name)
E   importlib.metadata.PackageNotFoundError: astropy

During handling of the above exception, another exception occurred:
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:972: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:228: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1030: in _gcd_import
    ???
<frozen importlib._bootstrap>:1007: in _find_and_load
    ???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:680: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:850: in exec_module
    ???
<frozen importlib._bootstrap>:228: in _call_with_frames_removed
    ???
astropy/cosmology/tests/__init__.py:7: in <module>
    import mypackage
astropy/cosmology/tests/mypackage/__init__.py:1: in <module>
    from . import cosmology, io
astropy/cosmology/tests/mypackage/io/__init__.py:20: in <module>
    ASTROPY_GE_5 = minversion("astropy", "5.0")
astropy/utils/decorators.py:547: in wrapper
    return function(*args, **kwargs)
astropy/utils/introspection.py:164: in minversion
    module_version = metadata.version(dist_names[module_name][0])
E   KeyError: 'astropy'

Aside from the error itself, I am wondering why we need to check for the version here at all?

Expected behavior

Tests should pass; I would expect this even on a non-installed Astropy.

Actual behavior

See above

Steps to Reproduce

  1. Build the package with python3 setup.py build
  2. cd to the build dir; python3.9 -m pytest

System Details

Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.0

Platform: Linux-5.14.0-2-amd64-x86_64-with-glibc2.32

Full Python Version:
3.9.7 (default, Sep 24 2021, 09:43:00)
[GCC 10.3.0]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions:
Numpy: 1.19.5
Scipy: 1.7.1
Matplotlib: 3.3.4
h5py: not available
Pandas: not available
PyERFA: 2.0.0
Cython: 0.29.24
Scikit-image: not available
asdf: not available
pyarrow: not available

Using Astropy options: remote_data: none.

Matplotlib: 3.3.4
Freetype: 2.11.0
ARCH_ON_CI: undefined
IS_CRON: undefined

rootdir: /build/astropy-5.0~rc1, configfile: setup.cfg
plugins: astropy-header-0.1.2, hypothesis-5.43.3, arraydiff-0.3, mpl-0.11, filter-subpackage-0.1.1, cov-3.0.0, doctestplus-0.11.0, remotedata-0.3.2, mock-3.6.1, openfiles-0.5.0

@olebole olebole added the Bug label Nov 3, 2021
@pllim pllim added the utils label Nov 3, 2021
@pllim
Copy link
Member

pllim commented Nov 3, 2021

Yeah, minversion was refactored in #11714 so its behavior is different now. Maybe @saimn can advise?

@pllim pllim added this to the v5.0 milestone Nov 3, 2021
@pllim
Copy link
Member

pllim commented Nov 3, 2021

I am putting a v5.0 milestone here in case this will block actual release. Please remove it if that is not the case. Thanks!

@saimn
Copy link
Contributor

saimn commented Nov 3, 2021

I don't understand why this is needed in the cosmology tests, @nstarman ?
If we need to keep it, we could use instead import astropy; minversion(astropy, ....) since minversion would then use the __version__ attribute.

@nstarman
Copy link
Member

nstarman commented Nov 3, 2021

All this comes from https://docs.astropy.org/en/latest/cosmology/dev.html#astropy-cosmology-for-developers
where I walk through how the maintainer of another cosmology package (e.g. cosmolopy) can register their file formats with Astropy I/O and more importantly the ability to convert cosmology objects between the their package and Astropy.
3rd party packages would need to check Astropy's minimum version, if it's even installed.

@nstarman nstarman self-assigned this Nov 3, 2021
@astrofrog
Copy link
Member

@pllim just to confirm, this is definitely a release blocker as it is causing issues with Debian packaging

@nstarman
Copy link
Member

nstarman commented Nov 3, 2021

I'll push a fix that does

try:
    import astropy
    from astropy.utils.introspection import minversion
except ImportError:
    ASTROPY_GE_5 = False
else:
    ASTROPY_GE_5 = minversion(astropy, "5.0")

It used to do

try:
    from astropy.utils.introspection import minversion
except ImportError:
    ASTROPY_GE_5 = False
else:
    ASTROPY_GE_5 = minversion("astropy", "5.0")

@nstarman nstarman mentioned this issue Nov 3, 2021
9 tasks
@olebole
Copy link
Member Author

olebole commented Nov 4, 2021

Thanks to @nstarman for the quick fix!

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

Successfully merging a pull request may close this issue.

5 participants