diff --git a/bluecellulab/cell/ballstick/__init__.py b/bluecellulab/cell/ballstick/__init__.py index 451aab64..cbfd0690 100644 --- a/bluecellulab/cell/ballstick/__init__.py +++ b/bluecellulab/cell/ballstick/__init__.py @@ -1,11 +1,11 @@ """A simple ball and stick model.""" -import pkg_resources +import importlib_resources as resources from bluecellulab.cell import Cell def create_ball_stick() -> Cell: """Creates a ball and stick model by using package's hoc and asc.""" - hoc = pkg_resources.resource_filename("bluecellulab", "cell/ballstick/emodel.hoc") - morphology = pkg_resources.resource_filename("bluecellulab", "cell/ballstick/morphology.asc") + hoc = resources.files("bluecellulab") / "cell/ballstick/emodel.hoc" + morphology = resources.files("bluecellulab") / "cell/ballstick/morphology.asc" return Cell(template_path=hoc, morphology_path=morphology) diff --git a/bluecellulab/importer.py b/bluecellulab/importer.py index d982ca22..0052793c 100644 --- a/bluecellulab/importer.py +++ b/bluecellulab/importer.py @@ -13,10 +13,10 @@ # limitations under the License. """Main importer of bluecellulab.""" +import importlib_resources as resources import logging import os from types import ModuleType -import pkg_resources import neuron @@ -62,7 +62,7 @@ def import_neurodamus(neuron: ModuleType) -> None: ] for hoc_file in hoc_files: - hoc_file_path = pkg_resources.resource_filename("bluecellulab", f"hoc/{hoc_file}") + hoc_file_path = str(resources.files("bluecellulab") / f"hoc/{hoc_file}") neuron.h.load_file(hoc_file_path) diff --git a/tests/test_importer.py b/tests/test_importer.py index eb916adf..5976d259 100644 --- a/tests/test_importer.py +++ b/tests/test_importer.py @@ -1,5 +1,6 @@ import logging import os +from pathlib import Path import pytest from types import ModuleType from unittest.mock import MagicMock, patch @@ -51,16 +52,16 @@ def test_import_mod_lib_no_env_with_folder(): @patch.object( - importer.pkg_resources, - "resource_filename", - return_value="/fake/path/to/hoc_file.hoc", + importer.resources, + "files", + return_value=Path("/fake/path/"), ) -def test_import_neurodamus(mocked_pkg_resources): +def test_import_neurodamus(mocked_resources): mock_neuron = MagicMock() importer.import_neurodamus(mock_neuron) assert mock_neuron.h.load_file.called # Check that it was called with the expected arguments - mock_neuron.h.load_file.assert_any_call("/fake/path/to/hoc_file.hoc") + mock_neuron.h.load_file.assert_any_call("/fake/path/hoc/Cell.hoc") def test_print_header(caplog):