Skip to content

Commit

Permalink
Merge pull request #757 from glennpj/extend_r
Browse files Browse the repository at this point in the history
Make R extendable
  • Loading branch information
tgamblin committed May 10, 2016
2 parents b1da366 + 2b7b7f6 commit 57e4959
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/spack/spack/cmd/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ def __call__(self, stage):
autotools = "configure('--prefix=%s' % prefix)"
cmake = "cmake('.', *std_cmake_args)"
python = "python('setup.py', 'install', '--prefix=%s' % prefix)"
r = "R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)"

config_lines = ((r'/configure$', 'autotools', autotools),
(r'/CMakeLists.txt$', 'cmake', cmake),
(r'/setup.py$', 'python', python))
(r'/setup.py$', 'python', python),
(r'/NAMESPACE$', 'r', r))

# Peek inside the tarball.
tar = which('tar')
Expand Down Expand Up @@ -272,6 +274,10 @@ def create(parser, args):
if guesser.build_system == 'python':
name = 'py-%s' % name

# Prepend 'r-' to R package names, by convention.
if guesser.build_system == 'r':
name = 'r-%s' % name

# Create a directory for the new package.
pkg_path = repo.filename_for_package_name(name)
if os.path.exists(pkg_path) and not args.force:
Expand Down
3 changes: 3 additions & 0 deletions lib/spack/spack/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def parse_version_offset(path):
# e.g. lame-398-1
(r'-((\d)+-\d)', stem),

# e.g. foobar_1.2-3
(r'_((\d+\.)+\d+(-\d+)?[a-z]?)', stem),

# e.g. foobar-4.5.1
(r'-((\d+\.)*\d+)$', stem),

Expand Down
59 changes: 58 additions & 1 deletion var/spack/repos/builtin/packages/R/package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import functools
import glob
import inspect
import os
import re
from contextlib import closing

import spack
from llnl.util.lang import match_predicate
from spack import *
from spack.util.environment import *


class R(Package):
Expand All @@ -9,6 +19,8 @@ class R(Package):
"""
homepage = "https://www.r-project.org"
url = "http://cran.cnr.berkeley.edu/src/base/R-3/R-3.1.2.tar.gz"

extendable = True

version('3.2.3', '1ba3dac113efab69e706902810cc2970')
version('3.2.2', '57cef5c2e210a5454da1979562a10e5b')
Expand Down Expand Up @@ -38,12 +50,57 @@ class R(Package):
depends_on('tk')

def install(self, spec, prefix):
rlibdir = join_path(prefix, 'rlib')
options = ['--prefix=%s' % prefix,
'--libdir=%s' % rlibdir,
'--enable-R-shlib',
'--enable-BLAS-shlib']
'--enable-BLAS-shlib',
'--enable-R-framework=no']
if '+external-lapack' in spec:
options.extend(['--with-blas', '--with-lapack'])

configure(*options)
make()
make('install')

# ========================================================================
# Set up environment to make install easy for R extensions.
# ========================================================================

@property
def r_lib_dir(self):
return os.path.join('rlib', 'R', 'library')

def setup_dependent_environment(self, spack_env, run_env, extension_spec):
# Set R_LIBS to include the library dir for the
# extension and any other R extensions it depends on.
r_libs_path = []
for d in extension_spec.traverse():
if d.package.extends(self.spec):
r_libs_path.append(os.path.join(d.prefix, self.r_lib_dir))

r_libs_path = ':'.join(r_libs_path)
spack_env.set('R_LIBS', r_libs_path)

# For run time environment set only the path for extension_spec and prepend it to R_LIBS
if extension_spec.package.extends(self.spec):
run_env.prepend_path('R_LIBS', os.path.join(extension_spec.prefix, self.r_lib_dir))


def setup_dependent_package(self, module, ext_spec):
"""
Called before R modules' install() methods.
In most cases, extensions will only need to have one line::
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)
"""
# R extension builds can have a global R executable function
module.R = Executable(join_path(self.spec.prefix.bin, 'R'))

# Add variable for library directry
module.r_lib_dir = os.path.join(ext_spec.prefix, self.r_lib_dir)

# Make the site packages directory for extensions, if it does not exist already.
if ext_spec.package.is_extension:
mkdirp(module.r_lib_dir)
14 changes: 14 additions & 0 deletions var/spack/repos/builtin/packages/r-BiocGenerics/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from spack import *

class RBiocgenerics(Package):
"""S4 generic functions needed by many Bioconductor packages."""

homepage = 'https://www.bioconductor.org/packages/release/bioc/html/BiocGenerics.html'
url = "https://www.bioconductor.org/packages/release/bioc/src/contrib/BiocGenerics_0.16.1.tar.gz"

version('0.16.1', 'c2148ffd86fc6f1f819c7f68eb2c744f', expand=False)

extends('R')

def install(self, spec, prefix):
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)
18 changes: 18 additions & 0 deletions var/spack/repos/builtin/packages/r-abind/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from spack import *

class RAbind(Package):
"""Combine multidimensional arrays into a single array. This is a
generalization of 'cbind' and 'rbind'. Works with vectors, matrices, and
higher-dimensional arrays. Also provides functions 'adrop', 'asub', and
'afill' for manipulating, extracting and replacing data in arrays."""

homepage = "https://cran.r-project.org/"
url = "https://cran.r-project.org/src/contrib/abind_1.4-3.tar.gz"

version('1.4-3', '10fcf80c677b991bf263d38be35a1fc5', expand=False)

extends('R')

def install(self, spec, prefix):

R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)
22 changes: 22 additions & 0 deletions var/spack/repos/builtin/packages/r-filehash/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from spack import *

class RFilehash(Package):
"""Implements a simple key-value style database where character string keys
are associated with data values that are stored on the disk. A simple
interface is provided for inserting, retrieving, and deleting data from the
database. Utilities are provided that allow 'filehash' databases to be
treated much like environments and lists are already used in R. These
utilities are provided to encourage interactive and exploratory analysis on
large datasets. Three different file formats for representing the database
are currently available and new formats can easily be incorporated by third
parties for use in the 'filehash' framework."""

homepage = 'https://cran.r-project.org/'
url = "https://cran.r-project.org/src/contrib/filehash_2.3.tar.gz"

version('2.3', '01fffafe09b148ccadc9814c103bdc2f', expand=False)

extends('R')

def install(self, spec, prefix):
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)
19 changes: 19 additions & 0 deletions var/spack/repos/builtin/packages/r-magic/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from spack import *

class RMagic(Package):
"""A collection of efficient, vectorized algorithms for the creation and
investigation of magic squares and hypercubes, including a variety of
functions for the manipulation and analysis of arbitrarily dimensioned
arrays."""

homepage = "https://cran.r-project.org/"
url = "https://cran.r-project.org/src/contrib/magic_1.5-6.tar.gz"

version('1.5-6', 'a68e5ced253b2196af842e1fc84fd029', expand=False)

extends('R')

depends_on('r-abind')

def install(self, spec, prefix):
R('CMD', 'INSTALL', '--library=%s' % self.module.r_lib_dir, '%s' % self.stage.archive_file)

0 comments on commit 57e4959

Please sign in to comment.