Skip to content

Commit

Permalink
fix tiny bug for rqalpha mod install cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1100717 committed Apr 24, 2017
1 parent 131b683 commit b766e60
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion rqalpha/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def install(params):
return
if "rqalpha_mod_" in mod_name:
lib_name = mod_name
mod_name = lib_name.replace("rqalpha_mod_", "")
else:
lib_name = "rqalpha_mod_" + mod_name
params[mod_name_index] = lib_name
Expand All @@ -232,7 +231,22 @@ def install(params):
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

Expand Down Expand Up @@ -321,5 +335,12 @@ def disable(params):
locals()[cmd](params)


def _detect_package_name_from_dir():
setup_path = os.path.join(os.path.abspath('.'), 'setup.py')
if not os.path.exists(setup_path):
return None
return os.path.split(os.path.dirname(setup_path))[1]


if __name__ == '__main__':
entry_point()

0 comments on commit b766e60

Please sign in to comment.