Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/3.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a dkist config file using custom location from astropy
47 changes: 19 additions & 28 deletions dkist/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os
from warnings import warn

from pkg_resources import DistributionNotFound, get_distribution

from astropy.config.configuration import (ConfigurationDefaultMissingError,
ConfigurationDefaultMissingWarning,
update_default_config)
import astropy.config as _config
from astropy.tests.helper import TestRunner

from .dataset import Dataset # noqa
Expand All @@ -16,29 +13,23 @@
# package is not installed
__version__ = "unknown"

# add these here so we only need to cleanup the namespace at the end
config_dir = None

if not os.environ.get('ASTROPY_SKIP_CONFIG_UPDATE', False):
config_dir = os.path.dirname(__file__)
config_template = os.path.join(config_dir, __package__ + ".cfg")
if os.path.isfile(config_template):
try:
update_default_config(
__package__, config_dir, version=__version__)
except TypeError as orig_error:
try:
update_default_config(__package__, config_dir)
except ConfigurationDefaultMissingError as e:
wmsg = (e.args[0] +
" Cannot install default profile. If you are "
"importing from source, this is expected.")
warn(ConfigurationDefaultMissingWarning(wmsg))
del e
except Exception:
raise orig_error


__all__ = ['test', 'Dataset']
__all__ = ['test', 'Dataset', 'write_default_config']


def write_default_config():
"""
Writes out the template configuration file for this version of dkist.

This function will save a template config file for manual editing, if a
config file already exits this will write a config file appended with the
version number, to facilitate comparison of changes.

Returns
-------
filepath : `pathlib.Path` or `None`
The full path of the file written or `None` if no file was written.
"""
return _config.write_default_config("dkist", "dkist")


test = TestRunner.make_test_runner_in(os.path.dirname(__file__))
2 changes: 0 additions & 2 deletions dkist/_dkist_init.py

This file was deleted.

8 changes: 8 additions & 0 deletions dkist/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from astropy.config import ConfigItem as _AstropyConfigItem
from astropy.config import ConfigNamespace

__all__ = ['ConfigItem', 'ConfigNamespace']


class ConfigItem(_AstropyConfigItem):
rootname = 'dkist'
3 changes: 3 additions & 0 deletions dkist/dkist.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[io]
## Name of Preferred fits module
# preferred_fits_library = 'astropy'
17 changes: 17 additions & 0 deletions dkist/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import dkist.config as _config

from .fits import AstropyFITSLoader, BaseFITSLoader
from .reference_collections import (BaseFITSArrayContainer, DaskFITSArrayContainer,
NumpyFITSArrayContainer)

__all__ = ['BaseFITSLoader', 'AstropyFITSLoader', 'BaseFITSArrayContainer',
'NumpyFITSArrayContainer', 'DaskFITSArrayContainer', 'conf']


class Conf(_config.ConfigNamespace):
"""
Configuration Parameters for the IO Package.
"""

preferred_fits_library = _config.ConfigItem('astropy',
"Name of the preferred FITS module.")


conf = Conf()