Skip to content

Commit

Permalink
fix anaconda path error
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Mar 23, 2018
1 parent 2ca867f commit 028b9fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
37 changes: 16 additions & 21 deletions py/desiutil/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)
# The line above will help with 2to3 support.
from sys import argv, executable, path, version_info
import requests
import sys
import tarfile
import re
import shutil
import requests
from subprocess import Popen, PIPE
from datetime import date
from types import MethodType
from os import chdir, environ, getcwd, makedirs, remove, symlink
from os.path import abspath, basename, exists, isdir, join
from shutil import copytree, rmtree
from .git import last_tag
from .log import get_logger, DEBUG, INFO
from .modules import (init_modules, configure_module,
Expand Down Expand Up @@ -133,8 +132,6 @@ class DesiInstall(object):
this holds the object that reads it.
default_nersc_dir_template : :class:`str`
The default code and Modules install directory for every NERSC host.
executable : :class:`str`
The command used to invoke the script.
fullproduct : :class:`str`
The path to the product including its URL, *e.g.*,
"https://github.com/desihub/desiutil".
Expand All @@ -153,8 +150,6 @@ class DesiInstall(object):
product_url : :class:`str`
The URL that will be used to download the code. This differs from
`fullproduct` in that it includes the tag or branch name.
test : :class:`bool`
Captures the value of the `test` argument passed to the constructor.
"""
default_nersc_dir_template = '/global/common/software/desi/{nersc_host}/desiconda/{desiconda_version}'

Expand Down Expand Up @@ -195,7 +190,7 @@ def get_options(self, test_args=None):
self.log.warning('The environment variable %s is not set!',
e)
parser = ArgumentParser(description="Install DESI software.",
prog=basename(argv[0]))
prog=basename(sys.argv[0]))
parser.add_argument('-a', '--anaconda', action='store', dest='anaconda',
default=self.anaconda_version(), metavar='VERSION',
help="Set the version of the DESI+Anaconda software stack.")
Expand Down Expand Up @@ -434,9 +429,9 @@ def get_code(self):
if isdir(self.working_dir):
self.log.info("Detected old working directory, %s. Deleting...",
self.working_dir)
self.log.debug("rmtree('%s')", self.working_dir)
self.log.debug("shutil.rmtree('%s')", self.working_dir)
if not self.options.test:
rmtree(self.working_dir)
shutil.rmtree(self.working_dir)
if self.github:
if self.is_trunk or self.is_branch:
if self.is_branch:
Expand Down Expand Up @@ -582,7 +577,7 @@ def anaconda_version(self):
except KeyError:
return 'current'
try:
return basename(desiconda[:desiconda.index('/code/desiconda')])
return basename(desiconda[:desiconda.index('/conda')])
except ValueError:
return 'current'

Expand Down Expand Up @@ -628,9 +623,9 @@ def set_install_dir(self):
self.baseversion)
if isdir(self.install_dir) and not self.options.test:
if self.options.force:
self.log.debug("rmtree('%s')", self.install_dir)
self.log.debug("shutil.rmtree('%s')", self.install_dir)
if not self.options.test:
rmtree(self.install_dir)
shutil.rmtree(self.install_dir)
else:
message = ("Install directory, {0}, already exists!".format(
self.install_dir))
Expand Down Expand Up @@ -851,13 +846,13 @@ def install(self):
# For certain installs, all that is needed is to copy the
# downloaded code to the install directory.
#
self.log.debug("copytree('%s', '%s')",
self.log.debug("shutil.copytree('%s', '%s')",
self.working_dir, self.install_dir)
if self.options.test:
self.log.debug("Test mode. Skipping copy of %s to %s.",
self.working_dir, self.install_dir)
else:
copytree(self.working_dir, self.install_dir)
shutil.copytree(self.working_dir, self.install_dir)
else:
#
# Run a 'real' install
Expand All @@ -882,18 +877,18 @@ def install(self):
except OSError as ose:
self.log.critical(ose.strerror)
raise DesiInstallException(ose.strerror)
if lib_dir not in path:
if lib_dir not in sys.path:
try:
newpythonpath = (lib_dir + ':' +
environ['PYTHONPATH'])
except KeyError:
newpythonpath = lib_dir
environ['PYTHONPATH'] = newpythonpath
path.insert(int(path[0] == ''), lib_dir)
sys.path.insert(int(sys.path[0] == ''), lib_dir)
#
# Ready to python setup.py
#
command = [executable, 'setup.py', 'install',
command = [sys.executable, 'setup.py', 'install',
'--prefix={0}'.format(self.install_dir)]
self.log.debug(' '.join(command))
if self.options.test:
Expand Down Expand Up @@ -998,9 +993,9 @@ def cleanup(self):
if not self.options.test:
chdir(self.original_dir)
if not self.options.keep:
self.log.debug("rmtree('%s')", self.working_dir)
self.log.debug("shutil.rmtree('%s')", self.working_dir)
if not self.options.test:
rmtree(self.working_dir)
shutil.rmtree(self.working_dir)
return True

def run(self): # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions py/desiutil/test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ def test_anaconda_version(self):
with patch.dict('os.environ', {'DESICONDA': 'FOO'}):
v = self.desiInstall.anaconda_version()
self.assertEqual(v, 'current')
environ['DESICONDA'] = '/global/common/software/desi/cori/desiconda/20170613-1.1.4-spectro/code/desiconda/20170613-1.1.4-spectro_conda'
environ['DESICONDA'] = '/global/common/software/desi/cori/desiconda/20170613-1.1.4-spectro/conda'
v = self.desiInstall.anaconda_version()
self.assertEqual(v, '20170613-1.1.4-spectro')
environ['DESICONDA'] = '/global/common/software/desi/cori/desiconda/20170613-1.1.4-spectro/CODE/desiconda/20170613-1.1.4-spectro_conda'
environ['DESICONDA'] = '/global/common/software/desi/cori/desiconda/20170613-1.1.4-spectro/code/desiconda/20170613-1.1.4-spectro_conda'
v = self.desiInstall.anaconda_version()
self.assertEqual(v, 'current')

Expand Down

0 comments on commit 028b9fe

Please sign in to comment.