Repository: spack/spack

Issue:
Installation issue: py-zipp with py-setuptools-scm@6.3.2
### Steps to reproduce the issue

```console
$ spack install py-zipp ^py-setuptools-scm@6.3.2
(...)
Error: ProcessError: Command exited with status 1:
(...)
==> Error: py-zipp-3.6.0-u26np7v3tncfi32jyu4pbby6xbkqxoio: Package was not installed
==> Error: Installation request failed.  Refer to reported errors for failing package(s).
$ tail .../spack-build-out.txt
pkg_resources.DistributionNotFound: The 'packaging>=20.0' distribution was not found and is required by the application
```

### Information on your system

* **Spack:** 0.16.3-4967-3720d06e26
* **Python:** 3.10.0
* **Platform:** linux-debian11-skylake_avx512
* **Concretizer:** clingo

### Additional information

@adamjstewart 

Logs: https://gist.github.com/8ea20ef00793767a46e48ed6d4b320cf

Adding an explicit build dependency on `py-packaging` to `py-zipp` allows the installation to complete. 

py-zipp is not the only package with this problem, I think that any package that depends on `py-setuptools-scm` will fail with the newest version.

So, I propose to add `py-packaging` as a run-time dependency to `py-setuptools-scm` with condition `@6.3.1:`

### 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:
Hmm, I'm having trouble reproducing this issue locally. It also isn't clear why this dep would be needed for all packages that depend on setuptools-scm. I don't see it mentioned anywhere in `setup_requires` or `install_requires`.
@adamjstewart try starting from `python:3` docker image. I have also reproduced the error on Ubuntu 20.04 (physical) machine and on SLC7 one.
As to why is it needed - no idea. `packaging` is not listed as a requirement for zipp (or anyio, or matplotlib - these are the packages that need this additional dependency).
@alalazo this might be related to the CI failures we were seeing.
> 
> 
> As to why is it needed - no idea. `packaging` is not listed as a requirement for zipp (or anyio, or matplotlib - these are the packages that need this additional dependency).

Correction: not matplotlib, but python-dateutil
> 
> 
> Hmm, I'm having trouble reproducing this issue locally. It also isn't clear why this dep would be needed for all packages that depend on setuptools-scm. I don't see it mentioned anywhere in `setup_requires` or `install_requires`.

@adamjstewart It is mentioned [here](https://github.com/pypa/setuptools_scm/blob/v6.3.1/pyproject.toml#L6). The `build-system` table's `requires` key is described in [PEP-518])(https://www.python.org/dev/peps/pep-0518/#build-system-table) as follows:
>  ... must have a value of a list of strings representing PEP 508 dependencies required to execute the build system (currently that means what dependencies are required to execute a setup.py file)

In my opinion, this matches spack's definition of run-time dependency.
Isn't that the definition of a build-time dep? The `setup.py` is only executed when we build the package, it doesn't get installed so it isn't used at run-time.
> 
> 
> Isn't that the definition of a build-time dep? The `setup.py` is only executed when we build the package, it doesn't get installed so it isn't used at run-time.

I think the mentioned `setup.py` is not setuptools-scm's one, but (e.g.) zipp' - "required ... to execute the build system", not to build the build system.
The docs say to add `requires = ['setuptools', 'wheel']` for most packages. So this is to execute the build system of the package, not dependency packages.
Just did one more test. Using a clean environment, ran `pip install -vvv --no-binary=:all: zipp==3.6.0`, you can find full log here: [gist](https://gist.github.com/iarspider/21b36f565173e2ec94dfcf3001d21150). If you run `grep packaging` on that output, you will see that pip downloads and installs `packaging`, but it is not listed in `pip install`, meaning that it is only installed temporary.

> 
> 
> The docs say to add `requires = ['setuptools', 'wheel']` for most packages. So this is to execute the build system of the package, not dependency packages.

`setuptools-scm` is listed in `requires` key for zipp: [link](https://github.com/jaraco/zipp/blob/v3.6.0/pyproject.toml#L2)
Yep, so `py-setuptools-scm` should have a build dep on `py-packaging`, and `py-zipp` should have a build dep on `py-setuptools-scm`. If any other deps are needed, then I think we should report a bug to those developers because the dependency isn't properly listed under `install_requires`.
https://github.com/pypa/setuptools_scm/blob/v6.3.0/setup.cfg#L30 Oops...

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-importlib-metadata/package.py b/var/spack/repos/builtin/packages/py-importlib-metadata/package.py
--- a/var/spack/repos/builtin/packages/py-importlib-metadata/package.py
+++ b/var/spack/repos/builtin/packages/py-importlib-metadata/package.py
@@ -13,7 +13,7 @@ class PyImportlibMetadata(PythonPackage):
     pypi = "importlib_metadata/importlib_metadata-1.2.0.tar.gz"
 
     version('4.8.1', sha256='f284b3e11256ad1e5d03ab86bb2ccd6f5339688ff17a4d797a0fe7df326f23b1')
-    version('4.6.1', sha256='079ada16b7fc30dfbb5d13399a5113110dab1aa7c2bc62f66af75f0b717c8cac', preferred=True)
+    version('4.6.1', sha256='079ada16b7fc30dfbb5d13399a5113110dab1aa7c2bc62f66af75f0b717c8cac')
     version('3.10.1', sha256='c9356b657de65c53744046fa8f7358afe0714a1af7d570c00c3835c2d724a7c1')
     version('3.10.0', sha256='c9db46394197244adf2f0b08ec5bc3cf16757e9590b02af1fca085c16c0d600a')
     version('2.0.0', sha256='77a540690e24b0305878c37ffd421785a6f7e53c8b5720d211b211de8d0e95da')
diff --git a/var/spack/repos/builtin/packages/py-setuptools-scm/package.py b/var/spack/repos/builtin/packages/py-setuptools-scm/package.py
--- a/var/spack/repos/builtin/packages/py-setuptools-scm/package.py
+++ b/var/spack/repos/builtin/packages/py-setuptools-scm/package.py
@@ -13,7 +13,7 @@ class PySetuptoolsScm(PythonPackage):
     pypi = "setuptools_scm/setuptools_scm-4.1.2.tar.gz"
 
     version('6.3.2',  sha256='a49aa8081eeb3514eb9728fa5040f2eaa962d6c6f4ec9c32f6c1fba88f88a0f2')
-    version('6.0.1',  sha256='d1925a69cb07e9b29416a275b9fadb009a23c148ace905b2fb220649a6c18e92', preferred=True)
+    version('6.0.1',  sha256='d1925a69cb07e9b29416a275b9fadb009a23c148ace905b2fb220649a6c18e92')
     version('4.1.2',  sha256='a8994582e716ec690f33fec70cca0f85bd23ec974e3f783233e4879090a7faa8')
     version('3.5.0',  sha256='5bdf21a05792903cafe7ae0c9501182ab52497614fa6b1750d9dbae7b60c1a87')
     version('3.3.3',  sha256='bd25e1fb5e4d603dcf490f1fde40fb4c595b357795674c3e5cb7f6217ab39ea5')
@@ -31,3 +31,5 @@ class PySetuptoolsScm(PythonPackage):
 
     depends_on('py-toml', when='+toml @:6.1.0', type=('build', 'run'))
     depends_on('py-tomli@1.0.0:', when='+toml @6.1.0:', type=('build', 'run'))
+
+    depends_on('py-packaging@20.0:', when='@6.3.0:', type=('build', 'run'))


Test patch: