Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DASDAE/dascore into rename_patch_new
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Jan 4, 2024
2 parents 75f6528 + a11438c commit c9e9e99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 19 additions & 2 deletions dascore/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def yield_fiberio(
format: str | None = None,
version: str | None = None,
extension: str | None = None,
formatter_hint: FiberIO | None = None,
) -> Self:
"""
Yields fiber IO object based on input priorities.
Expand All @@ -216,13 +217,20 @@ def yield_fiberio(
Parameters
----------
format
The format string indicating the format name
The format string indicating the format name.
version
The version string of the format
extension
The extension of the file.
formatter_hint
If not None, a suspected formatter to use first. This is an
optimization for file archives which tend to have many files of
the same format.
"""
# TODO replace this with concise pattern matching once 3.9 is dropped
if formatter_hint is not None:
yield formatter_hint
if version and not format:
msg = "Providing only a version is not sufficient to determine format"
raise UnknownFiberFormatError(msg)
Expand Down Expand Up @@ -623,6 +631,7 @@ def scan(
>>> attr_list = dc.scan(file_path)
"""
out = []
formatter = None
for patch_source in _iterate_scan_inputs(path):
# just pull attrs from patch
if isinstance(patch_source, dc.Patch):
Expand All @@ -636,6 +645,7 @@ def scan(
man,
file_format=file_format,
file_version=file_version,
formatter_hint=formatter,
)
except UnknownFiberFormatError: # skip bad entities
continue
Expand All @@ -656,6 +666,7 @@ def get_format(
path: str | Path | IOResourceManager,
file_format: str | None = None,
file_version: str | None = None,
formatter_hint: FiberIO | None = None,
**kwargs,
) -> tuple[str, str]:
"""
Expand All @@ -669,6 +680,9 @@ def get_format(
The known file format.
file_version
The known file version.
formatter_hint
A suspected formatter to try first. This is primarily an optimization
for reading file archives where the formats usually are the same.
Returns
-------
Expand All @@ -695,7 +709,10 @@ def get_format(
suffix = Path(path).suffix
ext = suffix[1:] if suffix else None
iterator = FiberIO.manager.yield_fiberio(
file_format, file_version, extension=ext
file_format,
file_version,
extension=ext,
formatter_hint=formatter_hint,
)
for formatter in iterator:
# we need to wrap this in try except to make it robust to what
Expand Down
2 changes: 0 additions & 2 deletions dascore/io/plugin.py

This file was deleted.

0 comments on commit c9e9e99

Please sign in to comment.