Skip to content

Commit

Permalink
remove unused readonly flag
Browse files Browse the repository at this point in the history
mmap access changes in whole file memmap asdf-format#1230 may have
made this flag redundant.
  • Loading branch information
braingram committed Jan 3, 2023
1 parent e4e234f commit 280399a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
7 changes: 1 addition & 6 deletions asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def __init__(
copy_arrays=False,
lazy_load=True,
custom_schema=None,
_readonly=False,
):
"""
Parameters
Expand Down Expand Up @@ -156,7 +155,7 @@ def __init__(
self._fd = None
self._closed = False
self._external_asdf_by_uri = {}
self._blocks = block.BlockManager(self, copy_arrays=copy_arrays, lazy_load=lazy_load, readonly=_readonly)
self._blocks = block.BlockManager(self, copy_arrays=copy_arrays, lazy_load=lazy_load)
self._uri = None
if tree is None:
# Bypassing the tree property here, to avoid validating
Expand Down Expand Up @@ -1819,21 +1818,17 @@ def open_asdf(
The new AsdfFile object.
"""

readonly = False

# For now retain backwards compatibility with the old API behavior,
# specifically when being called from AsdfFile.open
if not _compat:
mode = _check_and_set_mode(fd, mode)
readonly = mode == "r" and not copy_arrays

instance = AsdfFile(
ignore_version_mismatch=ignore_version_mismatch,
ignore_unrecognized_tag=ignore_unrecognized_tag,
copy_arrays=copy_arrays,
lazy_load=lazy_load,
custom_schema=custom_schema,
_readonly=readonly,
)

return AsdfFile._open_impl(
Expand Down
15 changes: 3 additions & 12 deletions asdf/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BlockManager:
Manages the `Block`s associated with a ASDF file.
"""

def __init__(self, asdffile, copy_arrays=False, lazy_load=True, readonly=False):
def __init__(self, asdffile, copy_arrays=False, lazy_load=True):
self._asdffile = weakref.ref(asdffile)

self._internal_blocks = []
Expand All @@ -40,7 +40,6 @@ def __init__(self, asdffile, copy_arrays=False, lazy_load=True, readonly=False):
self._validate_checksums = False
self._memmap = not copy_arrays
self._lazy_load = lazy_load
self._readonly = readonly
self._internal_blocks_mapped = False

def __len__(self):
Expand Down Expand Up @@ -512,9 +511,7 @@ def read_block_index(self, fd, ctx):
# It seems we're good to go, so instantiate the UnloadedBlock
# objects
for offset in offsets[1:-1]:
self._internal_blocks.append(
UnloadedBlock(fd, offset, memmap=self.memmap, lazy_load=self.lazy_load, readonly=self._readonly)
)
self._internal_blocks.append(UnloadedBlock(fd, offset, memmap=self.memmap, lazy_load=self.lazy_load))

# We already read the last block in the file -- no need to read it again
self._internal_blocks.append(block)
Expand Down Expand Up @@ -814,7 +811,6 @@ def __init__(self, data=None, uri=None, array_storage="internal", memmap=True, l
self._should_memmap = memmap
self._memmapped = False
self._lazy_load = lazy_load
self._readonly = False

self.update_size()
self._allocated = self._size
Expand Down Expand Up @@ -920,10 +916,6 @@ def output_compression_kwargs(self, config):
def checksum(self):
return self._checksum

@property
def readonly(self):
return self._readonly

def _set_checksum(self, checksum):
if checksum == b"\0" * 16:
self._checksum = None
Expand Down Expand Up @@ -1234,7 +1226,7 @@ class UnloadedBlock:
requested.
"""

def __init__(self, fd, offset, memmap=True, lazy_load=True, readonly=False):
def __init__(self, fd, offset, memmap=True, lazy_load=True):
self._fd = fd
self._offset = offset
self._data = None
Expand All @@ -1247,7 +1239,6 @@ def __init__(self, fd, offset, memmap=True, lazy_load=True, readonly=False):
self._should_memmap = memmap
self._memmapped = False
self._lazy_load = lazy_load
self._readonly = readonly

def __len__(self):
self.load()
Expand Down
2 changes: 0 additions & 2 deletions asdf/tags/core/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ def _make_array(self):

self._array = np.ndarray(shape, dtype, block.data, self._offset, self._strides, self._order)
self._array = self._apply_mask(self._array, self._mask)
if block.readonly:
self._array.setflags(write=False)
return self._array

def _apply_mask(self, array, mask):
Expand Down

0 comments on commit 280399a

Please sign in to comment.