diff --git a/README.md b/README.md index 44f3983..df4d1fe 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ tree -I '*svn|*node_module*|*git|py3|*.pyc|__pycache__|statics' ``` 软件架构说明 -* .env 环境配置文件,只有一个section [sys],一个变量 TREST_ENV +* .env 环境配置文件,只有一个section [sys],一个变量 RUNTIME_ENV * configs 应用配置文件 * configs/local.yaml 本地开发环境相关配置 * configs/dev.yaml 开发环境相关配置 @@ -144,9 +144,9 @@ if __name__ == "__main__": 在 项目根目录( ROOT_PATH ) 下面创建 [.env 文件](https://gitee.com/leeyi/trest/blob/master/demo_dot.env) ``` -# TREST_ENV is not one of the local, dev, test, or product -TREST_ENV : dev - +# RUNTIME_ENV is not one of the local, dev, test, or product +# the colon must have Spaces around it +RUNTIME_ENV : local ``` run diff --git a/README_zh.md b/README_zh.md index 44f3983..df4d1fe 100644 --- a/README_zh.md +++ b/README_zh.md @@ -65,7 +65,7 @@ tree -I '*svn|*node_module*|*git|py3|*.pyc|__pycache__|statics' ``` 软件架构说明 -* .env 环境配置文件,只有一个section [sys],一个变量 TREST_ENV +* .env 环境配置文件,只有一个section [sys],一个变量 RUNTIME_ENV * configs 应用配置文件 * configs/local.yaml 本地开发环境相关配置 * configs/dev.yaml 开发环境相关配置 @@ -144,9 +144,9 @@ if __name__ == "__main__": 在 项目根目录( ROOT_PATH ) 下面创建 [.env 文件](https://gitee.com/leeyi/trest/blob/master/demo_dot.env) ``` -# TREST_ENV is not one of the local, dev, test, or product -TREST_ENV : dev - +# RUNTIME_ENV is not one of the local, dev, test, or product +# the colon must have Spaces around it +RUNTIME_ENV : local ``` run diff --git a/demo_dot.env b/demo_dot.env index 0f29899..2266de1 100644 --- a/demo_dot.env +++ b/demo_dot.env @@ -1,2 +1,3 @@ -# TREST_ENV is not one of the local, dev, test, or product -TREST_ENV : dev +# RUNTIME_ENV is not one of the local, dev, test, or product +# the colon must have Spaces around it +RUNTIME_ENV : local diff --git a/trest/config/__init__.py b/trest/config/__init__.py index 85eea54..3e5935d 100644 --- a/trest/config/__init__.py +++ b/trest/config/__init__.py @@ -17,13 +17,15 @@ else: raise ConfigError('ROOT_PATH is not configured') -with open(f'{ROOT_PATH}/.env', encoding='utf-8') as f: - cfg = yaml.safe_load(f) +env = os.getenv('RUNTIME_ENV') +if not env: + with open(f'{ROOT_PATH}/.env', encoding='utf-8') as f: + cfg = yaml.safe_load(f) + env = cfg.get('RUNTIME_ENV','') -env = cfg.get('TREST_ENV','') -# 检查系统环境变量 TREST_ENV 设置 +# 检查系统环境变量 RUNTIME_ENV 设置 if env not in ['local', 'dev', 'test', 'product']: - msg = f'The system variable TREST_ENV ({env}) is not one of the local, dev, test, or product' + msg = f'The system variable RUNTIME_ENV ({env}) is not one of the local, dev, test, or product' raise ConfigError(msg) _yf = f'{ROOT_PATH}/configs/{env}.yaml'