Skip to content

Commit 364bc22

Browse files
committed
fix: update .gitignore and .env files, enhance SolrTermInfoFetcher with lazy loading for vfb_connect, and refactor vfb_queries for lazy import of dict_cursor
1 parent 4e1ef28 commit 364bc22

6 files changed

Lines changed: 38 additions & 7 deletions

File tree

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PYTHONPATH=${workspaceFolder}/src
2+
MPLBACKEND=Agg
3+
VISPY_GL_LIB=osmesa
4+
VISPY_USE_EGL=0

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ src/vfbquery/ontology/__pycache__/
88
build/
99
test_examples.py
1010
test_results.py
11+
.vscode
12+
.pytest_cache
13+
.venv
14+
.vscode/settings.json

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
"-s",
66
"./src/test/",
77
"-p",
8-
"*.py"
8+
"*test*.py"
99
],
1010
"python.testing.pytestEnabled": false,
11-
"python.testing.unittestEnabled": true
11+
"python.testing.unittestEnabled": true,
12+
"python.testing.cwd": "${workspaceFolder}",
13+
"python.envFile": "${workspaceFolder}/.env",
14+
"python.terminal.activateEnvironment": true,
15+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
1216
}

src/test/term_info_queries_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_term_info_serialization_individual_anatomy(self):
122122
'reference': '[VFB_00017894,VFB_00010001]'} in serialized["thumbnail"])
123123

124124
def test_term_info_serialization_class(self):
125-
term_info_dict = self.vc.get_TermInfo(['FBbt_00048531'], return_dataframe=False, summary=False)[0]
125+
term_info_dict = self.vc.get_TermInfo(['FBbt_0004853'], return_dataframe=False, summary=False)[0]
126126
print(term_info_dict)
127127
start_time = time.time()
128128
serialized = process(term_info_dict, self.variable)

src/vfbquery/solr_fetcher.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import pandas as pd
55
from typing import List, Dict, Any, Optional, Union
6-
from vfb_connect import vfb
76

87
class SolrTermInfoFetcher:
98
"""Fetches term information directly from the Solr server instead of using VfbConnect"""
@@ -12,7 +11,19 @@ def __init__(self, solr_url: str = "https://solr.virtualflybrain.org/solr/vfb_js
1211
"""Initialize with the Solr server URL"""
1312
self.solr_url = solr_url
1413
self.logger = logging.getLogger(__name__)
15-
self.vfb = vfb
14+
self._vfb = None # Lazy load vfb_connect
15+
16+
@property
17+
def vfb(self):
18+
"""Lazy load vfb_connect to avoid import issues during testing"""
19+
if self._vfb is None:
20+
try:
21+
from vfb_connect import vfb
22+
self._vfb = vfb
23+
except ImportError as e:
24+
self.logger.error(f"Could not import vfb_connect: {e}")
25+
raise ImportError("vfb_connect is required but could not be imported")
26+
return self._vfb
1627

1728
def get_TermInfo(self, short_forms: List[str],
1829
return_dataframe: bool = False,

src/vfbquery/vfb_queries.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
from .term_info_queries import deserialize_term_info
33
# Replace VfbConnect import with our new SolrTermInfoFetcher
44
from .solr_fetcher import SolrTermInfoFetcher
5-
# Keep dict_cursor if it's used elsewhere
6-
from vfb_connect.cross_server_tools import dict_cursor
5+
# Keep dict_cursor if it's used elsewhere - lazy import to avoid GUI issues
76
from marshmallow import Schema, fields, post_load
87
from typing import List, Tuple, Dict, Any, Union
98
import pandas as pd
109
from marshmallow import ValidationError
1110
import json
1211

12+
# Lazy import for dict_cursor to avoid GUI library issues
13+
def get_dict_cursor():
14+
"""Lazy import dict_cursor to avoid import issues during testing"""
15+
try:
16+
from vfb_connect.cross_server_tools import dict_cursor
17+
return dict_cursor
18+
except ImportError as e:
19+
raise ImportError(f"vfb_connect is required but could not be imported: {e}")
20+
1321
# Connect to the VFB SOLR server
1422
vfb_solr = pysolr.Solr('http://solr.virtualflybrain.org/solr/vfb_json/', always_commit=False, timeout=990)
1523

0 commit comments

Comments
 (0)