Skip to content

Commit

Permalink
TREST_ENV 修改为 RUNTIME_ENV 首先从系统变量中获取 RUNTIME_ENV ;
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Feb 3, 2020
1 parent 59214ec commit d22ee9b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 开发环境相关配置
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 开发环境相关配置
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions demo_dot.env
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions trest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit d22ee9b

Please sign in to comment.