Repository: spack/spack

Issue:
`spack activate py-virtualenv` fails to activate `py-setuptools`
I've starting installing and activating py-virtualenv as part of a standard shared toolset.  Here's the bit of the script that drives the installation.

```
spack install python            # default from packages.yaml
spack install py-virtualenv
spack activate py-virtualenv

spack install python@3.6.0
spack install py-virtualenv ^python@3.6.0
spack activate py-virtualenv ^python@3.6.0
```

I was suprised to discover that activating `py-virtualenv` did not activate the apparently-required `py-setuptools` (happens with python2 and python3).  

E.g.  Here's the python3 version: 
- adding the installed python directory to PATH;
- python3 works; and
- virtualenv is on PATH; but
- it blows up; until
- I activate `py-setuptools ^python@3.6.0`.

```
hartzelg@rpbuchop002:spack (llnl/develop)$ export PATH=`pwd`/opt/spack/linux-centos7-x86_64/gcc-5.4.0/python-3.6.0-m5uhlrl7k4ac7gi2agj7xiw6wmquxpq3/bin:$PATH
hartzelg@rpbuchop002:spack (llnl/develop)$ which python
/usr/bin/python
hartzelg@rpbuchop002:spack (llnl/develop)$ which python3
/isilon/Analysis/scratch/hartzelg/spack-cime-rpbuchop002-working-dir/workspace/daily-build/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/python-3.6.0-m5uhlrl7k4ac7gi2agj7xiw6wmquxpq3/bin/python3
hartzelg@rpbuchop002:spack (llnl/develop)$ python3
Python 3.6.0 (default, Mar 17 2017, 11:35:47)
[GCC 5.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
hartzelg@rpbuchop002:spack (llnl/develop)$ which virtualenv
/isilon/Analysis/scratch/hartzelg/spack-cime-rpbuchop002-working-dir/workspace/daily-build/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/python-3.6.0-m5uhlrl7k4ac7gi2agj7xiw6wmquxpq3/bin/virtualenv
hartzelg@rpbuchop002:spack (llnl/develop)$ virtualenv
Traceback (most recent call last):
  File "/isilon/Analysis/scratch/hartzelg/spack-cime-rpbuchop002-working-dir/workspace/daily-build/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/python-3.6.0-m5uhlrl7k4ac7gi2agj7xiw6wmquxpq3/bin/virtualenv", line 7, in <module>
    from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
hartzelg@rpbuchop002:spack (llnl/develop)$ spack activate py-setuptools ^python@3.6.0
==> Activated extension py-appdirs@1.4.0%gcc@5.4.0 arch=linux-centos7-x86_64 /eajpjfn for python@3.6.0~tk~ucs4%gcc@5.4.0
==> Activated extension py-pyparsing@2.1.10%gcc@5.4.0 arch=linux-centos7-x86_64 /jzlgzex for python@3.6.0~tk~ucs4%gcc@5.4.0
==> Activated extension py-six@1.10.0%gcc@5.4.0 arch=linux-centos7-x86_64 /em5tra4 for python@3.6.0~tk~ucs4%gcc@5.4.0
==> Activated extension py-packaging@16.8%gcc@5.4.0 arch=linux-centos7-x86_64 /wporjj5 for python@3.6.0~tk~ucs4%gcc@5.4.0
==> Activated extension py-setuptools@34.2.0%gcc@5.4.0 arch=linux-centos7-x86_64 /ys7rdd6 for python@3.6.0~tk~ucs4%gcc@5.4.0
hartzelg@rpbuchop002:spack (llnl/develop)$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR

[...]
```

`py-virtualenv` seems to depend on `py-setuptools`....

```python
class PyVirtualenv(PythonPackage):
  [...]
    depends_on('py-setuptools') # not just build-time, requires pkg_resources
```

I have a feeling that I've been around this before.

Is this a bug?  Am I missing something obvious (share a previous Issue and shame my search skills... :1st_place_medal: )?

Thanks!


Discussion:
Try:
```python
depends_on('py-setuptools', type=('build', 'run'))
```
If that works I can submit a PR. People keep forgetting that the default deptype is `('build', 'link')`, not `('build', 'run')`. I'm pretty sure we only activate run deptypes.
This change solved the problem for me. Note that I had to uninstall and reinstall `py-virtualenv` so that the dependency was correct in the database. `spack reindex` may also have worked. I'll submit a PR shortly.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-virtualenv/package.py b/var/spack/repos/builtin/packages/py-virtualenv/package.py
--- a/var/spack/repos/builtin/packages/py-virtualenv/package.py
+++ b/var/spack/repos/builtin/packages/py-virtualenv/package.py
@@ -27,11 +27,16 @@
 
 class PyVirtualenv(PythonPackage):
     """virtualenv is a tool to create isolated Python environments."""
-    homepage = "http://virtualenv.readthedocs.org/projects/virtualenv/"
-    url      = "https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.6.tar.gz"
 
-    version('1.11.6', 'f61cdd983d2c4e6aeabb70b1060d6f49')
-    version('13.0.1', '1ffc011bde6667f0e37ecd976f4934db')
+    homepage = "https://virtualenv.pypa.io/"
+    url      = "https://pypi.io/packages/source/v/virtualenv/virtualenv-15.1.0.tar.gz"
+
+    version('15.1.0', '44e19f4134906fe2d75124427dc9b716')
     version('15.0.1', '28d76a0d9cbd5dc42046dd14e76a6ecc')
+    version('13.0.1', '1ffc011bde6667f0e37ecd976f4934db')
+    version('1.11.6', 'f61cdd983d2c4e6aeabb70b1060d6f49')
+
+    depends_on('python@2.6:')
 
-    depends_on('py-setuptools') # not just build-time, requires pkg_resources
+    # not just build-time, requires pkg_resources
+    depends_on('py-setuptools', type=('build', 'run'))


Test patch: