Repository: spack/spack

Issue:
Installation issue: py-symengine failed to build metadata
### Steps to reproduce the issue

```console
$ spack install py-symengine
```


### Error message

<details><summary>Error message</summary>

<pre>
[All dependencies successfully installed]
...
==> Installing py-symengine-0.9.2-zuzmlffyon56gv7rpvcuocnrdc2v3u6l
==> No binary for py-symengine-0.9.2-zuzmlffyon56gv7rpvcuocnrdc2v3u6l found: installing from source
==> Using cached archive: /home/kevin/software/spack/var/spack/cache/_source-cache/archive/0f/0f7e45f5bba3fa844f7de7aa8d6640faaacb1075df76d8e4996e82b0ec6a4f62.tar.gz
==> No patches needed for py-symengine
==> py-symengine: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 1:
    '/home/kevin/software/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.4.0/python-3.10.8-atrkure33ggs6lfrflexqbfp4lrgacoi/bin/python3.10' '-m' 'pip' '-vvv' '--no-input' '--no-cache-dir' '--disable-pip-version-check' 'install' '--no-deps' '--ignore-installed' '--no-build-isolation' '--no-warn-script-location' '--no-index' '--prefix=/home/kevin/software/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.4.0/py-symengine-0.9.2-zuzmlffyon56gv7rpvcuocnrdc2v3u6l' '--install-option=--symengine-dir=/home/kevin/software/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.4.0/symengine-0.9.0-xf2nmkpbgiq5vlcvnxetcpvh7dzkyes2' '.'

1 error found in build log:
     74          setup_py_code = "from setuptools import setup; setup()"
     75    
     76      exec(compile(setup_py_code, filename, "exec"))
     77      '"'"''"'"''"'"' % ('"'"'/tmp/kevin/spack-stage/spack-stage-py-symengine-0.9.2-zuzmlffyon56gv7rpvcuocnrdc2v3u6l/spack-src/setup.py'"'"',), "<pip-setuptools-caller>", "exec"))' egg_info --egg-base /tmp/pip-pip-egg-info-xbutyzs1
     78      cwd: /tmp/kevin/spack-stage/spack-stage-py-symengine-0.9.2-zuzmlffyon56gv7rpvcuocnrdc2v3u6l/spack-src/
     79      Preparing metadata (setup.py): finished with status 'error'
  >> 80    error: metadata-generation-failed
     81    
     82    × Encountered error while generating package metadata.
     83    ╰─> See above for output.
     84    
     85    note: This is an issue with the package mentioned above, not pip.
     86    hint: See above for details.

</pre></details>


### Information on your system

* **Spack:** 0.20.0.dev0 (5f8c09fd334d729cf2ff0cdd2398ead78d9c621c)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-zen3
* **Concretizer:** clingo

Also occurs on `linux-ubuntu20.04-zen2` system with last commit f5418ac34466c25583df26c3966488852cbac6e8.

### Additional information

Also reproducible on my test system when running `spack install --fresh py-symengine`, so doesn't seem to be any weird DAG or outdated dependency issue.
As a sanity check, I ran
```console
spack load symengine py-cython
pip install symengine
```
and that seemed to install (the equivalent of) `py-symengine` without any apparent issue, so the problem seems to be within spack and not in `py-symengine` itself. I haven't done any further digging yet.
Maintainers: @adamjstewart @pradyunsg 
[spack-build-env.txt](https://github.com/spack/spack/files/10677418/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/10677419/spack-build-out.txt)


### General information

- [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:
The real error message is:
```
  Running command python setup.py egg_info
  error: Multiple top-level packages discovered in a flat-layout: ['cmake', 'symengine'].

  To avoid accidental inclusion of unwanted files or directories,
  setuptools will not proceed with this build.

  If you are trying to create a single distribution with multiple packages
  on purpose, you should not rely on automatic discovery.
  Instead, consider the following options:

  1. set up custom discovery (`find` directive with `include` or `exclude`)
  2. use a `src-layout`
  3. explicitly set `py_modules` or `packages` with a list of names

  To find more information, look for "package discovery" on setuptools docs.
  error: subprocess-exited-with-error
```
Same issue was reported in https://github.com/symengine/symengine.py/issues/429 and fixed in https://github.com/symengine/symengine.py/pull/402. I'll open a PR to fix this while we wait for the new release.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-symengine/package.py b/var/spack/repos/builtin/packages/py-symengine/package.py
--- a/var/spack/repos/builtin/packages/py-symengine/package.py
+++ b/var/spack/repos/builtin/packages/py-symengine/package.py
@@ -28,6 +28,8 @@ class PySymengine(PythonPackage):
     depends_on("python@3.6:3", type=("build", "run"), when="@0.8.1:")
     depends_on("python@3.7:3", type=("build", "run"), when="@0.9.2:")
     depends_on("py-setuptools", type="build")
+    # https://github.com/symengine/symengine.py/issues/429
+    depends_on("py-setuptools@:60", type="build", when="@:0.9.2")
     depends_on("py-cython@0.19.1:", type="build", when="@0.2.0")
     depends_on("py-cython@0.29.24:", type="build", when="@0.8.1:")
     depends_on("cmake@2.8.12:", type="build")
@@ -35,6 +37,7 @@ class PySymengine(PythonPackage):
     depends_on("symengine@0.2.0", when="@0.2.0")
     depends_on("symengine@0.8.1", when="@0.8.1")
     depends_on("symengine@0.9.0", when="@0.9.2")
+    depends_on("symengine@master", when="@master")
 
     def install_options(self, spec, prefix):
         return ["--symengine-dir={0}".format(spec["symengine"].prefix)]


Test patch: