Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetize available_readers method and update documentation #1378

Merged
merged 4 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/source/readers.rst
Expand Up @@ -15,7 +15,9 @@ requested, or added to a Scene object.
Available Readers
=================

To get a list of available readers use the `available_readers` function::
To get a list of available readers use the `available_readers` function. By default,
it returns the names of available readers. To return additional reader information
use `available_readers(as_dict=True)`::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Great addition.


>>> from satpy import available_readers
>>> available_readers()
Expand Down
9 changes: 5 additions & 4 deletions satpy/readers/__init__.py
Expand Up @@ -85,7 +85,6 @@ def group_files(files_to_sort, reader=None, time_threshold=10,
a `Scene` object.

"""

if reader is not None and not isinstance(reader, (list, tuple)):
reader = [reader]

Expand Down Expand Up @@ -124,7 +123,6 @@ def _assign_files_to_readers(files_to_sort, reader_names, ppp_config_dir,
Mapping where the keys are reader names and the values are tuples of
(reader_configs, filenames).
"""

files_to_sort = set(files_to_sort)
reader_dict = {}
for reader_configs in configs_for_reader(reader_names, ppp_config_dir):
Expand Down Expand Up @@ -164,7 +162,6 @@ def _get_file_keys_for_reader_files(reader_files, group_keys=None):
Returns:
Mapping[str, List[Tuple[Tuple, str]]], as described.
"""

file_keys = {}
for (reader_name, (reader_instance, files_to_sort)) in reader_files.items():
if group_keys is None:
Expand Down Expand Up @@ -315,10 +312,14 @@ def available_readers(as_dict=False):
try:
reader_info = read_reader_config(reader_configs)
except (KeyError, IOError, yaml.YAMLError):
LOG.warning("Could not import reader config from: %s", reader_configs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why you removed this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The person who made the original request recommended that we "suppress [the output] when the reader config is not found as a first time user this creates a lot of clutter."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking! Could you just make it a debug instead? That way, regular users won't see it but devs will still get the info.

LOG.debug("Could not import reader config from: %s", reader_configs)
LOG.debug("Error loading YAML", exc_info=True)
continue
readers.append(reader_info if as_dict else reader_info['name'])
if as_dict:
readers = sorted(readers, key=lambda reader_info: reader_info['name'])
else:
readers = sorted(readers)
return readers


Expand Down
2 changes: 2 additions & 0 deletions satpy/tests/test_readers.py
Expand Up @@ -625,12 +625,14 @@ def test_available_readers(self):
self.assertIsInstance(reader_names[0], str)
self.assertIn('viirs_sdr', reader_names) # needs h5py
self.assertIn('abi_l1b', reader_names) # needs netcdf4
self.assertEqual(reader_names, sorted(reader_names))

reader_infos = available_readers(as_dict=True)
self.assertEqual(len(reader_names), len(reader_infos))
self.assertIsInstance(reader_infos[0], dict)
for reader_info in reader_infos:
self.assertIn('name', reader_info)
self.assertEqual(reader_infos, sorted(reader_infos, key=lambda reader_info: reader_info['name']))


class TestGroupFiles(unittest.TestCase):
Expand Down