Repository: spack/spack

Issue:
py-pyyaml: Specify libyaml location explicitly
Depending on the compiler, the library of `libyaml` could not be found and an error occurred.
So, I fixed to specify the path of `libyaml` installed with Spack explicitly.
Installation issue: py-pyyaml
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

I have tried to build a package that depends on `py-pyyaml`, but `py-pyyaml` fails during the build stage due to what looks like a linker error. I am not sure whether this is due to the linker looking at the wrong place or if it is something else.

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install py-pyyaml
==> Error: Failed to install py-pyyaml due to ChildError: ProcessError: Command exited with status 1:
    '/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/python-3.7.7-oqdlfukk7v3iajirursoemgwjz4uq6uc/bin/python3.7' '-s' 'setup.py' '--no-user-cfg' '--with-libyaml' 'build'
3 errors found in build log:
     425    In file included from ext/_yaml.h:2,
     426                     from ext/_yaml.c:596:
     427    /home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/libyaml-0.2.4-k46pfvmdak4ogt5qbu34cdkjtw4yjey5/include/yaml.h:635
            :1: note: expected 'const yaml_char_t *' {aka 'const unsigned char *'} but argument is of type 'char *'
     428     yaml_mapping_start_event_initialize(yaml_event_t *event,
     429     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     430    /opt/rh/devtoolset-8/root/usr/bin/gcc -pthread -shared -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/gettext-
            0.20.2-ywb257jdmwqy5gwssz6opqhqmjmnfpkh/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/readline-8.0-qfr2d6
            nrzui4pihmumw2ngs5oezg2ebx/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/ncurses-6.2-gy7fmfawhiwde4tk4lwn
            vwppf6xg6nku/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/openssl-1.1.1g-73vqdkaryyg356e2skc7uu5foyllury
            y/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/sqlite-3.31.1-5lrgvo7dtj6p4m2gv4d5gy7ecpshet3o/lib -L/hom
            e/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/gdbm-1.18.1-rw5vcezglu4vrccrvzt7u3vormfpnslk/lib -L/home/hsf/spack/op
            t/spack/linux-centos7-sandybridge/gcc-8.3.1/zlib-1.2.11-j2ucagtfig5spujohz2kfvt6bvqczkoa/lib -L/home/hsf/spack/opt/spack/linux-
            centos7-sandybridge/gcc-8.3.1/bzip2-1.0.8-ipfmbxrjzthhecv4mf3ecwi6jp5nlks7/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandyb
            ridge/gcc-8.3.1/xz-5.2.5-ssqjpbn5vti7tluiwqo3pxbgdx2d4p6x/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/e
            xpat-2.2.9-bijlnz6u5vp3oy35osxfghvelwbl4gok/lib -L/home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/libffi-3.3-a557
            3cu6i6sycxun36p6ahlpvfxuy7kx/lib64 build/temp.linux-x86_64-3.7/ext/_yaml.o -L/home/hsf/spack/opt/spack/linux-centos7-sandybridg
            e/gcc-8.3.1/python-3.7.7-oqdlfukk7v3iajirursoemgwjz4uq6uc/lib -lyaml -lpython3.7m -o build/lib.linux-x86_64-3.7/_yaml.cpython-3
            7m-x86_64-linux-gnu.so
  >> 431    /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/ld: cannot find -lyaml
  >> 432    collect2: error: ld returned 1 exit status
     433    /home/hsf/spack/opt/spack/linux-centos7-sandybridge/gcc-8.3.1/python-3.7.7-oqdlfukk7v3iajirursoemgwjz4uq6uc/lib/python3.7/distu
            tils/dist.py:274: UserWarning: Unknown distribution option: 'python_requires'
     434      warnings.warn(msg)
  >> 435    error: command '/opt/rh/devtoolset-8/root/usr/bin/gcc' failed with exit status 1
```

### Information on your system

<!-- Please include the output of `spack debug report` -->
```console
$ spack debug report
* **Spack:** 0.14.2-1047-ff6a0fc
* **Python:** 3.6.8
* **Platform:** linux-centos7-sandybridge
```

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists


. -->
* [spack-build-env.txt](https://github.com/spack/spack/files/4610527/spack-build-env.txt)
* [spack-build-out.txt](https://github.com/spack/spack/files/4610529/spack-build-out.txt)

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:
see also #16527
I think I know a better way to do this. Let me open another PR and I'll ping both of you.
This looks like the issue that @skosukhin reported and is trying to fix in #16527. I still don't know why I didn't encounter this issue myself. For now, you can either try #16527 and see if that fixes the issue for you, or build without libyaml: `spack install py-pyyaml~libyaml`. If pyyaml accepts some kind of flag or environment variable, we could use that to tell it where to find `libyaml`, but I haven't found such a flag/env var yet.
HI @adamjstewart, sorry I had briefly looked through any related issues, but apparently I have missed the open PR. `spack install py-pyyaml~libyaml` indeed seems to work to build pyyaml. I have to check if the dependencies are working as expected with this in place.

I have also tried #16527 and that works as well for me. So once that is merged, I suppose this can also be closed. 

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-pyyaml/package.py b/var/spack/repos/builtin/packages/py-pyyaml/package.py
--- a/var/spack/repos/builtin/packages/py-pyyaml/package.py
+++ b/var/spack/repos/builtin/packages/py-pyyaml/package.py
@@ -11,6 +11,9 @@ class PyPyyaml(PythonPackage):
 
     homepage = "https://pyyaml.org/wiki/PyYAML"
     url      = "https://pypi.io/packages/source/P/PyYAML/PyYAML-5.3.1.tar.gz"
+    git      = "https://github.com/yaml/pyyaml.git"
+
+    maintainers = ['adamjstewart']
 
     version('5.3.1', sha256='b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d')
     version('5.1.2', sha256='01adf0b6c6f61bd11af6e10ca52b7d4057dd0be0343eb9283c878cf3af56aee4')
@@ -24,6 +27,17 @@ class PyPyyaml(PythonPackage):
     depends_on('python@2.7:2.8,3.5:', type=('build', 'run'))
     depends_on('libyaml', when='+libyaml')
 
+    phases = ['build_ext', 'install']
+
+    @property
+    def import_modules(self):
+        modules = ['yaml']
+
+        if '+libyaml' in self.spec:
+            modules.append('yaml.cyaml')
+
+        return modules
+
     def setup_py(self, *args, **kwargs):
         # Cast from tuple to list
         args = list(args)
@@ -34,3 +48,21 @@ def setup_py(self, *args, **kwargs):
             args.insert(0, '--without-libyaml')
 
         super(PyPyyaml, self).setup_py(*args, **kwargs)
+
+    def build_ext_args(self, spec, prefix):
+        args = []
+
+        if '+libyaml' in spec:
+            args.extend([
+                spec['libyaml'].libs.search_flags,
+                spec['libyaml'].headers.include_flags,
+            ])
+
+        return args
+
+    # Tests need to be re-added since `phases` was overridden
+    run_after('build_ext')(
+        PythonPackage._run_default_build_time_test_callbacks)
+    run_after('install')(
+        PythonPackage._run_default_install_time_test_callbacks)
+    run_after('install')(PythonPackage.sanity_check_prefix)


Test patch: