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

Switch to the open-sourced brain-indexer #272

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions bluepysnap/edges/edge_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,7 @@ def h5_filepath(self):
@cached_property
def spatial_synapse_index(self):
"""Access to edges spatial index."""
try:
from spatial_index import open_index
except ImportError as e:
raise BluepySnapError(
(
"Spatial index is for now only available internally to BBP. "
"It requires `spatial_index`, an internal package."
)
) from e
from brain_indexer import open_index

index_dir = self._properties.spatial_synapse_index_dir
if not index_dir:
Expand Down
10 changes: 1 addition & 9 deletions bluepysnap/nodes/node_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,7 @@ def h5_filepath(self):
@cached_property
def spatial_segment_index(self):
"""Access to edges spatial index."""
try:
from spatial_index import open_index
except ImportError as e:
raise BluepySnapError(
(
"Spatial index is for now only available internally to BBP. ",
"It requires `spatial_index`, an internal package.",
)
) from e
from brain_indexer import open_index

index_dir = self._properties.spatial_segment_index_dir
if not index_dir:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, *args, **kwargs):
name="bluepysnap",
python_requires=">=3.8",
install_requires=[
"brain-indexer>=3.0.0",
"cached_property>=1.0",
"h5py>=3.0.1,<4.0.0",
"importlib_resources>=5.0.0",
Expand All @@ -58,7 +59,6 @@ def __init__(self, *args, **kwargs):
extras_require={
"docs": ["sphinx", "sphinx-bluebrain-theme"],
"plots": ["matplotlib>=3.0.0"],
"spatial-index": ["spatial-index>=1.2.1"],
},
packages=find_packages(),
package_data={
Expand Down
21 changes: 2 additions & 19 deletions tests/test_edge_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,30 +728,13 @@ def test_iter_connection_unique(self):
def test_h5_filepath_from_config(self):
assert self.test_obj.h5_filepath == str(TEST_DATA_DIR / "edges.h5")

@pytest.mark.skip(reason="Until spatial-index is released publicly")
def test_spatial_synapse_index(self):
mgeplf marked this conversation as resolved.
Show resolved Hide resolved
with mock.patch("spatial_index.open_index") as mock_open_index:
self.test_obj.spatial_synapse_index
mock_open_index.assert_called_once_with("path/to/edge/dir")

@mock.patch.dict(sys.modules, {"spatial_index": mock.Mock()})
def test_spatial_synapse_index_call(self):
with pytest.raises(
BluepySnapError,
match="It appears default does not have synapse indices",
):
self.test_obj.spatial_synapse_index

def test_spatial_synapse_index_error(self):
with pytest.raises(
BluepySnapError,
match=(
"Spatial index is for now only available internally to BBP. "
"It requires `spatial_index`, an internal package."
),
):
self.test_obj.spatial_synapse_index

def test_pickle(self, tmp_path):
pickle_path = tmp_path / "pickle.pkl"

Expand All @@ -776,9 +759,9 @@ def setup_method(self):
TEST_DATA_DIR / "circuit_config.json", "default2"
)

@mock.patch.dict(sys.modules, {"spatial_index": mock.Mock()})
@mock.patch.dict(sys.modules, {"brain_indexer": mock.Mock()})
def test_spatial_synapse_index_call(self):
self.test_obj.spatial_synapse_index
mock = sys.modules["spatial_index"].open_index
mock = sys.modules["brain_indexer"].open_index
assert mock.call_count == 1
assert mock.call_args[0][0].endswith("path/to/edge/dir")
20 changes: 3 additions & 17 deletions tests/test_node_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,9 @@ def test_models(self):
def test_h5_filepath_from_config(self):
assert self.test_obj.h5_filepath == str(TEST_DATA_DIR / "nodes.h5")

@pytest.mark.skip(reason="Until spatial-index is released publicly")
def test_spatial_segment_index(self):
with mock.patch("spatial_index.open_index") as mock_open_index:
self.test_obj.spatial_segment_index
mock_open_index.assert_called_once_with("path/to/node/dir")

@mock.patch.dict(sys.modules, {"spatial_index": mock.Mock()})
def test_spatial_segment_index_call(self):
with pytest.raises(
BluepySnapError,
match="It appears default does not have segment indices",
):
self.test_obj.spatial_segment_index

def test_spatial_segment_index_error(self):
with pytest.raises(
BluepySnapError, match="Spatial index is for now only available internally to BBP."
BluepySnapError, match="It appears default does not have segment indices"
):
self.test_obj.spatial_segment_index

Expand Down Expand Up @@ -718,10 +704,10 @@ class TestNodePopulationSpatialIndex:
def setup_method(self):
self.test_obj = Circuit(str(TEST_DATA_DIR / "circuit_config.json")).nodes["default2"]

@mock.patch.dict(sys.modules, {"spatial_index": mock.Mock()})
@mock.patch.dict(sys.modules, {"brain_indexer": mock.Mock()})
def test_spatial_segment_index_call(self):
self.test_obj.spatial_segment_index

mock = sys.modules["spatial_index"].open_index
mock = sys.modules["brain_indexer"].open_index
assert mock.call_count == 1
assert mock.call_args[0][0].endswith("path/to/node/dir")
8 changes: 5 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil
import tempfile
from contextlib import contextmanager
from distutils.dir_util import copy_tree
from pathlib import Path

import numpy.testing as npt
Expand All @@ -24,7 +23,7 @@

@contextmanager
def setup_tempdir(cleanup=True):
temp_dir = str(Path(tempfile.mkdtemp()).resolve())
temp_dir = Path(tempfile.mkdtemp()).resolve()
try:
yield temp_dir
finally:
Expand All @@ -41,7 +40,10 @@ def copy_test_data(config="circuit_config.json"):
yields a path to the copy of the config file
"""
with setup_tempdir() as tmp_dir:
copy_tree(str(TEST_DATA_DIR), tmp_dir)
# shutil.copytree expects the target to not exist
if tmp_dir.exists():
tmp_dir.rmdir()
shutil.copytree(str(TEST_DATA_DIR), tmp_dir)
copied_path = Path(tmp_dir)
yield copied_path, copied_path / config

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = bluepysnap
[tox]
envlist =
lint
py{38,39,310,311}
py{39,310,311,312}

ignore_basepython_conflict = true

Expand Down
Loading