Skip to content

Improve import handling for QtPy#656

Open
kif wants to merge 4 commits into
mainfrom
654_import_qtpy
Open

Improve import handling for QtPy#656
kif wants to merge 4 commits into
mainfrom
654_import_qtpy

Conversation

@kif

@kif kif commented Jun 18, 2026

Copy link
Copy Markdown
Member

Modified import statements to handle potential ImportError for QtPy.

Close # 654

kif added 4 commits June 18, 2026 16:35
Modified import statements to handle potential ImportError for QtPy.

Close # 654
Add error handling for QtPy import failure
Handle ImportError for qtpy and manage environment variable for testing.
Wrap Qt imports in a try-except block to handle ImportError and check environment variable.
@kif

kif commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

@t20100
I don't especially like this approach, but maybe you have some suggestion to silent-out ImportError when importing a module.

One could have QtPy available inside fabio as a single entry-point if this is finally accepted.

@kif kif requested a review from t20100 June 18, 2026 14:56
@kif

kif commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

I twisted CI, now tests are passing, this is probably not useful, at least not for this release.

@t20100

t20100 commented Jun 19, 2026

Copy link
Copy Markdown
Member

If it's only for the import_all filter, why not handling this in this test by skipping the files requiring QtPy when WITH_QT_TEST is false?

something like:

def test_import_all(self):
    import fabio

    skip_without_qt = {
        "fabio.app.viewer",
        "fabio.qt.dialogs",
        "fabio.qt.matplotlib",
    }
    with_qt = os.environ.get("WITH_QT_TEST", "True").lower() not in ("0", "false", "no")

    base = os.path.split(fabio.__path__[0])[0] + "/"
    for root, dirs, files in os.walk(fabio.__path__[0]):
        for f in files:
            if f.endswith(".py"):
                module = os.path.join(root, f[:-3])[len(base):].replace(os.sep, ".")
                if not with_qt and module in skip_without_qt:
                    continue
                __import__(module)

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.

2 participants