Skip to content

Commit

Permalink
Migrate pkg_resources to importlib_resources (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkilic authored May 16, 2024
1 parent d06e158 commit 11275af
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
9 changes: 5 additions & 4 deletions bluepyemodel/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"""

import csv
from importlib import resources

import numpy as np
import pkg_resources


def get_dendritic_data_filepath(data_type):
Expand All @@ -32,11 +32,12 @@ def get_dendritic_data_filepath(data_type):
ValueError if data_type is not 'ISI_CV' nor 'rheobase'
"""
if data_type == "ISI_CV":
return pkg_resources.resource_filename(__name__, "ISI_CV_Shai2015.csv")
return resources.files("bluepyemodel").joinpath("data", "ISI_CV_Shai2015.csv")
if data_type == "rheobase":
return pkg_resources.resource_filename(
__name__, "spike_rheobase_pA_BeaulieuLaroche2021.csv"
return resources.files("bluepyemodel").joinpath(
"data", "spike_rheobase_pA_BeaulieuLaroche2021.csv"
)

raise ValueError(f"read_data expects 'ISI_CV' or 'rheobase' but got {data_type}")


Expand Down
7 changes: 4 additions & 3 deletions bluepyemodel/ecode/noiseou3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"""

import logging
from importlib import resources

import numpy
import pkg_resources

from bluepyemodel.ecode.noise import NoiseMixin

Expand Down Expand Up @@ -55,8 +55,9 @@ def __init__(self, location, **kwargs):
if data_filepath is not None:
series = numpy.loadtxt(data_filepath)
else:
series_file = pkg_resources.resource_filename(__name__, "data/NoiseOU3.txt")
series = numpy.loadtxt(series_file)
resource = resources.files("bluepyemodel").joinpath("ecode", "data", "NoiseOU3.txt")
with open(resource, "r") as f:
series = numpy.loadtxt(f)

self.current_series = series[:, 1]
self.time_series = series[:, 0]
Expand Down
9 changes: 6 additions & 3 deletions bluepyemodel/ecode/subwhitenoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"""

import logging
from importlib import resources

import numpy
import pkg_resources

from bluepyemodel.ecode.stimulus import BPEM_stimulus

Expand Down Expand Up @@ -62,8 +62,11 @@ def __init__(self, location, **kwargs):
if data_filepath is not None:
series = numpy.loadtxt(data_filepath)
else:
series_file = pkg_resources.resource_filename(__name__, "data/SubWhiteNoise.txt")
series = numpy.loadtxt(series_file)
resource = resources.files("bluepyemodel").joinpath(
"ecode", "data", "SubWhiteNoise.txt"
)
with open(resource, "r") as f:
series = numpy.loadtxt(f)

self.current_series = series[:, 1]
self.time_series = series[:, 0]
Expand Down
7 changes: 4 additions & 3 deletions bluepyemodel/ecode/whitenoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"""

import logging
from importlib import resources

import numpy
import pkg_resources

from bluepyemodel.ecode.noise import NoiseMixin

Expand Down Expand Up @@ -55,8 +55,9 @@ def __init__(self, location, **kwargs):
if data_filepath is not None:
series = numpy.loadtxt(data_filepath)
else:
series_file = pkg_resources.resource_filename(__name__, "data/WhiteNoise.txt")
series = numpy.loadtxt(series_file)
resource = resources.files("bluepyemodel").joinpath("ecode", "data", "WhiteNoise.txt")
with open(resource, "r") as f:
series = numpy.loadtxt(f)

self.current_series = series[:, 1]
self.time_series = series[:, 0]
Expand Down
1 change: 1 addition & 0 deletions bluepyemodel/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def define_distributions(distributions_definition, morphology=None):
Args:
distributions_definition (list): definitions of the distributions
"""
hotspot_begin, hotspot_end = None, None
if any(definition.name == "step" for definition in distributions_definition):
hotspot_begin, hotspot_end = get_hotspot_location(morphology.morphology_path)
distributions = collections.OrderedDict()
Expand Down
2 changes: 2 additions & 0 deletions bluepyemodel/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def parse_legacy_checkpoint_path(path):
"iteration": None,
"ttype": None,
}
else:
raise ValueError(f"Invalid checkpoint path: {path}")

return checkpoint_metadata

Expand Down
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

sys.path.insert(0, os.path.abspath("../../."))

from pkg_resources import get_distribution
from importlib.metadata import version


# -- Project information -----------------------------------------------------
Expand All @@ -24,7 +24,7 @@
author = "Blue Brain Project/EPFL"

# The short X.Y version
version = get_distribution("bluepyemodel").version
version = version("bluepyemodel")

# The full version, including alpha/beta/rc tags
release = version
Expand Down

0 comments on commit 11275af

Please sign in to comment.