Skip to content

Commit

Permalink
Use importlib instead of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreso committed Dec 19, 2023
1 parent aafad9b commit 60d4ff8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies=[
"resdata",
"fastapi",
"filelock",
"importlib_resources;python_version <= '3.8'",
"iterative_ensemble_smoother==0.2.0",
"typing_extensions",
"jinja2",
Expand Down
11 changes: 7 additions & 4 deletions src/ert/gui/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import functools
import logging
import os
import sys
import warnings
import webbrowser
from signal import SIG_DFL, SIGINT, signal
from typing import Optional, cast

import pkg_resources
if sys.version_info >= (3, 9):
from importlib.resources import files
else:
from importlib_resources import files

from PyQt5.QtGui import QIcon
from qtpy.QtCore import QDir, QLocale, Qt
from qtpy.QtWidgets import (
Expand Down Expand Up @@ -55,9 +60,7 @@ def run_gui(args: Namespace, plugin_manager: Optional[ErtPluginManager] = None):
# happen in Qt slots.
signal(SIGINT, SIG_DFL)

QDir.addSearchPath(
"img", pkg_resources.resource_filename("ert.gui", "resources/gui/img")
)
QDir.addSearchPath("img", str(files("ert.gui").joinpath("resources/gui/img")))

app = QApplication([]) # Early so that QT is initialized before other imports
app.setWindowIcon(QIcon("img:application/window_icon_cutout"))
Expand Down
10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from typing import TYPE_CHECKING, cast
from unittest.mock import MagicMock

import pkg_resources
if sys.version_info >= (3, 9):
from importlib.resources import files
else:
from importlib_resources import files

import pytest
from hypothesis import HealthCheck, settings
from qtpy.QtCore import QDir
Expand All @@ -31,9 +35,7 @@
@pytest.fixture
def _qt_add_search_paths(qapp):
"Ensure that icons and such are found by the tests"
QDir.addSearchPath(
"img", pkg_resources.resource_filename("ert.gui", "resources/gui/img")
)
QDir.addSearchPath("img", str(files("ert.gui").joinpath("resources/gui/img")))


# Timeout settings are unreliable both on CI and
Expand Down

0 comments on commit 60d4ff8

Please sign in to comment.