Skip to content

Commit 6653635

Browse files
committed
add asdf.blocks to documentation
1 parent 6599d39 commit 6653635

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

asdf/_asdf.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from . import _version as version
1616
from . import constants, generic_io, lazy_nodes, reference, schema, treeutil, util, versioning, yamlutil
1717
from ._block.manager import Manager as BlockManager
18-
from ._block.viewer import BlockViewer
1918
from ._helpers import validate_version
19+
from .blocks import BlockViewer
2020
from .config import config_context, get_config
2121
from .exceptions import (
2222
AsdfManifestURIMismatchWarning,
@@ -141,7 +141,7 @@ def __init__(
141141
self._closed = False
142142
self._external_asdf_by_uri = {}
143143
self._blocks = BlockManager(uri=uri, lazy_load=lazy_load, memmap=memmap)
144-
self.blocks = BlockViewer(self._blocks)
144+
self._blocks_view = BlockViewer(self._blocks)
145145
if tree is None:
146146
# Bypassing the tree property here, to avoid validating
147147
# an empty tree.
@@ -546,8 +546,6 @@ def open_external(self, uri, **kwargs):
546546
def tree(self):
547547
"""
548548
Get/set the tree of data in the ASDF file.
549-
550-
When set, the tree will be validated against the ASDF schema.
551549
"""
552550
if self._closed:
553551
msg = "Cannot access data from closed ASDF file"
@@ -558,6 +556,13 @@ def tree(self):
558556
def tree(self, tree):
559557
self._tree = AsdfObject(tree)
560558

559+
@property
560+
def blocks(self):
561+
"""
562+
A `asdf.blocks.BlockViewer` with read-only access to ASDF blocks loaded from the ASDF file.
563+
"""
564+
return self._blocks_view
565+
561566
def keys(self):
562567
return self.tree.keys()
563568

asdf/_block/viewer.py renamed to asdf/blocks.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,43 @@
55

66
from asdf.constants import BLOCK_FLAG_STREAMED
77

8+
__all__ = ["BlockView", "BlockViewer"]
9+
810

911
class BlockView:
12+
"""
13+
A read-only view of an ASDF block.
14+
"""
15+
1016
def __init__(self, read_block):
1117
self._read_block = read_block
1218

1319
@property
1420
def header(self):
21+
"""
22+
MappingProxy: A read-only mapping of ASDF block header contents.
23+
"""
1524
return MappingProxyType(self._read_block.header)
1625

1726
@property
1827
def offset(self):
28+
"""
29+
int: The offset (in bytes) of the ASDF block from the start of the file.
30+
"""
1931
return self._read_block.offset
2032

2133
@property
2234
def data_offset(self):
35+
"""
36+
int: The offset (in bytes) of the ASDF block data from the start of the file.
37+
"""
2338
return self._read_block.data_offset
2439

2540
@property
2641
def loaded(self):
42+
"""
43+
bool: True if the ASDF block data has been loaded (and cached).
44+
"""
2745
return self._read_block._cached_data is not None
2846

2947
def load(self, out=None):
@@ -44,6 +62,10 @@ def _info(self):
4462

4563

4664
class BlockViewer(Sequence):
65+
"""
66+
A read-only sequence of `BlockView` objects.
67+
"""
68+
4769
def __init__(self, manager):
4870
self._manager = manager
4971

@@ -78,4 +100,7 @@ def bold(s):
78100
return lines
79101

80102
def info(self):
103+
"""
104+
Print a rendering of these blocks to stdout.
105+
"""
81106
print("\n".join(self._info()))

docs/asdf/user_api/asdf_blocks.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
******************
2+
asdf.blocks Module
3+
******************
4+
5+
.. currentmodule:: asdf
6+
7+
.. automodapi:: asdf.blocks
8+
:no-inheritance-diagram:

docs/asdf/user_api/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ User API
99
:hidden:
1010

1111
asdf_package.rst
12+
asdf_blocks.rst
1213
asdf_search.rst
1314
asdf_config.rst
1415

1516
* :doc:`asdf Package <asdf_package>`
17+
* :doc:`asdf.blocks Module <asdf_blocks>`
1618
* :doc:`asdf.search Module <asdf_search>`
1719
* :doc:`asdf.config Module <asdf_config>`

0 commit comments

Comments
 (0)