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

DM-37534: Ensure that pex_exceptions is imported for afw.fits #678

Merged
merged 1 commit into from Jan 30, 2023

Conversation

timj
Copy link
Member

@timj timj commented Jan 27, 2023

Without this it is not possible to "import lsst.afw.fits" because the FitsError is not translated to python. Tests passed in afw because other parts of afw were importing pex_exceptions.

@timj
Copy link
Member Author

timj commented Jan 27, 2023

This is the error without this change:

Traceback:
../../miniconda/envs/lsst-scipipe-5.0.0/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
python/lsst/obs/base/__init__.py:22: in <module>
    from ._fitsRawFormatterBase import *
python/lsst/obs/base/_fitsRawFormatterBase.py:27: in <module>
    import lsst.afw.fits
../../stack/lsst-scipipe-5.0.0/Darwin/afw/g87b8406481+bd7147d3c6/python/lsst/afw/fits/__init__.py:22: in <module>
    from ._fits import *
E   ImportError: generic_type: type "FitsError" referenced unknown base type "lsst::pex::exceptions::IoError"

@mwittgen I was under the impression that this line https://github.com/lsst/afw/blob/main/python/lsst/afw/fits/_fits.cc#L286 means that the python import was not needed. Seems I was wrong.

@timj timj requested a review from mwittgen January 30, 2023 17:22
@timj
Copy link
Member Author

timj commented Jan 30, 2023

Looking at the code, we currently have explicit mentions of lsst.pex.exceptions in 5 places so we don't seem to attempt to always ensure that it's imported when we have defined a C++ exception. In lsst.afw.fits we have:

wrappers.addSignatureDependency("lsst.pex.exceptions");

and that doesn't seem to have the effect of importing pex_exceptions. In meas_base we have:

py::module::import("lsst.pex.exceptions");

which is explicit about it.

@mwittgen
Copy link
Contributor

wrappers.addSignatureDependency("lsst.pex.exceptions");

This should be
wrappers.addInheritanceDependency("lsst.pex.exceptions");

The reason is

LSST_EXCEPTION_TYPE(FitsError, lsst::pex::exceptions::IoError, lsst::afw::fits::FitsError)

the fitsError class, etc inheriting from lsst::pex::exceptions classes

Without this it is not possible to "import lsst.afw.fits"
because the FitsError is not translated to python.
Tests passed previously in afw because other parts of afw were importing
pex_exceptions.
@timj
Copy link
Member Author

timj commented Jan 30, 2023

@mwittgen changing does fix the problem. I also fixed afw.geom since that was also trying to export a wrapped exception. Please take another look.

Copy link
Contributor

@mwittgen mwittgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and this is correcting an earlier mistake of mine.

@timj timj merged commit 4287475 into main Jan 30, 2023
@timj timj deleted the tickets/DM-37534 branch January 30, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants