"examples/vscode:/vscode.git/clone" did not exist on "e357c71fae0ac571d86e394743a07d71c163222b"
Commit a20c510c authored by liuzhe-lz's avatar liuzhe-lz Committed by QuanluZhang
Browse files

Support pip install as root (#77)

parent 6873a3cf
...@@ -118,7 +118,8 @@ easy-install: check-perm ...@@ -118,7 +118,8 @@ easy-install: check-perm
easy-install: install-dependencies easy-install: install-dependencies
easy-install: build easy-install: build
easy-install: install easy-install: install
easy-install: update-bashrc easy-install: update-bash-config
easy-install: easy-install:
#$(_INFO) Complete! #(_END) #$(_INFO) Complete! #(_END)
...@@ -131,6 +132,7 @@ pip-install: build ...@@ -131,6 +132,7 @@ pip-install: build
pip-install: install-node-modules pip-install: install-node-modules
pip-install: install-scripts pip-install: install-scripts
pip-install: install-examples pip-install: install-examples
pip-install: update-bash-config
# Target for NNI developers # Target for NNI developers
...@@ -253,9 +255,6 @@ install-scripts: ...@@ -253,9 +255,6 @@ install-scripts:
chmod +x $(BIN_PATH)/nnictl chmod +x $(BIN_PATH)/nnictl
install -Dm644 tools/bash-completion $(BASH_COMP_SCRIPT) install -Dm644 tools/bash-completion $(BASH_COMP_SCRIPT)
ifndef _ROOT
echo '[[ -f $(BASH_COMP_SCRIPT) ]] && source $(BASH_COMP_SCRIPT)' >> ~/.bash_completion
endif
.PHONY: install-examples .PHONY: install-examples
...@@ -264,16 +263,20 @@ install-examples: ...@@ -264,16 +263,20 @@ install-examples:
[ $(EXAMPLES_PATH) = ${PWD}/examples ] || cp -rT examples $(EXAMPLES_PATH) [ $(EXAMPLES_PATH) = ${PWD}/examples ] || cp -rT examples $(EXAMPLES_PATH)
.PHONY: update-bashrc .PHONY: update-bash-config
ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_PATH)')) # $(BIN_PATH) not in PATH ifndef _ROOT
ifdef _ROOT update-bash-config:
$(error $(BIN_PATH) not in PATH as root, which should never happen) #$(_INFO) Updating bash configurations $(_END)
endif ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_PATH)')) # $(BIN_PATH) not in PATH
update-bashrc:
#$(_WARNING) NOTE: adding $(BIN_PATH) to PATH in bashrc $(_END) #$(_WARNING) NOTE: adding $(BIN_PATH) to PATH in bashrc $(_END)
echo 'export PATH="$$PATH:$(BIN_PATH)"' >> ~/.bashrc echo 'export PATH="$$PATH:$(BIN_PATH)"' >> ~/.bashrc
else # $(BIN_PATH) already in PATH endif
update-bashrc: ; ifeq (, $(shell (source ~/.bash_completion ; command -v _nnictl) 2>/dev/null)) # completion not installed
#$(_WARNING) NOTE: adding $(BASH_COMP_SCRIPT) to ~/.bash_completion $(_END)
echo '[[ -f $(BASH_COMP_SCRIPT) ]] && source $(BASH_COMP_SCRIPT)' >> ~/.bash_completion
endif
else
update-bash-config: ;
endif endif
......
...@@ -22,38 +22,16 @@ ...@@ -22,38 +22,16 @@
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
from setuptools.command.install import install from setuptools.command.install import install
from subprocess import Popen import subprocess
def read(fname): def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname), encoding='utf-8').read() return open(os.path.join(os.path.dirname(__file__), fname), encoding='utf-8').read()
class CustomInstallCommand(install): class CustomInstallCommand(install):
'''a customized install class in pip module''' '''a customized install class in pip module'''
def makeInstall(self):
'''execute make pip-install command'''
cmds = ['make', 'pip-install']
process = Popen(cmds)
if process.wait() != 0:
print('Error: Make Install Failed')
exit(-1)
def writeEnvironmentVariables(self, variable_name):
'''write an environment variable into ~/.bashrc'''
paths = os.getenv("PATH").split(':')
bin_path = os.path.join(os.getenv('HOME'),'.local/'+variable_name+'/bin')
if bin_path not in paths:
bashrc_path = os.path.join(os.getenv('HOME'), '.bashrc')
process = Popen('echo export PATH=' + bin_path + ':\$PATH >> ' + bashrc_path, shell=True)
if process.wait() != 0:
print('Error: Write Environment Variables Failed')
exit(-1)
def run(self): def run(self):
install.run(self) super().run()
self.makeInstall() subprocess.run(['make', 'pip-install'], check=True)
self.writeEnvironmentVariables('node')
self.writeEnvironmentVariables('yarn')
setup( setup(
name = 'NNI', name = 'NNI',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment