Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1st cleanup pass for Anaconda easyblock #1

Merged
merged 1 commit into from
Oct 13, 2016
Merged
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
78 changes: 28 additions & 50 deletions easybuild/easyblocks/a/anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for building and installing the python distribution anaconda, implemented as an easyblock
EasyBuild support for building and installing Anaconda, implemented as an easyblock

@author: Jillian Rowe (New York University Abu Dhabi)
"""

Expand All @@ -32,33 +33,33 @@
import stat

import easybuild.tools.environment as env
from easybuild.framework.easyblock import EasyBlock
from easybuild.framework.easyconfig import CUSTOM
from easybuild.easyblocks.generic.binary import Binary
from easybuild.tools.run import run_cmd
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import rmtree2
from easybuild.tools.filetools import adjust_permissions, rmtree2


def set_conda_env(installdir):
""" Set the correct environmental variables for conda """

myEnv = os.environ.copy()
env.setvar('PATH', "{}/bin".format(installdir) + ":" + myEnv["PATH"])
env.setvar('CONDA_ENV', installdir)
env.setvar('CONDA_DEFAULT_ENV', installdir)


def pre_install_step(log, pre_install_cmd = None):
""" User defined pre install step """

if not pre_install_cmd:
pass
else:
log.debug('Pre command run', pre_install_cmd)
run_cmd(pre_install_cmd, log_all=True, simple=True)
log.info('Pre command run {}'.format(pre_install_cmd))


def post_install_step(log, installdir, post_install_cmd):
""" User defined post install step """

if not post_install_cmd:
pass
else:
Expand All @@ -67,83 +68,60 @@ def post_install_step(log, installdir, post_install_cmd):
run_cmd(post_install_cmd, log_all=True, simple=True)
log.info('Post command run {}'.format(post_install_cmd))


def initialize_conda_env(installdir):
""" Initialize the conda env """

rmtree2(installdir)
cmd = "conda config --add create_default_packages setuptools"
run_cmd(cmd, log_all=True, simple=True)

class EB_anaconda(EasyBlock):
"""Support for building/installing anaconda."""

class EB_Anaconda(Binary):
"""Support for building/installing Anaconda."""

@staticmethod
def extra_options(extra_vars=None):
"""Extra easyconfig parameters specific to EB_anaconda easyblock."""
extra_vars = EasyBlock.extra_options(extra_vars)
"""Extra easyconfig parameters specific to Anaconda."""
extra_vars = Binary.extra_options(extra_vars)
extra_vars.update({
'pre_install_cmd': [None, "Commands before install: setting custom environmental variables, etc", CUSTOM],
'post_install_cmd': [None, "Commands after install: pip install, cpanm install, etc", CUSTOM],
})
return extra_vars

def __init__(self, *args, **kwargs):
"""Initialize EB_anaconda-specific variables."""

super(EB_anaconda, self).__init__(*args, **kwargs)

def extract_step(self):
"""Move all source files to the build directory"""

self.src[0]['finalpath'] = self.builddir

# copy source to build dir.
for source in self.src:
src = source['path']
dst = os.path.join(self.builddir, source['name'])
try:
shutil.copy2(src, self.builddir)
os.chmod(dst, stat.S_IRWXU)
except (OSError, IOError), err:
raise EasyBuildError("Couldn't copy %s to %s: %s", src, self.builddir, err)

def configure_step(self):
"""No configuration, this is binary software"""
pass

def build_step(self):
"""No compilation, this is binary software"""
pass

def install_step(self):
"""Copy all files in build directory to the install directory"""

pre_install_step(self.log, self.cfg['pre_install_cmd'])

rmtree2(self.installdir)
sources = self.cfg['sources']
install_script = sources[0]
install_script = self.src[0]['name']

cmd = "chmod 777 {} && ./{} -p {} -b -f".format(install_script, install_script, self.installdir )
adjust_permissions(os.path.join(self.builddir, install_script), stat.S_IRUSR|stat.S_IXUSR)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this remove the extract_step for all the blocks? In CondaEnv I am sometimes pulling from a remote environment, which means there is no file source. Will this have an effect if there is no source?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only makes the change in the Anaconda easyblock, I haven't looked at the Conda* yet.

I think there may be some cleanup possible there too, I'll look into that later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. ;-)

This is the master branch , and I had most of my changes in the develop branch. I am sharing some functions between the three EBs, but I don't remember exactly which functions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by 'this is the master branch'?

I've targeted your develop branch using this PR, which is also the one you used for easybuilders#950

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I don't know why I thought it was the master branch. My kids are bouncing around, and I should have sat down and been more careful about collecting my thoughts. ;-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I know the feeling! :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boegel , have you had a chance to take a look at the conda blocks?

cmd = "./%s -p %s -b -f" % (install_script, self.installdir)
self.log.info("Installing %s using command '%s'..." % (self.name, cmd))
run_cmd(cmd, log_all=True, simple=True)

post_install_step(self.log, self.installdir, self.cfg['post_install_cmd'])

def make_module_extra(self):
"""Add the install directory to the PATH."""

txt = super(EB_anaconda, self).make_module_extra()
self.log.debug("make_module_extra added this: %s" % txt)
return txt

def make_module_req_guess(self):
"""
A dictionary of possible directories to look for.
"""
return {
'PATH': ['bin', 'sbin'],
'MANPATH': ['man', os.path.join('share', 'man')],
'PATH': ['bin', 'sbin'],
'PKG_CONFIG_PATH': [os.path.join(x, 'pkgconfig') for x in ['lib', 'lib32', 'lib64', 'share']],
}

def sanity_check_step(self):
"""
Custom sanity check for Anaconda
"""
bins = ['2to3', 'activate', 'conda', 'deactivate', 'ipython', 'pydoc', 'python', 'sqlite3']
custom_paths = {
'files': [os.path.join('bin', x) for x in bins],
'dirs': ['bin', 'etc', 'lib', 'pkgs'],
}
super(EB_Anaconda, self).sanity_check_step(custom_paths=custom_paths)