Skip to content

BF: Load gifti parser iff parsing gifti files #405

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

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 8 additions & 5 deletions nibabel/gifti/gifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ def __init__(self, header=None, extra=None, file_map=None, meta=None,
labeltable=None, darrays=None, version="1.0"):
super(GiftiImage, self).__init__(header=header, extra=extra,
file_map=file_map)
# placed here temporarily for git diff purposes
from .parse_gifti_fast import GiftiImageParser
GiftiImage.parser = GiftiImageParser

if darrays is None:
darrays = []
if meta is None:
Expand Down Expand Up @@ -596,7 +592,14 @@ def from_file_map(klass, file_map, buffer_size=35000000):
img : GiftiImage
Returns a GiftiImage
"""
parser = klass.parser(buffer_size=buffer_size)
# Note for refactorers: We were aiming to make ``parser`` a class
# attribute such that klass.parser().parse(...) would return an
# instance of klass.
#
# In the current setup of parse_gifti_fast.GiftiImageParser, this
# results in a circular dependency, so using a local import only.
from .parse_gifti_fast import GiftiImageParser
parser = GiftiImageParser(buffer_size=buffer_size)
parser.parse(fptr=file_map['image'].get_prepare_fileobj('rb'))
img = parser.img
return img
Expand Down