From 2e2a6a9294efde52c8b87dabdccb18ffafe8c413 Mon Sep 17 00:00:00 2001 From: liuzhe Date: Sat, 15 Sep 2018 02:44:26 +0800 Subject: [PATCH] Support pip install as root --- Makefile | 26 ++++++++++++++------------ setup.py | 35 +++++------------------------------ 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 6e8513e06c..b99a2ac7a2 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ easy-install: install-python-modules easy-install: install-node-modules easy-install: install-scripts easy-install: install-examples -easy-install: update-bashrc +easy-install: update-bash-config easy-install: #$(_INFO) Complete! #(_END) @@ -132,6 +132,7 @@ pip-install: build pip-install: install-node-modules pip-install: install-scripts pip-install: install-examples +pip-install: update-bash-config # Target for NNI developers @@ -254,9 +255,6 @@ install-scripts: chmod +x $(BIN_PATH)/nnictl 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 @@ -265,16 +263,20 @@ install-examples: [ $(EXAMPLES_PATH) = ${PWD}/examples ] || cp -rT examples $(EXAMPLES_PATH) -.PHONY: update-bashrc -ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_PATH)')) # $(BIN_PATH) not in PATH - ifdef _ROOT - $(error $(BIN_PATH) not in PATH as root, which should never happen) - endif -update-bashrc: +.PHONY: update-bash-config +ifndef _ROOT +update-bash-config: + #$(_INFO) Updating bash configurations $(_END) + ifeq (, $(shell echo $$PATH | tr ':' '\n' | grep -x '$(BIN_PATH)')) # $(BIN_PATH) not in PATH #$(_WARNING) NOTE: adding $(BIN_PATH) to PATH in bashrc $(_END) echo 'export PATH="$$PATH:$(BIN_PATH)"' >> ~/.bashrc -else # $(BIN_PATH) already in PATH -update-bashrc: ; + endif + 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 diff --git a/setup.py b/setup.py index eeee54d075..a1e24c03c6 100644 --- a/setup.py +++ b/setup.py @@ -22,38 +22,16 @@ import os from setuptools import setup, find_packages from setuptools.command.install import install -from subprocess import Popen +import subprocess def read(fname): return open(os.path.join(os.path.dirname(__file__), fname), encoding='utf-8').read() class CustomInstallCommand(install): '''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): - install.run(self) - self.makeInstall() - self.writeEnvironmentVariables('node') - self.writeEnvironmentVariables('yarn') + super().run() + subprocess.run(['make', 'pip-install'], check=True) setup( name = 'NNI', @@ -80,11 +58,8 @@ def run(self): 'psutil', 'pyyaml', 'requests', - 'scipy', - 'schema' - ], - dependency_links = [ - 'git+https://github.com/hyperopt/hyperopt.git' + 'schema', + 'scipy' ], cmdclass={