Skip to content

Commit

Permalink
fix load_module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaquier Aurélien Tristan committed Oct 7, 2024
1 parent c68f198 commit f572098
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions bluepymm/run_combos/calculate_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def run_emodel_morph(
print('Running e-model %s on morphology %s in %s' %
(emodel, morph_path, emodel_dir))

setup = tools.load_module('setup', emodel_dir)
setup = tools.load_module('setup', os.path.join(emodel_dir, 'setup/__init__.py'))

print("Changing path to %s" % emodel_dir)
with tools.cd(emodel_dir):
Expand Down Expand Up @@ -213,7 +213,10 @@ def create_arg_list(scores_db_filename, emodel_dirs, final_dict,
one_row = scores_db.execute('SELECT * FROM scores LIMIT 1').fetchone()

apical_points_isec = {}
setup = tools.load_module('setup', emodel_dirs[one_row['emodel']])
setup = tools.load_module(
'setup',
os.path.join(emodel_dirs[one_row['emodel']], 'setup/__init__.py')
)
if hasattr(setup, 'multieval') and use_apical_points:
apical_points_isec = tools.load_json(
os.path.join(one_row['morph_dir'], "apical_points_isec.json")
Expand Down
4 changes: 3 additions & 1 deletion bluepymm/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def load_module(name, path):
pass

spec = importlib.util.spec_from_file_location(name, path)
if spec is None:
return None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
sys.modules[name] = module
spec.loader.exec_module(module)
return module


Expand Down
4 changes: 2 additions & 2 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ def test_load_module():
"""bluepymm.tools: test load_module"""
# load module
module_dir = os.path.join(EXAMPLES, 'simple1/data/emodels_dir/subdir/')
setup = tools.load_module('setup', module_dir)
setup = tools.load_module('setup', os.path.join(module_dir, 'setup/__init__.py'))
# try and execute something from loaded module
setup.evaluator.create('emodel1')

# load as file
setup_dir = os.path.join(module_dir, 'setup')
evaluator = tools.load_module('evaluator', setup_dir)
evaluator = tools.load_module('evaluator', os.path.join(setup_dir, 'evaluator.py'))
evaluator.create('emodel1')


Expand Down

0 comments on commit f572098

Please sign in to comment.