Repository: spack/spack

Issue:
py-rpy2 test fails with LookupError: 'show' not found
If I install py-rpy2 with spack and try to run the tests that ship with py-rpy2, they fail.

### Expected Result

I expected the tests to pass.

### Actual Result

```console
/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/rinterface/__init__.py:146: RRuntimeWarning: Error in !value : invalid argument type

  warnings.warn(x, RRuntimeWarning)
rpy2 version: 2.9.4
- built against R version: 3-5.0--74626
- running linked to R version: R version 3.5.0 (2018-04-23)
E
======================================================================
ERROR: __main__ (unittest.loader._FailedTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/tests.py", line 43, in load_tests
    suite_robjects = loader.discover('robjects', pattern, rpy_root)
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/unittest/loader.py", line 290, in discover
    __import__(start_dir)
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/robjects/__init__.py", line 19, in <module>
    from rpy2.robjects.robject import RObjectMixin, RObject
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/robjects/__init__.py", line 19, in <module>
    from rpy2.robjects.robject import RObjectMixin, RObject
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/robjects/robject.py", line 52, in <module>
    class RObjectMixin(object):
  File "/usr/workspace/wsrzc/pozulp1/sp/lalor_spack/opt/spack/linux-rhel7-x86_64/gcc-4.9.3/python-3.6.2-dww6q37ao4ibgmxtwsj4ukax5tjl7xbb/lib/python3.6/site-packages/rpy2/robjects/robject.py", line 66, in RObjectMixin
    __show = rpy2.rinterface.baseenv.get("show")
LookupError: 'show' not found

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
```
### Steps to reproduce the issue

```console
(I'm at LLNL)
$ ssh rztopaz
$ git clone ssh://git@rz-bitbucket.llnl.gov:7999/opac/spack.git lalor_spack
$ cd lalor_spack
$ salloc -N1 --exclusive -t 2:00:00
$ ./bin/spack install -n py-rpy2@2.9.4 ^python@3.6.2 ^r@3.5.0
$ ./bin/spack activate py-rpy2
$ `./bin/spack location -i python@3.6.2`/bin/python3 -m rpy2.tests
```

### Information on your system

I'm on a toss3 system (x86 Broadwell) named rztopaz.
I am not using a packages.yaml.

### Friends who may be able to help

@lee218llnl @citibeth @adamjstewart @mathstuf 
I hope you don't mind me tagging you, I got your names from
```console
$ spack blame -g py-rpy2
``` 
and I know many of you are quite good at spack :)


Discussion:
Here's my spec output
```console
$ ./bin/spack spec py-rpy2@2.9.4 ^python@3.6.2 ^r@3.5.0
Input spec
--------------------------------
py-rpy2@2.9.4
    ^python@3.6.2
    ^r@3.5.0

Normalized
--------------------------------
py-rpy2@2.9.4
    ^py-setuptools
        ^python@3.6.2
            ^bzip2
            ^ncurses
                ^pkg-config@0.24:+internal_glib
            ^openssl
                ^zlib@1.2.5:
            ^readline
            ^sqlite
    ^py-six
    ^r@3.5.0
        ^cairo
            ^fontconfig@2.10.91:
                ^font-util
                    ^util-macros
                ^freetype
                    ^libpng
                ^libxml2
                    ^xz
            ^glib
                ^gettext@0.19:
                ^libffi
                ^perl
                    ^gdbm
            ^pixman
        ^curl
            ^nghttp2
                ^py-cython@0.19:
        ^icu4c
        ^java
        ^jpeg
        ^libtiff
        ^pango
            ^gobject-introspection
                ^bison
                    ^m4
                ^flex
                    ^help2man
            ^harfbuzz
        ^pcre
        ^tcl
        ^tk
            ^libx11
                ^inputproto
                ^kbproto
                ^libxcb@1.1.92:
                    ^libpthread-stubs
                    ^libxau@0.99.2:
                        ^xproto@7.0.17:
                    ^libxdmcp
                    ^xcb-proto
                ^xextproto
                ^xtrans

Concretized
--------------------------------
py-rpy2@2.9.4%gcc@4.9.3 arch=linux-rhel7-x86_64 
    ^py-setuptools@35.0.2%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^py-appdirs@1.4.3%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^python@3.6.2%gcc@4.9.3 patches=123082ab3483ded78e86d7c809e98a804b3465b4683c96bd79a2fd799f572244 +pic+shared~tk~ucs4 arch=linux-rhel7-x86_64 
                ^bzip2@1.0.6%gcc@4.9.3+shared arch=linux-rhel7-x86_64 
                ^ncurses@6.0%gcc@4.9.3 patches=f84b2708a42777aadcc7f502a261afe10ca5646a51c1ef8b5e60d2070d926b57 ~symlinks arch=linux-rhel7-x86_64 
                    ^pkg-config@0.29.2%gcc@4.9.3+internal_glib arch=linux-rhel7-x86_64 
                ^openssl@1.0.2k%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^zlib@1.2.11%gcc@4.9.3+optimize+pic+shared arch=linux-rhel7-x86_64 
                ^readline@7.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^sqlite@3.20.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^py-packaging@16.8%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^py-pyparsing@2.2.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^py-six@1.10.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
    ^r@3.5.0%gcc@4.9.3~X~external-lapack arch=linux-rhel7-x86_64 
        ^cairo@1.14.8%gcc@4.9.3~X arch=linux-rhel7-x86_64 
            ^fontconfig@2.12.3%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^font-util@1.3.1%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^util-macros@1.19.1%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^freetype@2.7.1%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^libpng@1.6.29%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^gperf@3.0.4%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^libxml2@2.9.4%gcc@4.9.3~python arch=linux-rhel7-x86_64 
                    ^xz@5.2.3%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^glib@2.53.1%gcc@4.9.3~libmount patches=c325997b72a205ad1638bb3e3ba0e5b73e3d32ce63b2d0d3282f3e3a2ff4663c arch=linux-rhel7-x86_64 
                ^gettext@0.19.8.1%gcc@4.9.3+bzip2+curses+git~libunistring+libxml2 patches=9acdb4e73f67c241b5ef32505c9ddf7cf6884ca8ea661692f21dca28483b04b8 +tar+xz arch=linux-rhel7-x86_64 
                    ^tar@1.29%gcc@4.9.3 patches=08921fcbd732050c74ddf1de7d8ad95ffdbc09f8b4342456fa2f6a0dd02a957c,5c314db58d005043bf407abaf25eb9823b9032a22fd12a0b142d4bf548130fa4,d428578be7fb99b831eb61e53b8d88a859afe08b479a21238180899707d79ce4,e34d2470461037933737c0a60fbcc5d5ea905fefb6b414b4a2e88a440fcae23a arch=linux-rhel7-x86_64 
                ^libffi@3.2.1%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^pcre@8.40%gcc@4.9.3~jit+utf arch=linux-rhel7-x86_64 
                ^perl@5.24.1%gcc@4.9.3+cpanm+shared arch=linux-rhel7-x86_64 
                    ^gdbm@1.13%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^pixman@0.34.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^curl@7.56.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^nghttp2@1.26.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^py-cython@0.25.2%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^icu4c@58.2%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^jdk@8u141-b15%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^libjpeg-turbo@1.5.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^nasm@2.11.06%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^libtiff@4.0.8%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^pango@1.40.3%gcc@4.9.3~X arch=linux-rhel7-x86_64 
            ^gobject-introspection@1.49.2%gcc@4.9.3 patches=6f90bb267efa043ed70b900b4b8e2faf9e8133afae311893b01060356ea81bba arch=linux-rhel7-x86_64 
                ^bison@3.0.4%gcc@4.9.3 patches=b72914fe38e54a6fc25f29019e0a0786705c4f61ce20d414cc2010c8d62448c7 arch=linux-rhel7-x86_64 
                    ^m4@1.4.18%gcc@4.9.3 patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00 +sigsegv arch=linux-rhel7-x86_64 
                        ^libsigsegv@2.11%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^flex@2.6.4%gcc@4.9.3+lex arch=linux-rhel7-x86_64 
                    ^help2man@1.47.4%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^harfbuzz@1.4.6%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^tcl@8.6.6%gcc@4.9.3 arch=linux-rhel7-x86_64 
        ^tk@8.6.6%gcc@4.9.3 arch=linux-rhel7-x86_64 
            ^libx11@1.6.5%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^inputproto@2.3.2%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^kbproto@1.0.7%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^libxcb@1.12%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^libpthread-stubs@0.4%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^libxau@1.0.8%gcc@4.9.3 arch=linux-rhel7-x86_64 
                        ^xproto@7.0.31%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^libxdmcp@1.1.2%gcc@4.9.3 arch=linux-rhel7-x86_64 
                    ^xcb-proto@1.12%gcc@4.9.3 patches=3bc1a1871d17325d1f591a8ec2091f956b2071d83a6e9998d7d4880c4abf3e8b arch=linux-rhel7-x86_64 
                ^xextproto@7.3.0%gcc@4.9.3 arch=linux-rhel7-x86_64 
                ^xtrans@1.3.5%gcc@4.9.3 arch=linux-rhel7-x86_64
```
I wasn't able to build `pixman` (#8596), so I can't test this. My first thoughts when looking at the package:

1. Try replacing `depends_on('r')` with `depends_on('r@2.8:', type=('build', 'run'))`.
2. PyPI tarballs often don't come with the unit tests. Try adding the develop branch from https://bitbucket.org/rpy2/rpy2
@adamjstewart darn.
1. This didn't fix it. What effect does the type= argument have?
2. Good idea, I'll give it a try.
> What effect does the type= argument have?

http://spack.readthedocs.io/en/latest/packaging_guide.html#dependency-types
@mmpozulp, I found that you need to add the spack-installed R's bin directory to your $PATH to get past the "show" error. Otherwise, it picks up an incompatible /usr/bin/R. Also FYI for others who come across this issue, you may get an error like this with older rpy2 versions:

`  TypeError: type 'rpy2.rinterface.StrSexpVector' is not an acceptable base type`

From what I have read this appears to be fixed in rpy2-2.7.4 and I found that this is fixed in rpy2-2.9.4.
forgot to add that you may need to install/activate py-jinja2 too.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-rpy2/package.py b/var/spack/repos/builtin/packages/py-rpy2/package.py
--- a/var/spack/repos/builtin/packages/py-rpy2/package.py
+++ b/var/spack/repos/builtin/packages/py-rpy2/package.py
@@ -35,14 +35,25 @@ class PyRpy2(PythonPackage):
     homepage = "https://pypi.python.org/pypi/rpy2"
     url = "https://pypi.io/packages/source/r/rpy2/rpy2-2.5.4.tar.gz"
 
-    version('2.5.4', '115a20ac30883f096da2bdfcab55196d')
+    version('2.9.4', '7df2562cdf43a0ccdd1e44ee1c16614f')
+    version('2.8.6', '85046aa58ba586622f67271fbca05933')
     version('2.5.6', 'a36e758b633ce6aec6a5f450bfee980f')
+    version('2.5.4', '115a20ac30883f096da2bdfcab55196d')
 
     # FIXME: Missing dependencies:
     # ld: cannot find -licuuc
     # ld: cannot find -licui18
 
-    depends_on('py-six', type=('build', 'run'))
+    # All versions
     depends_on('py-setuptools', type='build')
+    depends_on('r',             type=('build', 'run'))
+
+    # @2.9.0:
+    depends_on('r@3.3:',    when='@2.9.0:', type=('build', 'run'))
+    depends_on('python@3:', when='@2.9.0:', type=('build', 'run'))
+    depends_on('py-jinja2', when='@2.9.0:', type=('build', 'run'))
+    depends_on('py-six',    when='@2.9.0:', type=('build', 'run'))
 
-    depends_on('r')
+    # @:2.8.6
+    depends_on('r@2.8:', when='@:2.8.6', type=('build', 'run'))
+    depends_on('py-singledispatch', when='^python@:2',   type=('build', 'run'))


Test patch: