Skip to content

Commit

Permalink
fix #111
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1100717 committed May 2, 2017
1 parent 7543999 commit b2a9146
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions rqalpha/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,33 +225,36 @@ def install(params):
params[mod_name_index] = lib_name

# Install Mod
pip_main(params)
installed_result = pip_main(params)

# Export config
mod_config_path = get_mod_config_path(generate=True)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

if len(mod_list) == 0:
"""
主要是方便 `pip install -e .` 这种方式 本地调试 Mod 使用,需要满足以下条件:
1. `rqalpha mod install -e .` 命令是在对应 自定义 Mod 的根目录下
2. 该 Mod 必须包含 `setup.py` 文件(否则也不能正常的 `pip install -e .` 来安装)
3. 该 Mod 包名必须按照 RQAlpha 的规范来命名,具体规则如下
* 必须以 `rqalpha-mod-` 来开头,比如 `rqalpha-mod-xxx-yyy`
* 对应import的库名必须要 `rqalpha_mod_` 来开头,并且需要和包名后半部分一致,但是 `-` 需要替换为 `_`, 比如 `rqalpha_mod_xxx_yyy`
"""
mod_name = _detect_package_name_from_dir()
mod_name = mod_name.replace("-", "_").replace("rqalpha_mod_", "")
mod_list.append(mod_name)

for mod_name in mod_list:
if "rqalpha_mod_" in mod_name:
mod_name = mod_name.replace("rqalpha_mod_", "")
mod_config['mod'][mod_name] = {}
mod_config['mod'][mod_name]['enabled'] = False

dump_config(mod_config_path, mod_config)
if installed_result == 0:
# 如果为0,则说明安装成功
if len(mod_list) == 0:
"""
主要是方便 `pip install -e .` 这种方式 本地调试 Mod 使用,需要满足以下条件:
1. `rqalpha mod install -e .` 命令是在对应 自定义 Mod 的根目录下
2. 该 Mod 必须包含 `setup.py` 文件(否则也不能正常的 `pip install -e .` 来安装)
3. 该 Mod 包名必须按照 RQAlpha 的规范来命名,具体规则如下
* 必须以 `rqalpha-mod-` 来开头,比如 `rqalpha-mod-xxx-yyy`
* 对应import的库名必须要 `rqalpha_mod_` 来开头,并且需要和包名后半部分一致,但是 `-` 需要替换为 `_`, 比如 `rqalpha_mod_xxx_yyy`
"""
mod_name = _detect_package_name_from_dir()
mod_name = mod_name.replace("-", "_").replace("rqalpha_mod_", "")
mod_list.append(mod_name)

for mod_name in mod_list:
if "rqalpha_mod_" in mod_name:
mod_name = mod_name.replace("rqalpha_mod_", "")
mod_config['mod'][mod_name] = {}
mod_config['mod'][mod_name]['enabled'] = False

dump_config(mod_config_path, mod_config)
list({})
return installed_result

def uninstall(params):
"""
Expand Down Expand Up @@ -279,7 +282,7 @@ def uninstall(params):
params[mod_name_index] = lib_name

# Uninstall Mod
pip_main(params)
uninstalled_result = pip_main(params)

# Remove Mod Config
mod_config_path = get_mod_config_path(generate=True)
Expand All @@ -293,6 +296,7 @@ def uninstall(params):

dump_config(mod_config_path, mod_config)
list({})
return uninstalled_result

def enable(params):
"""
Expand All @@ -307,7 +311,9 @@ def enable(params):
try:
import_module(module_name)
except ImportError:
install([module_name])
installed_result = install([module_name])
if installed_result != 0:
return

mod_config_path = get_mod_config_path(generate=True)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)
Expand Down

0 comments on commit b2a9146

Please sign in to comment.