[Fix] Fix install ambiguous (#43)

* fix install ambigous

* fix install local repo

* fix docstring
pull/54/head
Zaida Zhou 2021-06-23 21:05:23 +08:00 committed by GitHub
parent 40151776de
commit 73692e491a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 7 deletions

View File

@ -129,7 +129,15 @@ def install(package: str,
target_pkg, target_version = split_package_version(package)
# whether install from local repo
is_install_local_repo = osp.isdir(osp.abspath(target_pkg)) and not find_url
if looks_like_path(target_pkg):
if is_installable_dir(target_pkg):
is_install_local_repo = True
else:
raise ValueError(
highlighted_error(
f'{target_pkg} is not a installable directory'))
else:
is_install_local_repo = False
# whether install master branch from github
is_install_master = bool(not target_version and find_url)
@ -240,6 +248,38 @@ def install(package: str,
echo_success(f'Successfully installed {target_pkg}.')
def looks_like_path(name: str) -> bool:
"""Checks whether the string "looks like" a path on the filesystem.
This does not check whether the target actually exists, only judge from the
appearance.
Args:
name (str): The string to be checked.
"""
if osp.sep in name:
return True
if osp.altsep is not None and osp.altsep in name:
return True
if name.startswith('.'):
return True
return False
def is_installable_dir(name: str) -> bool:
"""Check whether path is a directory containing setup.py.
Args:
name (str): The string to be checked.
"""
path = osp.abspath(name)
if osp.isdir(path):
setup_py = osp.join(path, 'setup.py')
return osp.isfile(setup_py)
else:
return False
def infer_find_url(package: str) -> str:
"""Try to infer find_url if possible.

View File

@ -64,12 +64,8 @@ def test_mmrepo_install():
result = runner.invoke(install, ['./mmclassification', '--yes'])
assert result.exit_code == 0
# mim install mmclassification
result = runner.invoke(install, ['mmclassification', '--yes'])
assert result.exit_code == 0
# mim install -e mmclassification
result = runner.invoke(install, ['-e', 'mmclassification', '--yes'])
# mim install -e ./mmclassification
result = runner.invoke(install, ['-e', './mmclassification', '--yes'])
assert result.exit_code == 0
os.chdir(current_root)