Skip to content

Commit

Permalink
Created CustomInstallCommand subclass for install command to test if …
Browse files Browse the repository at this point in the history
…dcr can be installed along with python setup.py install
  • Loading branch information
Simon Torres committed Oct 18, 2018
1 parent 8db42c4 commit 51d1dff
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
2 changes: 0 additions & 2 deletions install_dcr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ else
if [ -f $SOURCE_DIR/dcr ]
then
echo "Adding executing permission"
echo $SOURCE_DIR
echo $PATH
chmod +x $SOURCE_DIR/dcr

if [ -d $ENV_PATH/bin ] && echo $PATH | grep -q $ENV_PATH/bin
Expand Down
46 changes: 45 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

# Always prefer setuptools over distutils
from setuptools import setup, find_packages
from setuptools.command.install import install

import subprocess
from threading import Timer
from sphinx.setup_command import BuildDoc
# To use a consistent encoding
from codecs import open
Expand All @@ -40,6 +43,46 @@ def create_version_py(packagename, version, source_dir='.'):
from configparser import ConfigParser
conf = ConfigParser()


class CustomInstallCommand(install):
"""Custom install command to allow dcr installation."""

def _install_dcr(self, install_script='install_dcr.sh'):
print("Running DCR installer")
command = 'sh {:s}'.format(install_script)

try:
install_dcr = subprocess.Popen(command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

except OSError as error:
print(error)

install_timer = Timer(10, self._kill_process, [install_dcr])

try:
install_timer.start()
stdout, stderr = install_dcr.communicate()
finally:
install_timer.cancel()

for _line in stdout.split(b'\n'):
print(_line.decode("utf-8"))

for _line in stderr.split(b'\n'):
print(_line.decode("utf-8"))

@staticmethod
def _kill_process(process):
process.kill()

def run(self):

self._install_dcr(install_script='install_dcr.sh')
install.run(self)


# conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')])
conf.read([os.path.join(os.path.dirname(__file__), 'setup.cfg')])
metadata = dict(conf.items('metadata'))
Expand All @@ -63,7 +106,8 @@ def create_version_py(packagename, version, source_dir='.'):


cmdclassd = {'build_sphinx': BuildDoc,
'build_docs': BuildDoc}
'build_docs': BuildDoc,
'install': CustomInstallCommand}

setup(
name=metadata['package_name'],
Expand Down

0 comments on commit 51d1dff

Please sign in to comment.