This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix package installation in virtualenv and conda #1640
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ | |
import os | ||
import signal | ||
import psutil | ||
from .common_utils import print_error, print_normal, print_warning | ||
from .common_utils import print_error, print_normal, print_warning | ||
|
||
|
||
def check_output_command(file_path, head=None, tail=None): | ||
'''call check_output command to read content from a file''' | ||
"""call check_output command to read content from a file""" | ||
if os.path.exists(file_path): | ||
if sys.platform == 'win32': | ||
cmds = ['powershell.exe', 'type', file_path] | ||
|
@@ -26,30 +27,30 @@ def check_output_command(file_path, head=None, tail=None): | |
print_error('{0} does not exist!'.format(file_path)) | ||
exit(1) | ||
|
||
|
||
def kill_command(pid): | ||
'''kill command''' | ||
"""kill command""" | ||
if sys.platform == 'win32': | ||
process = psutil.Process(pid=pid) | ||
process.send_signal(signal.CTRL_BREAK_EVENT) | ||
else: | ||
cmds = ['kill', str(pid)] | ||
call(cmds) | ||
|
||
|
||
def install_package_command(package_name): | ||
'''install python package from pip''' | ||
#TODO refactor python logic | ||
if sys.platform == "win32": | ||
cmds = 'python -m pip install --user {0}'.format(package_name) | ||
else: | ||
cmds = 'python3 -m pip install --user {0}'.format(package_name) | ||
call(cmds, shell=True) | ||
"""install python package from pip""" | ||
call(_get_pip_install() + [package_name], shell=False) | ||
|
||
|
||
def install_requirements_command(requirements_path): | ||
'''install requirements.txt''' | ||
cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt' | ||
#TODO refactor python logic | ||
if sys.platform == "win32": | ||
cmds = cmds.format('python') | ||
else: | ||
cmds = cmds.format('python3') | ||
call(cmds, shell=True) | ||
"""install requirements.txt""" | ||
call(_get_pip_install() + ["-r", os.path.join(requirements_path, "requirements.txt")], shell=False) | ||
|
||
|
||
def _get_pip_install(): | ||
python = "python" if sys.platform == "win32" else "python3" | ||
ret = [python, "-m", "pip", "install"] | ||
if "CONDA_DEFAULT_ENV" not in os.environ and "VIRTUAL_ENV" not in os.environ: | ||
ret.append("--user") # not in virtualenv or conda | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if install as root? |
||
return ret |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you changed docstring format, I recommend you update the docstring following the discussed format :)