From 9927de69e139832c600074333f93aa908a7c483d Mon Sep 17 00:00:00 2001 From: Nicolas Tappy Date: Thu, 4 Jul 2024 10:10:08 +0200 Subject: [PATCH] De-exposing parse_metadata, linting --- rsciio/digitalsurf/__init__.py | 4 ++-- rsciio/digitalsurf/_api.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/rsciio/digitalsurf/__init__.py b/rsciio/digitalsurf/__init__.py index 4627e25e..49230cbb 100644 --- a/rsciio/digitalsurf/__init__.py +++ b/rsciio/digitalsurf/__init__.py @@ -1,6 +1,6 @@ -from ._api import file_reader, file_writer, parse_metadata +from ._api import file_reader, file_writer -__all__ = ["file_reader", "file_writer", "parse_metadata"] +__all__ = ["file_reader", "file_writer"] def __dir__(): diff --git a/rsciio/digitalsurf/_api.py b/rsciio/digitalsurf/_api.py index fbbfbd94..7689bd47 100644 --- a/rsciio/digitalsurf/_api.py +++ b/rsciio/digitalsurf/_api.py @@ -59,24 +59,27 @@ _logger = logging.getLogger(__name__) -def parse_metadata(cmt: str, prefix: str = '$', delimiter: str = '=') -> dict: - """Parse metadata from the comment field of a digitalsurf file, or any other +def parse_metadata(cmt : str, prefix : str = '$', delimiter : str = '=') -> dict: + """ + Parse metadata from the comment field of a digitalsurf file, or any other str in similar formatting. Return it as a hyperspy-compatible nested dict. Parameters ---------- - cmt: str - str containing contents of a digitalsurf file comment field - prefix: str, default = '$' - prefix character that must start each line, otherwise line is ignored. - '$' for digitalsurf files, typically '' when parsing from text files - delimiter: string, default = '=' - Character that delimit key-value pairs in digitalsurf comments. - Usually '=' + cmt : str + Str containing contents of a digitalsurf file "comment" field. + prefix : str, default = '$' + Prefix character, must be present at the start of each line. + Otherwise, the line is ignored. '$' for digitalsurf files, + typically '' when parsing from text files. + delimiter : string, default = '=' + Character that delimit key-value pairs in digitalsurf comment. + Usually, '=' is used. Returns ------- - dict_md: nested dictionnary. + dict_md : dict + Nested dictionnary containing comment contents. """ # dict_ms is created as an empty dictionnary