seagrid.config#
Configuration management for seagrid.
Settings are handled by Dynaconf in the same way as in tracmass. The
package template TEMPLATE (settings_template.toml) is always
loaded first and gives the defaults. It is followed by these files, in order
of increasing priority (missing files are skipped):
Global settings:
/etc/seagrid/seagrid.tomlUser settings:
~/.config/seagrid/seagrid.tomlCurrent directory settings:
./seagrid.tomlAny
sg_*.tomlfile in the current directory, sorted by filenameThe file named by the environment variable
SEAGRID_SETTINGS_FILE_FOR_DYNACONF
Each of the first three directories may also hold a .secrets.toml for
credentials, which must never be committed to version control.
Every [section] is a Dynaconf environment. [default] applies to
all of them, and every data source reads its own section ([ostia],
[modis_a], …) with source_settings(). Environment variables
prefixed with SEAGRID_ override single keys, e.g.
SEAGRID_BASEDATADIR=/data/seagrid.
- ivar USER_DIR:
User configuration directory,
~/.config/seagrid.- vartype USER_DIR:
- ivar GLOB_DIR:
Machine-wide configuration directory,
/etc/seagrid.- vartype GLOB_DIR:
- ivar CURR_DIR:
The working directory when seagrid was imported.
- vartype CURR_DIR:
- ivar TEMPLATE:
The commented settings template shipped with the package.
- vartype TEMPLATE:
- ivar settings_files:
Every settings file checked, in loading order (after
TEMPLATE).- vartype settings_files:
listofpathlib.Path- ivar settings:
The settings object.
- vartype settings:
dynaconf.Dynaconf
Examples
>>> from seagrid import config
>>> config.source_settings("ostia")["doi"]
'10.48670/moi-00168'
Module Attributes
|
Name of the environment variable naming an extra settings file. |
Dynaconf's own entries in a settings object, not from any settings file. |
|
Credential keys, accepted in any section (they belong in a .secrets.toml). |
|
|
Keys any section may set that the template does not show. |
Functions
|
Change the active environment of |
|
Find settings keys that seagrid does not know. |
|
Write the commented settings template to a file. |
Return the names of all data-source sections in the template. |
|
|
Return the settings of one data source. |
- seagrid.config.CREDENTIAL_KEYS = frozenset({'appkey', 'password', 'token', 'username'})#
Credential keys, accepted in any section (they belong in a .secrets.toml).
- seagrid.config.DYNACONF_KEYS = frozenset({'environments', 'envvar_prefix', 'load_dotenv'})#
Dynaconf’s own entries in a settings object, not from any settings file.
- seagrid.config.change_env(new_env)[source]#
Change the active environment of
settings.- Parameters:
new_env (
str) – The environment (section) to switch to.- Return type:
None
Notes
Data sources read their own section with
source_settings()and are not affected by the active environment.
- seagrid.config.check_settings(name=None, *, warn=True)[source]#
Find settings keys that seagrid does not know.
A misspelt key does nothing, silently, because the default from the template is used instead. This compares the keys of each section with the keys the template defines for that section and for
[default]. Keys listed in a section’sextra_keysare accepted too.- Parameters:
name (
str, optional) – Section to check. Default: every section in the template.warn (
bool, optional) – Issue aUserWarningfor each unknown key. Default True.
- Returns:
- Warns:
UserWarning – For each unknown key, if warn is True.
- Return type:
- seagrid.config.init(path='seagrid.toml', overwrite=False)[source]#
Write the commented settings template to a file.
- Parameters:
path (
stroros.PathLike, optional) – File to write (a.tomlname), or a directory to writeseagrid.tomlinto.~is expanded and missing directories are created. Default"seagrid.toml"in the current directory. Use"~/.config/seagrid"(USER_DIR) for settings that apply to every project.overwrite (
bool, optional) – Replace an existing file. Default False.
- Returns:
pathlib.Path– The file written.- Raises:
FileExistsError – If the file exists and overwrite is False.
- Return type:
Examples
>>> import seagrid >>> seagrid.config.init("~/.config/seagrid") PosixPath('/home/user/.config/seagrid/seagrid.toml')
- seagrid.config.source_names()[source]#
Return the names of all data-source sections in the template.
- Returns:
listofstr– Section names (Dynaconf environments) other thandefault, in the order they appear inTEMPLATE.- Return type:
Examples
>>> "ostia" in source_names() True
- seagrid.config.source_settings(name)[source]#
Return the settings of one data source.
The result is an independent Dynaconf object for environment name: the
[default]keys overlaid with the keys of[name]from every settings file. Changing its active environment does not affectsettingsor any other source.- Parameters:
name (
str) – Section (environment) name, e.g."ostia"or"modis_a".- Returns:
dynaconf.LazySettings– The settings of name. Read keys withs["key"]ors.get("key", default).- Return type:
Examples
>>> source_settings("acspo")["host"] 'https://coastwatch.noaa.gov'
Notes
Dynaconf caches one object per environment. The cache is cleared when a
SEAGRID_*environment variable or a settings file changes, so such changes take effect at the next call.