Skip to content

Commit

Permalink
Doc strings + annotations added.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-i-berry committed Sep 5, 2023
1 parent bd8ad53 commit faf4f0f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions csv2bufr/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# under the License.
#
###############################################################################

import json
import logging
import os
from pathlib import Path
from typing import Union

TEMPLATE_DIRS = []

Expand All @@ -36,7 +36,17 @@
TEMPLATE_DIRS.append(Path(__file__).resolve().parent / 'resources')


def load_template(template_name):
def load_template(template_name: str) -> Union[dict, None]:
"""
Checks whether specified template exists and loads file.
Returns none and prints a warning if no template found.
:param template_name: The name of the template (without file extension)
to load.
:returns: BUFR template as a dictionary or none in the case of template
not found.
"""
template = None
# iterate over directories and load file
for dir_ in TEMPLATE_DIRS:
Expand All @@ -51,12 +61,18 @@ def load_template(template_name):

if template is None:
LOGGER.warning(f"Requested template '{template_name}' not found." +
f" Search path = {TEMPLATE_DIRS}")
f" Search path = {TEMPLATE_DIRS}. Please update " +
"search path (e.g. 'export CSV2BUFR_TEMPLATE=...')"
)

return template


def list_templates():
def list_templates() -> list:
"""
:returns: List of known templates in search path (CSV2BUFR_TEMPLATES).
An empty list is return if no templates are found.
"""
templates = []
for dir_ in TEMPLATE_DIRS:
try:
Expand Down

0 comments on commit faf4f0f

Please sign in to comment.