pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.07k stars 298 forks source link

Proposal: search automatically for local config-files/readers #286

Closed sjoro closed 6 years ago

sjoro commented 6 years ago

EUMETSAT has many Level 0, 1, and 2 products in different internal formats. These products are only used in-house and are not send out to the users. Therefore, satpy-readers for such products would quickly pollute satpy/etc/readers/-directory with *.yaml-files that are only useful for a small amount of PyTroll users.

The workaround with current implementation is to use ppp_config_dir-keyword when creating a Scene-object:

scn = Scene(fname, reader='my_reader', ppp_config_dir='/local/config/path')

This is a proposal for a possibility to add a local config directory where config files would be automatically searched. Proposed solution by modifying config_search_paths-method in satpy/config.py by setting an environmental variable, e.g. SATPY_LOCAL_CONFIG

Proposed modification

def config_search_paths(filename, *search_dirs, **kwargs):
    # Get the environment variable value every time (could be set dynamically)
    # FIXME: Consider removing the 'magic' environment variable all together
    CONFIG_PATH = get_environ_config_dir()
    LOCAL_PATH = os.environ.get('SATPY_LOCAL_CONFIG')
    paths = [filename, os.path.basename(filename)]
    paths += [os.path.join(search_dir, filename) for search_dir in search_dirs]
    if LOCAL_PATH:
        paths += [os.path.join(LOCAL_PATH, filename)]
    # FUTURE: Remove CONFIG_PATH because it should be included as a search_dir
    paths += [os.path.join(CONFIG_PATH, filename),
              os.path.join(PACKAGE_CONFIG_PATH, filename)]

    if kwargs.get("check_exists", True):
        paths = [x for x in paths if os.path.isfile(x)]

    # flip the order of the list so builtins are loaded first
    return paths[::-1]

Any ideas, comments, thoughts? Would such modification be useful for other institutes/organizations? Or is this just silly? ;)

sjoro commented 6 years ago

The functionality can be achieved by pointing PPP_CONFIG_DIR-environmental variable to the local config path.