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

Support sudo pip install #76

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
35 changes: 5 additions & 30 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 All @@ -80,11 +58,8 @@ def run(self):
'psutil',
'pyyaml',
'requests',
'scipy',
'schema'
],
dependency_links = [
'git+https://github.com/hyperopt/hyperopt.git'
'schema',
'scipy'
],

cmdclass={
Expand Down