Add a __reduce__ method to Spec (#25658)
Add a __reduce__ method to Spec (#25658)

* Add a __reduce__ method to Spec

fixes #23892

The recursion limit seems to be due to the default
way in which a Spec is serialized, following all
the attributes. It's still not clear to me why this
is related to being in an environment, but in any
case we already have methods to serialize Specs to
disk in JSON and YAML format. Here we use them to
pickle a Spec instance too.

* Downgrade to build-hash

Hopefully nothing will change the package in
between serializing the spec and sending it
to the child process.

* Add support for Python 2
LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack