gummy.utils.environ_utils module¶
Utility programs for environment variables.
-
gummy.utils.environ_utils.
name2envname
(name, service='', prefix='')[source]¶ Convert name to environment varname.
- Parameters
name (str) – name.
service (str) – service name. (default=
""
)prefix (str) – prefix of the
name
. (default=""
)
Examples
>>> from gummy.utils import name2envname >>> name2envname(name="name", service="", prefix="") 'TRANSLATION_GUMMY_NAME' >>> name2envname(name="name", service="service", prefix="") 'TRANSLATION_GUMMY_SERVICE_NAME' >>> name2envname(name="name", service="", prefix="prefix") 'TRANSLATION_GUMMY_PREFIX_NAME' >>> name2envname(name="name", service="service", prefix="prefix") 'TRANSLATION_GUMMY_SERVICE_PREFIX_NAME'
-
gummy.utils.environ_utils.
where_is_envfile
()[source]¶ Get Where the envfile is.
Examples
>>> from gummy.utils import where_is_envfile >>> where_is_envfile() '/Users/iwasakishuto/.gummy/.env'
-
gummy.utils.environ_utils.
read_environ
(dotenv_path='/Users/iwasakishuto/.gummy/.env')[source]¶ Read the environment variables from
dotenv_path
- Parameters
dotenv_path (str) – path/to/.env (default=
DOTENV_PATH
)- Returns
the dictionary containing
dotenv_path
’s environment variables.- Return type
dict
Examples
>>> from gummy.utils import read_environ >>> read_environ() {'TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME': 'USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD': 'PASSWORD'}
-
gummy.utils.environ_utils.
write_environ
(dotenv_path='/Users/iwasakishuto/.gummy/.env', **kwargs)[source]¶ Overwrite or Write the environment variables in
dotenv_path
- Parameters
dotenv_path (str) – path/to/.env (default=
DOTENV_PATH
)kwargs (dict) – new environment variables
Examples
>>> from gummy.utils import read_environ, write_environ >>> read_environ() {'TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME': 'USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD': 'PASSWORD'} >>> write_environ(TRANSLATION_GUMMY_SAMPLE="SAMPLE") >>> read_environ() {'TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME': 'USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD': 'PASSWORD', 'TRANSLATION_GUMMY_SAMPLE': 'SAMPLE'} >>> write_environ(TRANSLATION_GUMMY_SAMPLE="SAMPLE_AMENDED") >>> read_environ() {'TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME': 'USERNAME', 'TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD': 'PASSWORD', 'TRANSLATION_GUMMY_SAMPLE': 'SAMPLE_AMENDED'}
-
gummy.utils.environ_utils.
show_environ
(dotenv_path='/Users/iwasakishuto/.gummy/.env')[source]¶ Show environment variables written in
dotenv_path
.- Parameters
dotenv_path (str) – path/to/.env (default=
DOTENV_PATH
)
Examples
>>> from gummy.utils import show_environ >>> show_environ() * TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME : "USERNAME" * TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD : "PASSWORD"
-
gummy.utils.environ_utils.
load_environ
(dotenv_path='/Users/iwasakishuto/.gummy/.env', env_varnames=[], verbose=False)[source]¶ Load environment variables from
path
file, and return whether every necessary VARNAMES (env_varnames
) are set.- Parameters
dotenv_path (str) – path/to/.env (default=
DOTENV_PATH
)env_varnames (list) – new environment variables
verbose (bool) – Whether to print message or not. (default=
False
)
- Returns
Whether there are environment variables not defined in
dotenv_path
but inenv_varnames
- Return type
bool
Examples
>>> from gummy.utils import load_environ, show_environ >>> is_ok = load_environ() >>> is_ok True >>> show_environ() * TRANSLATION_GUMMY_GATEWAY_UTOKYO_USERNAME : "USERNAME" * TRANSLATION_GUMMY_GATEWAY_UTOKYO_PASSWORD : "PASSWORD" >>> is_ok = load_environ(env_varnames=["TRANSLATION_GUMMY_NOT_DEFINED"]) TRANSLATION_GUMMY_NOT_DEFINED is not set. EnvVariableNotDefinedWarning: Please set environment variable in /Users/iwasakishuto/.gummy/.env >>> is_ok False
-
gummy.utils.environ_utils.
check_environ
(required_keynames, required_env_varnames=None, verbose=True, **kwargs)[source]¶ Check whether meet the requirements.
- Parameters
required_keynames (list) – Required keynames
required_env_varnames (list) – Required environment variables.
verbose (bool) – Whether to print message or not. (default=
True
)
Examples
>>> check_environ( ... required_keynames=["hoge"], ... required_env_varnames=["TRANSLATION_GUMMY_HOGE"], ... hoge="hoge" >>> ) (True, []) >>> check_environ( ... required_keynames=["hoge"], ... required_env_varnames=["TRANSLATION_GUMMY_HOGE"], ... hoge1="hoge" >>> ) Please set TRANSLATION_GUMMY_HOGE or give hoge as kwargs. (False, ['hoge'])
- Returns
is_ok
: Whether meet the requirements.not_meet_keynames
: contains keynames you have to supply.
- Return type
tuple (bool, list)