Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Support pip install as root #77

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ easy-install: check-perm
easy-install: install-dependencies
easy-install: build
easy-install: install
easy-install: update-bashrc
easy-install: update-bash-config

easy-install:
#$(_INFO) Complete! #(_END)

Expand All @@ -129,6 +130,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
Expand Down Expand Up @@ -251,9 +253,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
Expand All @@ -262,16 +261,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


Expand Down
28 changes: 3 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down