diff --git a/packages/py-deap/package.py b/packages/py-deap/package.py
index 1841b020953bde7862d5e147f15c1f16a568a8ca..afafdcf7407bd2a2bf63c4a878a7e0d06638af2b 100644
--- a/packages/py-deap/package.py
+++ b/packages/py-deap/package.py
@@ -1,12 +1,11 @@
-# (this package was adapted from the spack develop upstream as a dependency of py-bluepyopt)
+# this package was backported from the spack develop upstream to support newer setuptools
 
 # Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
-
-from spack import *
+from spack.package import *
 
 
 class PyDeap(PythonPackage):
@@ -15,10 +14,10 @@ class PyDeap(PythonPackage):
     homepage = "https://deap.readthedocs.org/"
     pypi = "deap/deap-1.3.1.tar.gz"
 
-    maintainers = ["hjorth", "elmath"]
-
     version("1.3.3", sha256="8772f1b0fff042d5e516b0aebac2c706243045aa7d0de8e0b8658f380181cf31")
     version("1.3.1", sha256="11f54493ceb54aae10dde676577ef59fc52d52f82729d5a12c90b0813c857a2f")
 
-    depends_on("py-setuptools@:57", type=("build"))
-    depends_on("py-numpy",          type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    # uses 2to3
+    depends_on("py-setuptools@:57", type="build", when="@1.3.1")
+    depends_on("py-numpy", type=("build", "run"))
diff --git a/packages/py-ipycanvas/package.py b/packages/py-ipycanvas/package.py
index e2142728bc5347a755c57a119d77ff1515c4121d..4456c1fdfac3679290a84f517169a9c88f331500 100644
--- a/packages/py-ipycanvas/package.py
+++ b/packages/py-ipycanvas/package.py
@@ -1,3 +1,5 @@
+# this package was adapted from Spack upstream v0.19.2, to add version 0.12.0
+
 # Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
@@ -10,20 +12,20 @@ class PyIpycanvas(PythonPackage):
     """Interactive Canvas in Jupyter."""
 
     homepage = "https://github.com/martinRenou/ipycanvas"
-    pypi     = "ipycanvas/ipycanvas-0.9.0.tar.gz"
+    pypi = "ipycanvas/ipycanvas-0.9.0.tar.gz"
 
-    version('0.12.0', sha256='3984339cef0c15674e347dd65ffb0cd1edc62e37869cbb5efea46f3259e976f3')
-    version('0.10.2', sha256='a02c494834cb3c60509801172e7429beae837b3cb6c61d3becf8b586c5a66004')
-    version('0.9.0', sha256='f29e56b93fe765ceace0676c3e75d44e02a3ff6c806f3b7e5b869279f470cc43')
+    version("0.12.0", sha256="3984339cef0c15674e347dd65ffb0cd1edc62e37869cbb5efea46f3259e976f3")
+    version("0.10.2", sha256="a02c494834cb3c60509801172e7429beae837b3cb6c61d3becf8b586c5a66004")
+    version("0.9.0", sha256="f29e56b93fe765ceace0676c3e75d44e02a3ff6c806f3b7e5b869279f470cc43")
 
-    depends_on('python@3.5:', type=('build', 'run'))
-    depends_on('python@3.6:', when='@10:', type=('build', 'run'))
-    depends_on('python@3.7:', when='@11:', type=('build', 'run'))
-    depends_on('py-setuptools@40.8:', type='build')
+    depends_on("python@3.5:", type=("build", "run"))
+    depends_on("python@3.6:", when="@10:", type=("build", "run"))
+    depends_on("python@3.7:", when="@11:", type=("build", "run"))
+    depends_on("py-setuptools@40.8:", type="build")
     # TODO: replace this after concretizer learns how to concretize separate build deps
-    depends_on('py-jupyter-packaging7', type='build')
+    depends_on("py-jupyter-packaging7", type="build")
     # depends_on('py-jupyter-packaging@0.7.0:0.7', type='build')
-    depends_on('py-jupyterlab@3.0:3', type='build')
-    depends_on('py-ipywidgets@7.6:', type=('build', 'run'))
-    depends_on('pil@6:', type=('build', 'run'))
-    depends_on('py-numpy', type=('build', 'run'))
+    depends_on("py-jupyterlab@3.0:3", type="build")
+    depends_on("py-ipywidgets@7.6:", type=("build", "run"))
+    depends_on("pil@6:", type=("build", "run"))
+    depends_on("py-numpy", type=("build", "run"))
diff --git a/packages/py-nilearn/package.py b/packages/py-nilearn/package.py
index 40129e7f4a8a19f4f9e2860e0304a5729664485e..0bbc024662fcfedad0ff31f4a38063cde22aecb6 100644
--- a/packages/py-nilearn/package.py
+++ b/packages/py-nilearn/package.py
@@ -1,6 +1,6 @@
 # this package was added from spack develop:
 # https://github.com/spack/spack/blob/c10b84f08d1febce6d1f64a5f8b9cbff73e461d9/var/spack/repos/builtin/packages/py-nilearn/package.py
-# to fix a typo in 0.19.0 version (https://github.com/spack/spack/pull/34284)
+# to fix a typo in 0.19.2 version (https://github.com/spack/spack/pull/34284)
 
 # Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
diff --git a/packages/py-scipy/package.py b/packages/py-scipy/package.py
index f3290e6ed221939dd6c45a66df3a190bb7632f05..d689b89be469cd282c8a6393d2a085243520c738 100644
--- a/packages/py-scipy/package.py
+++ b/packages/py-scipy/package.py
@@ -1,14 +1,18 @@
-# this package was slightly adapted from the spack v0.18.1 upstream because with py-pybind11@2.10.1
+# this package was slightly adapted from the spack v0.19.2 upstream because with py-pybind11@2.10.1
 # available, the concretizer selected py-scipy@1.5:1.6.1
-# depends_on('py-pybind11@2.4.3:2.8', when='@1.8:', type=('build', 'link'))
+#     depends_on("py-pybind11@2.4.3:2.8", when="@1.8:", type=("build", "link"))
 # was changed to
-# depends_on('py-pybind11@2.4.3:', when='@1.8:', type=('build', 'link'))
+#     depends_on("py-pybind11@2.4.3:", when="@1.8:", type=("build", "link"))
 
 # Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
+
+from spack.package import *
+
+
 class PyScipy(PythonPackage):
     """SciPy (pronounced "Sigh Pie") is a Scientific Library for Python.
     It provides many user-friendly and efficient numerical routines such
@@ -18,107 +22,140 @@ class PyScipy(PythonPackage):
     pypi = "scipy/scipy-1.5.4.tar.gz"
     git = "https://github.com/scipy/scipy.git"
 
-    maintainers = ['adamjstewart', 'rgommers']
-
-    version('master', branch='master')
-    version('1.8.1',  sha256='9e3fb1b0e896f14a85aa9a28d5f755daaeeb54c897b746df7a55ccb02b340f33')
-    version('1.8.0',  sha256='31d4f2d6b724bc9a98e527b5849b8a7e589bf1ea630c33aa563eda912c9ff0bd')
-    version('1.7.3',  sha256='ab5875facfdef77e0a47d5fd39ea178b58e60e454a4c85aa1e52fcb80db7babf')
-    version('1.7.2',  sha256='fa2dbabaaecdb502641b0b3c00dec05fb475ae48655c66da16c9ed24eda1e711')
-    version('1.7.1',  sha256='6b47d5fa7ea651054362561a28b1ccc8da9368a39514c1bbf6c0977a1c376764')
-    version('1.7.0',  sha256='998c5e6ea649489302de2c0bc026ed34284f531df89d2bdc8df3a0d44d165739')
-    version('1.6.3',  sha256='a75b014d3294fce26852a9d04ea27b5671d86736beb34acdfc05859246260707')
-    version('1.6.2',  sha256='e9da33e21c9bc1b92c20b5328adb13e5f193b924c9b969cd700c8908f315aa59')
-    version('1.6.1',  sha256='c4fceb864890b6168e79b0e714c585dbe2fd4222768ee90bc1aa0f8218691b11')
-    version('1.6.0',  sha256='cb6dc9f82dfd95f6b9032a8d7ea70efeeb15d5b5fd6ed4e8537bb3c673580566')
-    version('1.5.4',  sha256='4a453d5e5689de62e5d38edf40af3f17560bfd63c9c5bd228c18c1f99afa155b')
-    version('1.5.3',  sha256='ddae76784574cc4c172f3d5edd7308be16078dd3b977e8746860c76c195fa707')
-    version('1.5.2',  sha256='066c513d90eb3fd7567a9e150828d39111ebd88d3e924cdfc9f8ce19ab6f90c9')
-    version('1.5.1',  sha256='039572f0ca9578a466683558c5bf1e65d442860ec6e13307d528749cfe6d07b8')
-    version('1.5.0',  sha256='4ff72877d19b295ee7f7727615ea8238f2d59159df0bdd98f91754be4a2767f0')
-    version('1.4.1',  sha256='dee1bbf3a6c8f73b6b218cb28eed8dd13347ea2f87d572ce19b289d6fd3fbc59')
-    version('1.4.0',  sha256='31f7cfa93b01507c935c12b535e24812594002a02a56803d7cd063e9920d25e8')
-    version('1.3.3',  sha256='64bf4e8ae0db2d42b58477817f648d81e77f0b381d0ea4427385bba3f959380a')
-    version('1.3.2',  sha256='a03939b431994289f39373c57bbe452974a7da724ae7f9620a1beee575434da4')
-    version('1.3.1',  sha256='2643cfb46d97b7797d1dbdb6f3c23fe3402904e3c90e6facfe6a9b98d808c1b5')
-    version('1.3.0',  sha256='c3bb4bd2aca82fb498247deeac12265921fe231502a6bc6edea3ee7fe6c40a7a')
-    version('1.2.3',  sha256='ecbe6413ca90b8e19f8475bfa303ac001e81b04ec600d17fa7f816271f7cca57')
-    version('1.2.2',  sha256='a4331e0b8dab1ff75d2c67b5158a8bb9a83c799d7140094dda936d876c7cfbb1')
-    version('1.2.1',  sha256='e085d1babcb419bbe58e2e805ac61924dac4ca45a07c9fa081144739e500aa3c')
-    version('1.1.0',  sha256='878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1')
-    version('1.0.0',  sha256='87ea1f11a0e9ec08c264dc64551d501fa307289460705f6fccd84cbfc7926d10')
-    version('0.19.1', sha256='a19a2ca7a7336495ec180adeaa0dfdcf41e96dbbee90d51c3ed828ba570884e6')
-    version('0.18.1', sha256='8ab6e9c808bf2fb3e8576cd8cf07226d9cdc18b012c06d9708429a821ac6634e')
-    version('0.17.0', sha256='f600b755fb69437d0f70361f9e560ab4d304b1b66987ed5a28bdd9dd7793e089')
-    version('0.15.1', sha256='a212cbc3b79e9a563aa45fc5c517b3499198bd7eb7e7be1e047568a5f48c259a')
-    version('0.15.0', sha256='0c74e31e08acc8bf9b6ceb9bced73df2ae0cc76003e0366350bc7b26292bf8b1')
+    maintainers = ["adamjstewart", "rgommers"]
+
+    version("master", branch="master")
+    version("1.8.1", sha256="9e3fb1b0e896f14a85aa9a28d5f755daaeeb54c897b746df7a55ccb02b340f33")
+    version("1.8.0", sha256="31d4f2d6b724bc9a98e527b5849b8a7e589bf1ea630c33aa563eda912c9ff0bd")
+    version("1.7.3", sha256="ab5875facfdef77e0a47d5fd39ea178b58e60e454a4c85aa1e52fcb80db7babf")
+    version("1.7.2", sha256="fa2dbabaaecdb502641b0b3c00dec05fb475ae48655c66da16c9ed24eda1e711")
+    version("1.7.1", sha256="6b47d5fa7ea651054362561a28b1ccc8da9368a39514c1bbf6c0977a1c376764")
+    version("1.7.0", sha256="998c5e6ea649489302de2c0bc026ed34284f531df89d2bdc8df3a0d44d165739")
+    version("1.6.3", sha256="a75b014d3294fce26852a9d04ea27b5671d86736beb34acdfc05859246260707")
+    version("1.6.2", sha256="e9da33e21c9bc1b92c20b5328adb13e5f193b924c9b969cd700c8908f315aa59")
+    version("1.6.1", sha256="c4fceb864890b6168e79b0e714c585dbe2fd4222768ee90bc1aa0f8218691b11")
+    version("1.6.0", sha256="cb6dc9f82dfd95f6b9032a8d7ea70efeeb15d5b5fd6ed4e8537bb3c673580566")
+    version("1.5.4", sha256="4a453d5e5689de62e5d38edf40af3f17560bfd63c9c5bd228c18c1f99afa155b")
+    version("1.5.3", sha256="ddae76784574cc4c172f3d5edd7308be16078dd3b977e8746860c76c195fa707")
+    version("1.5.2", sha256="066c513d90eb3fd7567a9e150828d39111ebd88d3e924cdfc9f8ce19ab6f90c9")
+    version("1.5.1", sha256="039572f0ca9578a466683558c5bf1e65d442860ec6e13307d528749cfe6d07b8")
+    version("1.5.0", sha256="4ff72877d19b295ee7f7727615ea8238f2d59159df0bdd98f91754be4a2767f0")
+    version("1.4.1", sha256="dee1bbf3a6c8f73b6b218cb28eed8dd13347ea2f87d572ce19b289d6fd3fbc59")
+    version("1.4.0", sha256="31f7cfa93b01507c935c12b535e24812594002a02a56803d7cd063e9920d25e8")
+    version("1.3.3", sha256="64bf4e8ae0db2d42b58477817f648d81e77f0b381d0ea4427385bba3f959380a")
+    version("1.3.2", sha256="a03939b431994289f39373c57bbe452974a7da724ae7f9620a1beee575434da4")
+    version("1.3.1", sha256="2643cfb46d97b7797d1dbdb6f3c23fe3402904e3c90e6facfe6a9b98d808c1b5")
+    version("1.3.0", sha256="c3bb4bd2aca82fb498247deeac12265921fe231502a6bc6edea3ee7fe6c40a7a")
+    version("1.2.3", sha256="ecbe6413ca90b8e19f8475bfa303ac001e81b04ec600d17fa7f816271f7cca57")
+    version("1.2.2", sha256="a4331e0b8dab1ff75d2c67b5158a8bb9a83c799d7140094dda936d876c7cfbb1")
+    version("1.2.1", sha256="e085d1babcb419bbe58e2e805ac61924dac4ca45a07c9fa081144739e500aa3c")
+    version("1.1.0", sha256="878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1")
+    version("1.0.0", sha256="87ea1f11a0e9ec08c264dc64551d501fa307289460705f6fccd84cbfc7926d10")
+    version("0.19.1", sha256="a19a2ca7a7336495ec180adeaa0dfdcf41e96dbbee90d51c3ed828ba570884e6")
+    version("0.18.1", sha256="8ab6e9c808bf2fb3e8576cd8cf07226d9cdc18b012c06d9708429a821ac6634e")
+    version("0.17.0", sha256="f600b755fb69437d0f70361f9e560ab4d304b1b66987ed5a28bdd9dd7793e089")
+    version("0.15.1", sha256="a212cbc3b79e9a563aa45fc5c517b3499198bd7eb7e7be1e047568a5f48c259a")
+    version("0.15.0", sha256="0c74e31e08acc8bf9b6ceb9bced73df2ae0cc76003e0366350bc7b26292bf8b1")
 
     # pyproject.toml
-    depends_on('py-wheel@:0.37', type='build')
-    depends_on('py-setuptools', type='build')
-    depends_on('py-setuptools@:51.0.0', when='@1.6', type='build')
-    depends_on('py-setuptools@:57', when='@1.7', type='build')
-    depends_on('py-setuptools@:59', when='@1.8:', type='build')
-    depends_on('py-cython@0.29.18:2', when='@1.7:', type='build')
-    depends_on('py-pybind11@2.2.4:', when='@1.4.0', type=('build', 'link'))
-    depends_on('py-pybind11@2.4.0:', when='@1.4.1:1.4', type=('build', 'link'))
-    depends_on('py-pybind11@2.4.3:', when='@1.5:1.6.1', type=('build', 'link'))
-    depends_on('py-pybind11@2.4.3:2.6', when='@1.6.2:1.7.1', type=('build', 'link'))
-    depends_on('py-pybind11@2.4.3:2.7', when='@1.7.2:1.7', type=('build', 'link'))
-    depends_on('py-pybind11@2.4.3:', when='@1.8:', type=('build', 'link'))
-    depends_on('py-pythran@0.9.11', when='@1.7.0:1.7.1', type=('build', 'link'))
-    depends_on('py-pythran@0.9.12:0.9', when='@1.7.2:1.7', type=('build', 'link'))
-    depends_on('py-pythran@0.10:', when='@1.8:', type=('build', 'link'))
+    depends_on("py-wheel@:0.37", type="build")
+    depends_on("py-setuptools", type="build")
+    depends_on("py-setuptools@:51.0.0", when="@1.6", type="build")
+    depends_on("py-setuptools@:57", when="@1.7", type="build")
+    depends_on("py-setuptools@:59", when="@1.8:", type="build")
+    depends_on("py-cython@0.29.18:2", when="@1.7:", type="build")
+    depends_on("py-pybind11@2.2.4:", when="@1.4.0", type=("build", "link"))
+    depends_on("py-pybind11@2.4.0:", when="@1.4.1:1.4", type=("build", "link"))
+    depends_on("py-pybind11@2.4.3:", when="@1.5:1.6.1", type=("build", "link"))
+    depends_on("py-pybind11@2.4.3:2.6", when="@1.6.2:1.7.1", type=("build", "link"))
+    depends_on("py-pybind11@2.4.3:2.7", when="@1.7.2:1.7", type=("build", "link"))
+    depends_on("py-pybind11@2.4.3:", when="@1.8:", type=("build", "link"))
+    depends_on("py-pythran@0.9.11", when="@1.7.0:1.7.1", type=("build", "link"))
+    depends_on("py-pythran@0.9.12:0.9", when="@1.7.2:1.7", type=("build", "link"))
+    depends_on("py-pythran@0.10:", when="@1.8:", type=("build", "link"))
     # setup.py
-    depends_on('py-numpy@1.5.1:+blas+lapack', when='@:0.15', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.6.2:+blas+lapack', when='@0.16:0.17', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.7.1:+blas+lapack', when='@0.18.0:0.18', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.8.2:+blas+lapack', when='@0.19:1.2', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.13.3:+blas+lapack', when='@1.3:1.4', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.14.5:+blas+lapack', when='@1.5.0:1.5', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.16.5:+blas+lapack', when='@1.6:1.6.1', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.16.5:1.22+blas+lapack', when='@1.6.2:1.7', type=('build', 'link', 'run'))
-    depends_on('py-numpy@1.17.3:1.24+blas+lapack', when='@1.8:', type=('build', 'link', 'run'))
-    depends_on('python@2.6:2.8,3.2:', when='@:0.17', type=('build', 'link', 'run'))
-    depends_on('python@2.7:2.8,3.4:', when='@0.18:1.2', type=('build', 'link', 'run'))
-    depends_on('python@3.5:', when='@1.3:1.4', type=('build', 'link', 'run'))
-    depends_on('python@3.6:', when='@1.5.0:1.5', type=('build', 'link', 'run'))
-    depends_on('python@3.7:', when='@1.6:1.6.1', type=('build', 'link', 'run'))
-    depends_on('python@3.7:3.9', when='@1.6.2:1.7.1', type=('build', 'link', 'run'))
-    depends_on('python@3.7:3.10', when='@1.7.2:1.7', type=('build', 'link', 'run'))
-    depends_on('python@3.8:3.10', when='@1.8:', type=('build', 'link', 'run'))
-    depends_on('py-pytest', type='test')
-
-    # NOTE: scipy picks up Blas/Lapack from numpy, see
-    # http://www.scipy.org/scipylib/building/linux.html#step-4-build-numpy-1-5-0
-    depends_on('blas')
-    depends_on('lapack')
+    depends_on("py-numpy@1.5.1:+blas+lapack", when="@:0.15", type=("build", "link", "run"))
+    depends_on("py-numpy@1.6.2:+blas+lapack", when="@0.16:0.17", type=("build", "link", "run"))
+    depends_on("py-numpy@1.7.1:+blas+lapack", when="@0.18.0:0.18", type=("build", "link", "run"))
+    depends_on("py-numpy@1.8.2:+blas+lapack", when="@0.19:1.2", type=("build", "link", "run"))
+    depends_on("py-numpy@1.13.3:+blas+lapack", when="@1.3:1.4", type=("build", "link", "run"))
+    depends_on("py-numpy@1.14.5:+blas+lapack", when="@1.5.0:1.5", type=("build", "link", "run"))
+    depends_on("py-numpy@1.16.5:+blas+lapack", when="@1.6:1.6.1", type=("build", "link", "run"))
+    depends_on(
+        "py-numpy@1.16.5:1.22+blas+lapack", when="@1.6.2:1.7", type=("build", "link", "run")
+    )
+    depends_on("py-numpy@1.17.3:1.24+blas+lapack", when="@1.8:", type=("build", "link", "run"))
+    depends_on("python@2.6:2.8,3.2:", when="@:0.17", type=("build", "link", "run"))
+    depends_on("python@2.7:2.8,3.4:", when="@0.18:1.2", type=("build", "link", "run"))
+    depends_on("python@3.5:", when="@1.3:1.4", type=("build", "link", "run"))
+    depends_on("python@3.6:", when="@1.5.0:1.5", type=("build", "link", "run"))
+    depends_on("python@3.7:", when="@1.6:1.6.1", type=("build", "link", "run"))
+    depends_on("python@3.7:3.9", when="@1.6.2:1.7.1", type=("build", "link", "run"))
+    depends_on("python@3.7:3.10", when="@1.7.2:1.7", type=("build", "link", "run"))
+    depends_on("python@3.8:3.10", when="@1.8:", type=("build", "link", "run"))
+    depends_on("py-pytest", type="test")
+
+    # NOTE: scipy should use the same Blas/Lapack as numpy
+    # This is achieved by calling the set_blas_lapack() and setup_build_environment()
+    # from numpy in the scipy spec
+    depends_on("blas")
+    depends_on("lapack")
     # https://github.com/scipy/scipy/wiki/Dropping-support-for-Accelerate
-    depends_on('lapack@3.4.1:', when='@1.2:')
+    depends_on("lapack@3.4.1:", when="@1.2:")
+
+    # https://github.com/scipy/scipy/pull/11324
+    conflicts("@1.4.0:1.4.1", when="target=ppc64le:")
 
     # https://github.com/scipy/scipy/issues/12860
-    patch('https://git.sagemath.org/sage.git/plain/build/pkgs/scipy/patches/extern_decls.patch?id=711fe05025795e44b84233e065d240859ccae5bd',
-          sha256='5433f60831cb554101520a8f8871ac5a32c95f7a971ccd68b69049535b106780', when='@1.2:1.5.3')
+    patch(
+        "https://git.sagemath.org/sage.git/plain/build/pkgs/scipy/patches/extern_decls.patch?id=711fe05025795e44b84233e065d240859ccae5bd",
+        sha256="5433f60831cb554101520a8f8871ac5a32c95f7a971ccd68b69049535b106780",
+        when="@1.2:1.5.3",
+    )
+
+    patch("scipy-clang.patch", when="@1.5.0:1.6.3 %clang")
+
+    @run_before("install")
+    def set_blas_lapack(self):
+        # Pick up Blas/Lapack from numpy
+        self.spec["py-numpy"].package.set_blas_lapack()
 
-    patch('scipy-clang.patch', when='@1.5.0:1.6.3 %clang')
+    @run_before("install")
+    def set_fortran_compiler(self):
+        if self.spec.satisfies("%fj"):
+            with open("setup.cfg", "w") as f:
+                f.write("[config_fc]\n")
+                f.write("fcompiler = fujitsu\n")
+        elif self.spec.satisfies("%intel") or self.spec.satisfies("%oneapi"):
+            if self.spec.satisfies("target=x86:"):
+                with open("setup.cfg", "w") as f:
+                    f.write("[config_fc]\n")
+                    f.write("fcompiler = intel\n")
+            elif self.spec.satisfies("target=x86_64:"):
+                with open("setup.cfg", "w") as f:
+                    f.write("[config_fc]\n")
+                    f.write("fcompiler = intelem\n")
 
     def setup_build_environment(self, env):
         # https://github.com/scipy/scipy/issues/9080
-        env.set('F90', spack_fc)
+        env.set("F90", spack_fc)
 
         # https://github.com/scipy/scipy/issues/11611
-        if self.spec.satisfies('@:1.4 %gcc@10:'):
-            env.set('FFLAGS', '-fallow-argument-mismatch')
+        if self.spec.satisfies("@:1.4 %gcc@10:"):
+            env.set("FFLAGS", "-fallow-argument-mismatch")
+            if self.spec.satisfies("^py-numpy@1.16:1.17"):
+                env.set("NPY_DISTUTILS_APPEND_FLAGS", "1")
 
-    def install_options(self, spec, prefix):
-        args = []
-        if spec.satisfies('%fj'):
-            args.extend(['config_fc', '--fcompiler=fujitsu'])
-        return args
+        # https://github.com/scipy/scipy/issues/14935
+        if self.spec.satisfies("%intel ^py-pythran") or self.spec.satisfies("%oneapi ^py-pythran"):
+            if self.spec["py-pythran"].version < Version("0.12"):
+                env.set("SCIPY_USE_PYTHRAN", "0")
 
-    @run_after('install')
+        # Pick up Blas/Lapack from numpy
+        self.spec["py-numpy"].package.setup_build_environment(env)
+
+    @run_after("install")
     @on_package_attributes(run_tests=True)
     def install_test(self):
-        with working_dir('spack-test', create=True):
-            python('-c', 'import scipy; scipy.test("full", verbose=2)')
-
+        with working_dir("spack-test", create=True):
+            python("-c", 'import scipy; scipy.test("full", verbose=2)')
diff --git a/packages/py-torch/package.py b/packages/py-torch/package.py
index ce683443e9bf9226393edf7ed102ab6bdd3f2f9b..641955a02a44d39916335af196e40c28e85fcdea 100644
--- a/packages/py-torch/package.py
+++ b/packages/py-torch/package.py
@@ -6,263 +6,342 @@
 import os
 import sys
 
-from spack import *
+from spack.operating_systems.mac_os import macos_version
+from spack.package import *
 
 
-class PyTorch(PythonPackage, CudaPackage):
+class PyTorch(PythonPackage, CudaPackage, ROCmPackage):
     """Tensors and Dynamic neural networks in Python
     with strong GPU acceleration."""
 
     homepage = "https://pytorch.org/"
-    git      = "https://github.com/pytorch/pytorch.git"
+    git = "https://github.com/pytorch/pytorch.git"
 
-    maintainers = ['adamjstewart']
+    maintainers = ["adamjstewart"]
 
     # Exact set of modules is version- and variant-specific, just attempt to import the
     # core libraries to ensure that the package was successfully installed.
-    import_modules = ['torch', 'torch.autograd', 'torch.nn', 'torch.utils']
-
-    version('master', branch='master', submodules=True)
-    version('1.11.0', tag='v1.11.0', submodules=True)
-    version('1.10.2', tag='v1.10.2', submodules=True)
-    version('1.10.1', tag='v1.10.1', submodules=True)
-    version('1.10.0', tag='v1.10.0', submodules=True)
-    version('1.9.1', tag='v1.9.1', submodules=True)
-    version('1.9.0', tag='v1.9.0', submodules=True)
-    version('1.8.2', tag='v1.8.2', submodules=True)
-    version('1.8.1', tag='v1.8.1', submodules=True)
-    version('1.8.0', tag='v1.8.0', submodules=True)
-    version('1.7.1', tag='v1.7.1', submodules=True)
-    version('1.7.0', tag='v1.7.0', submodules=True)
-    version('1.6.0', tag='v1.6.0', submodules=True)
-    version('1.5.1', tag='v1.5.1', submodules=True)
-    version('1.5.0', tag='v1.5.0', submodules=True)
-    version('1.4.1', tag='v1.4.1', submodules=True)
-    version('1.3.1', tag='v1.3.1', submodules=True)
-    version('1.3.0', tag='v1.3.0', submodules=True)
-    version('1.2.0', tag='v1.2.0', submodules=True)
-    version('1.1.0', tag='v1.1.0', submodules=True)
-    version('1.0.1', tag='v1.0.1', submodules=True, deprecated=True)
-    version('1.0.0', tag='v1.0.0', submodules=True, deprecated=True)
-
-    is_darwin = sys.platform == 'darwin'
+    import_modules = ["torch", "torch.autograd", "torch.nn", "torch.utils"]
+
+    version("master", branch="master", submodules=True)
+    version("1.13.0", tag="v1.13.0", submodules=True)
+    version("1.12.1", tag="v1.12.1", submodules=True)
+    version("1.12.0", tag="v1.12.0", submodules=True)
+    version("1.11.0", tag="v1.11.0", submodules=True)
+    version("1.10.2", tag="v1.10.2", submodules=True)
+    version("1.10.1", tag="v1.10.1", submodules=True)
+    version("1.10.0", tag="v1.10.0", submodules=True)
+    version("1.9.1", tag="v1.9.1", submodules=True)
+    version("1.9.0", tag="v1.9.0", submodules=True)
+    version("1.8.2", tag="v1.8.2", submodules=True)
+    version("1.8.1", tag="v1.8.1", submodules=True)
+    version("1.8.0", tag="v1.8.0", submodules=True)
+    version("1.7.1", tag="v1.7.1", submodules=True)
+    version("1.7.0", tag="v1.7.0", submodules=True)
+    version("1.6.0", tag="v1.6.0", submodules=True)
+    version("1.5.1", tag="v1.5.1", submodules=True)
+    version("1.5.0", tag="v1.5.0", submodules=True)
+    version("1.4.1", tag="v1.4.1", submodules=True)
+    version("1.3.1", tag="v1.3.1", submodules=True)
+    version("1.3.0", tag="v1.3.0", submodules=True)
+    version("1.2.0", tag="v1.2.0", submodules=True)
+    version("1.1.0", tag="v1.1.0", submodules=True)
+    version("1.0.1", tag="v1.0.1", submodules=True)
+    version("1.0.0", tag="v1.0.0", submodules=True)
+
+    is_darwin = sys.platform == "darwin"
 
     # All options are defined in CMakeLists.txt.
     # Some are listed in setup.py, but not all.
-    variant('debug', default=False, description="Build with debugging support")
-    variant('caffe2', default=True, description='Build Caffe2', when='@1.7:')
-    variant('test', default=False, description='Build C++ test binaries')
-    variant('cuda', default=not is_darwin, description='Use CUDA')
-    variant('rocm', default=False, description='Use ROCm')
-    variant('cudnn', default=not is_darwin, description='Use cuDNN', when='+cuda')
-    variant('fbgemm', default=True, description='Use FBGEMM (quantized 8-bit server operators)')
-    variant('kineto', default=True, description='Use Kineto profiling library', when='@1.8:')
-    variant('magma', default=not is_darwin, description='Use MAGMA', when='+cuda')
-    variant('metal', default=is_darwin, description='Use Metal for Caffe2 iOS build')
-    variant('nccl', default=True, description='Use NCCL', when='+cuda platform=linux')
-    variant('nccl', default=True, description='Use NCCL', when='+cuda platform=cray')
-    variant('nccl', default=True, description='Use NCCL', when='+rocm platform=linux')
-    variant('nccl', default=True, description='Use NCCL', when='+rocm platform=cray')
-    variant('nnpack', default=True, description='Use NNPACK')
-    variant('numa', default=True, description='Use NUMA', when='platform=linux')
-    variant('numa', default=True, description='Use NUMA', when='platform=cray')
-    variant('numpy', default=True, description='Use NumPy')
-    variant('openmp', default=True, description='Use OpenMP for parallel code')
-    variant('qnnpack', default=True, description='Use QNNPACK (quantized 8-bit operators)')
-    variant('valgrind', default=True, description='Use Valgrind', when='@1.8: platform=linux')
-    variant('valgrind', default=True, description='Use Valgrind', when='@1.8: platform=cray')
-    variant('xnnpack', default=True, description='Use XNNPACK', when='@1.5:')
-    variant('mkldnn', default=True, description='Use MKLDNN')
-    variant('distributed', default=not is_darwin, description='Use distributed')
-    variant('mpi', default=not is_darwin, description='Use MPI for Caffe2', when='+distributed')
-    variant('gloo', default=not is_darwin, description='Use Gloo', when='+distributed')
-    variant('tensorpipe', default=not is_darwin, description='Use TensorPipe', when='@1.6: +distributed')
-    variant('onnx_ml', default=True, description='Enable traditional ONNX ML API', when='@1.5:')
-    variant('breakpad', default=True, description='Enable breakpad crash dump library', when='@1.9:')
-
-    conflicts('+cuda+rocm')
-    conflicts('+breakpad', when='target=ppc64:')
-    conflicts('+breakpad', when='target=ppc64le:')
-
-    conflicts('cuda_arch=none', when='+cuda',
-              msg='Must specify CUDA compute capabilities of your GPU, see '
-              'https://developer.nvidia.com/cuda-gpus')
+    variant("debug", default=False, description="Build with debugging support")
+    variant("caffe2", default=False, description="Build Caffe2", when="@1.7:")
+    variant("test", default=False, description="Build C++ test binaries")
+    variant("cuda", default=not is_darwin, description="Use CUDA")
+    variant("rocm", default=False, description="Use ROCm")
+    variant("cudnn", default=not is_darwin, description="Use cuDNN", when="+cuda")
+    variant("fbgemm", default=True, description="Use FBGEMM (quantized 8-bit server operators)")
+    variant("kineto", default=True, description="Use Kineto profiling library", when="@1.8:")
+    variant("magma", default=not is_darwin, description="Use MAGMA", when="+cuda")
+    variant("metal", default=is_darwin, description="Use Metal for Caffe2 iOS build")
+    variant(
+        "mps",
+        default=is_darwin and macos_version() >= Version("12.3"),
+        description="Use MPS for macOS build",
+        when="@1.12: platform=darwin",
+    )
+    variant("nccl", default=True, description="Use NCCL", when="+cuda platform=linux")
+    variant("nccl", default=True, description="Use NCCL", when="+cuda platform=cray")
+    variant("nccl", default=True, description="Use NCCL", when="+rocm platform=linux")
+    variant("nccl", default=True, description="Use NCCL", when="+rocm platform=cray")
+    variant("nnpack", default=True, description="Use NNPACK")
+    variant("numa", default=True, description="Use NUMA", when="platform=linux")
+    variant("numa", default=True, description="Use NUMA", when="platform=cray")
+    variant("numpy", default=True, description="Use NumPy")
+    variant("openmp", default=True, description="Use OpenMP for parallel code")
+    variant("qnnpack", default=True, description="Use QNNPACK (quantized 8-bit operators)")
+    variant("valgrind", default=True, description="Use Valgrind", when="@1.8: platform=linux")
+    variant("valgrind", default=True, description="Use Valgrind", when="@1.8: platform=cray")
+    variant("xnnpack", default=True, description="Use XNNPACK", when="@1.5:")
+    variant("mkldnn", default=True, description="Use MKLDNN")
+    variant("distributed", default=not is_darwin, description="Use distributed")
+    variant("mpi", default=not is_darwin, description="Use MPI for Caffe2", when="+distributed")
+    variant("gloo", default=not is_darwin, description="Use Gloo", when="+distributed")
+    variant(
+        "tensorpipe",
+        default=not is_darwin,
+        description="Use TensorPipe",
+        when="@1.6: +distributed",
+    )
+    variant("onnx_ml", default=True, description="Enable traditional ONNX ML API", when="@1.5:")
+    variant(
+        "breakpad",
+        default=True,
+        description="Enable breakpad crash dump library",
+        when="@1.9:1.11",
+    )
+
+    conflicts("+cuda+rocm")
+    conflicts("+tensorpipe", when="+rocm", msg="TensorPipe doesn't yet support ROCm")
+    conflicts("+breakpad", when="target=ppc64:")
+    conflicts("+breakpad", when="target=ppc64le:")
+
+    # https://github.com/pytorch/pytorch/issues/77811
+    conflicts("+qnnpack", when="platform=darwin target=aarch64:")
+
+    conflicts(
+        "cuda_arch=none",
+        when="+cuda",
+        msg="Must specify CUDA compute capabilities of your GPU, see "
+        "https://developer.nvidia.com/cuda-gpus",
+    )
 
     # Required dependencies
-    depends_on('cmake@3.13:', when='@1.11:', type='build')
-    depends_on('cmake@3.10:', when='@1.10:', type='build')
-    depends_on('cmake@3.5:', type='build')
-    # Use Ninja generator to speed up build times, automatically used if found
-    depends_on('ninja@1.5:', when='@1.1:', type='build')
     # See python_min_version in setup.py
-    depends_on('python@3.7:', when='@1.11:', type=('build', 'link', 'run'))
-    depends_on('python@3.6.2:', when='@1.7.1:', type=('build', 'link', 'run'))
-    depends_on('python@3.6.1:', when='@1.6:1.7.0', type=('build', 'link', 'run'))
-    depends_on('python@3.5:', when='@1.5', type=('build', 'link', 'run'))
-    depends_on('python@2.7:2,3.5:', when='@1.4', type=('build', 'link', 'run'))
-    depends_on('python@2.7:2,3.5:3.7', when='@:1.3', type=('build', 'link', 'run'))
-    depends_on('py-setuptools', type=('build', 'run'))
-    depends_on('py-future', when='@1.5:', type=('build', 'run'))
-    depends_on('py-future', when='@1.1: ^python@:2', type=('build', 'run'))
-    depends_on('py-pyyaml', type=('build', 'run'))
-    depends_on('py-typing', when='^python@:3.4', type=('build', 'run'))
-    depends_on('py-pybind11@2.6.2:', when='@1.8:', type=('build', 'link', 'run'))
-    depends_on('py-pybind11@2.3.0', when='@1.1:1.7', type=('build', 'link', 'run'))
-    depends_on('py-pybind11@2.2.4', when='@:1.0', type=('build', 'link', 'run'))
-    depends_on('py-dataclasses', when='@1.7: ^python@3.6', type=('build', 'run'))
-    depends_on('py-tqdm', type='run')
-    # https://github.com/onnx/onnx#prerequisites
-    depends_on('py-numpy@1.16.6:', type=('build', 'run'))
-    depends_on('py-protobuf@3.12.2:', when='@1.10:', type=('build', 'run'))
-    depends_on('py-protobuf@:3.14', when='@:1.9', type=('build', 'run'))
-    depends_on('protobuf@3.12.2:', when='@1.10:')
-    depends_on('protobuf@:3.14', when='@:1.9')
-    depends_on('py-typing-extensions@3.6.2.1:', when='@1.7:', type=('build', 'run'))
-    depends_on('blas')
-    depends_on('lapack')
-    depends_on('eigen')
+    depends_on("python@3.7:", when="@1.11:", type=("build", "link", "run"))
+    depends_on("python@3.6.2:", when="@1.7.1:", type=("build", "link", "run"))
+    depends_on("python@3.6.1:", when="@1.6:1.7.0", type=("build", "link", "run"))
+    depends_on("python@3.5:", when="@1.5", type=("build", "link", "run"))
+    depends_on("python@2.7:2,3.5:", when="@1.4", type=("build", "link", "run"))
+    depends_on("python@2.7:2,3.5:3.7", when="@:1.3", type=("build", "link", "run"))
+
+    # pyproject.toml
+    depends_on("py-setuptools", type=("build", "run"))
+    depends_on("py-astunparse", when="@1.13:", type=("build", "run"))
+    depends_on("py-numpy@1.16.6:", type=("build", "run"))
+    depends_on("ninja@1.5:", when="@1.1:", type="build")
+    depends_on("py-pyyaml", type=("build", "run"))
+    depends_on("cmake@3.13:", when="@1.11:", type="build")
+    depends_on("cmake@3.10:", when="@1.10:", type="build")
+    depends_on("cmake@3.5:", type="build")
+    depends_on("py-cffi", type=("build", "run"))
+    depends_on("py-typing-extensions@3.6.2.1:", when="@1.7:", type=("build", "run"))
+    depends_on("py-future", when="@1.5:", type=("build", "run"))
+    depends_on("py-future", when="@1.1: ^python@:2", type=("build", "run"))
+    depends_on("py-six", when="@1.13:", type=("build", "run"))
+    depends_on("py-requests", when="@1.13:", type=("build", "run"))
+    depends_on("py-dataclasses", when="@1.7: ^python@3.6", type=("build", "run"))
+
+    # Undocumented dependencies
+    depends_on("py-typing", when="^python@:3.4", type=("build", "run"))
+    depends_on("py-tqdm", type="run")
+    depends_on("blas")
+    depends_on("lapack")
+
+    # third_party
+    depends_on("py-pybind11@2.10.0:", when="@1.13:", type=("build", "link", "run"))
+    depends_on("py-pybind11@2.6.2", when="@1.8:1.12", type=("build", "link", "run"))
+    depends_on("py-pybind11@2.3.0", when="@1.1:1.7", type=("build", "link", "run"))
+    depends_on("py-pybind11@2.2.4", when="@:1.0", type=("build", "link", "run"))
+    depends_on("py-protobuf@3.12.2:", when="@1.10:", type=("build", "run"))
+    depends_on("py-protobuf@:3.14", when="@:1.9", type=("build", "run"))
+    depends_on("protobuf@3.12.2:", when="@1.10:")
+    depends_on("protobuf@:3.14", when="@:1.9")
+    # https://github.com/protocolbuffers/protobuf/issues/10051
+    # https://github.com/pytorch/pytorch/issues/78362
+    depends_on("py-protobuf@:3", type=("build", "run"))
+    depends_on("protobuf@:3", type=("build", "run"))
+    depends_on("eigen")
     # https://github.com/pytorch/pytorch/issues/60329
-    # depends_on('cpuinfo@2020-12-17', when='@1.8:')
-    # depends_on('cpuinfo@2020-06-11', when='@1.6:1.7')
+    # depends_on("cpuinfo@2022-08-19", when="@1.13:")
+    # depends_on("cpuinfo@2020-12-17", when="@1.8:1.12")
+    # depends_on("cpuinfo@2020-06-11", when="@1.6:1.7")
     # https://github.com/shibatch/sleef/issues/427
-    # depends_on('sleef@3.5.1_2020-12-22', when='@1.8:')
+    # depends_on("sleef@3.5.1_2020-12-22", when="@1.8:")
     # https://github.com/pytorch/pytorch/issues/60334
-    # depends_on('sleef@3.4.0_2019-07-30', when='@1.6:1.7')
+    # depends_on("sleef@3.4.0_2019-07-30", when="@1.6:1.7")
     # https://github.com/Maratyszcza/FP16/issues/18
-    # depends_on('fp16@2020-05-14', when='@1.6:')
-    depends_on('pthreadpool@2021-04-13', when='@1.9:')
-    depends_on('pthreadpool@2020-10-05', when='@1.8')
-    depends_on('pthreadpool@2020-06-15', when='@1.6:1.7')
-    depends_on('psimd@2020-05-17', when='@1.6:')
-    depends_on('fxdiv@2020-04-17', when='@1.6:')
-    depends_on('benchmark', when='@1.6:+test')
+    # depends_on("fp16@2020-05-14", when="@1.6:")
+    depends_on("pthreadpool@2021-04-13", when="@1.9:")
+    depends_on("pthreadpool@2020-10-05", when="@1.8")
+    depends_on("pthreadpool@2020-06-15", when="@1.6:1.7")
+    depends_on("psimd@2020-05-17", when="@1.6:")
+    depends_on("fxdiv@2020-04-17", when="@1.6:")
+    depends_on("benchmark", when="@1.6:+test")
 
     # Optional dependencies
     # https://discuss.pytorch.org/t/compiling-1-10-1-from-source-with-gcc-11-and-cuda-11-5/140971
-    depends_on('cuda@9.2:', when='@1.11:+cuda', type=('build', 'link', 'run'))
-    depends_on('cuda@9.2:11.4', when='@1.6:1.10+cuda', type=('build', 'link', 'run'))
-    depends_on('cuda@9:11.4', when='@1.1:1.5+cuda', type=('build', 'link', 'run'))
-    depends_on('cuda@7.5:11.4', when='@:1.0+cuda', type=('build', 'link', 'run'))
-    depends_on('cudnn@6:7', when='@:1.0+cudnn')
-    depends_on('cudnn@7.0:7', when='@1.1:1.5+cudnn')
-    depends_on('cudnn@7:', when='@1.6:+cudnn')
-    depends_on('magma', when='+magma')
-    depends_on('nccl', when='+nccl')
-    depends_on('numactl', when='+numa')
-    depends_on('llvm-openmp', when='%apple-clang +openmp')
-    depends_on('valgrind', when='+valgrind')
+    depends_on("cuda@9.2:", when="@1.11:+cuda", type=("build", "link", "run"))
+    depends_on("cuda@9.2:11.4", when="@1.6:1.10+cuda", type=("build", "link", "run"))
+    depends_on("cuda@9:11.4", when="@1.1:1.5+cuda", type=("build", "link", "run"))
+    depends_on("cuda@7.5:11.4", when="@:1.0+cuda", type=("build", "link", "run"))
+    depends_on("cudnn@6:7", when="@:1.0+cudnn")
+    depends_on("cudnn@7.0:7", when="@1.1:1.5+cudnn")
+    depends_on("cudnn@7:", when="@1.6:+cudnn")
+    depends_on("magma+cuda", when="+magma+cuda")
+    depends_on("magma+rocm", when="+magma+rocm")
+    depends_on("nccl", when="+nccl+cuda")
+    depends_on("numactl", when="+numa")
+    depends_on("llvm-openmp", when="%apple-clang +openmp")
+    depends_on("valgrind", when="+valgrind")
+    with when("+rocm"):
+        depends_on("hsa-rocr-dev")
+        depends_on("hip")
+        depends_on("rccl", when="+nccl")
+        depends_on("rocprim")
+        depends_on("hipcub")
+        depends_on("rocthrust")
+        depends_on("roctracer-dev")
+        depends_on("rocrand")
+        depends_on("hipsparse")
+        depends_on("hipfft")
+        depends_on("rocfft")
+        depends_on("rocblas")
+        depends_on("miopen-hip")
+        depends_on("rocminfo")
     # https://github.com/pytorch/pytorch/issues/60332
-    # depends_on('xnnpack@2021-02-22', when='@1.8:+xnnpack')
-    # depends_on('xnnpack@2020-03-23', when='@1.6:1.7+xnnpack')
-    depends_on('mpi', when='+mpi')
+    # depends_on("xnnpack@2022-02-16", when="@1.12:+xnnpack")
+    # depends_on("xnnpack@2021-06-21", when="@1.10:1.11+xnnpack")
+    # depends_on("xnnpack@2021-02-22", when="@1.8:1.9+xnnpack")
+    # depends_on("xnnpack@2020-03-23", when="@1.6:1.7+xnnpack")
+    depends_on("mpi", when="+mpi")
     # https://github.com/pytorch/pytorch/issues/60270
-    # depends_on('gloo@2021-05-04', when='@1.9:+gloo')
-    # depends_on('gloo@2020-09-18', when='@1.7:1.8+gloo')
-    # depends_on('gloo@2020-03-17', when='@1.6+gloo')
+    # depends_on("gloo@2022-05-18", when="@1.13:+gloo")
+    # depends_on("gloo@2021-05-21", when="@1.10:1.12+gloo")
+    # depends_on("gloo@2021-05-04", when="@1.9+gloo")
+    # depends_on("gloo@2020-09-18", when="@1.7:1.8+gloo")
+    # depends_on("gloo@2020-03-17", when="@1.6+gloo")
     # https://github.com/pytorch/pytorch/issues/60331
-    # depends_on('onnx@1.8.0_2020-11-03', when='@1.8:+onnx_ml')
-    # depends_on('onnx@1.7.0_2020-05-31', when='@1.6:1.7+onnx_ml')
-    depends_on('mkl', when='+mkldnn')
+    # depends_on("onnx!1.12.0", when="@1.13:+onnx_ml")
+    # depends_on("onnx@1.11.0", when="@1.12+onnx_ml")
+    # depends_on("onnx@1.10.1_2021-10-08", when="@1.11+onnx_ml")
+    # depends_on("onnx@1.10.1", when="@1.10+onnx_ml")
+    # depends_on("onnx@1.8.0_2020-11-03", when="@1.8:1.9+onnx_ml")
+    # depends_on("onnx@1.7.0_2020-05-31", when="@1.6:1.7+onnx_ml")
+    depends_on("mkl", when="+mkldnn")
 
     # Test dependencies
-    depends_on('py-hypothesis', type='test')
-    depends_on('py-six', type='test')
-    depends_on('py-psutil', type='test')
+    depends_on("py-hypothesis", type="test")
+    depends_on("py-six", type="test")
+    depends_on("py-psutil", type="test")
 
     # Fix BLAS being overridden by MKL
     # https://github.com/pytorch/pytorch/issues/60328
-    patch('https://github.com/pytorch/pytorch/pull/59220.patch?full_index=1',
-          sha256='6d5717267f901e8ee493dfacd08734d9bcc48ad29a76ca9ef702368e96bee675',
-          when='@1.2:')
+    patch(
+        "https://github.com/pytorch/pytorch/pull/59220.patch?full_index=1",
+        sha256="6d5717267f901e8ee493dfacd08734d9bcc48ad29a76ca9ef702368e96bee675",
+        when="@1.2:1.11",
+    )
 
     # Fixes build on older systems with glibc <2.12
-    patch('https://github.com/pytorch/pytorch/pull/55063.patch?full_index=1',
-          sha256='2229bcbf20fbe88aa9f7318f89c126ec7f527875ffe689a763c78abfa127a65c',
-          when='@1.1:1.8.1')
+    patch(
+        "https://github.com/pytorch/pytorch/pull/55063.patch?full_index=1",
+        sha256="2229bcbf20fbe88aa9f7318f89c126ec7f527875ffe689a763c78abfa127a65c",
+        when="@1.1:1.8.1",
+    )
 
     # Fixes CMake configuration error when XNNPACK is disabled
     # https://github.com/pytorch/pytorch/pull/35607
     # https://github.com/pytorch/pytorch/pull/37865
-    patch('xnnpack.patch', when='@1.5')
+    patch("xnnpack.patch", when="@1.5")
 
     # Fixes build error when ROCm is enabled for pytorch-1.5 release
-    patch('rocm.patch', when='@1.5+rocm')
+    patch("rocm.patch", when="@1.5+rocm")
 
     # Fixes fatal error: sleef.h: No such file or directory
     # https://github.com/pytorch/pytorch/pull/35359
     # https://github.com/pytorch/pytorch/issues/26555
-    # patch('sleef.patch', when='@:1.5')
+    # patch("sleef.patch", when="@:1.5")
 
     # Fixes compilation with Clang 9.0.0 and Apple Clang 11.0.3
     # https://github.com/pytorch/pytorch/pull/37086
-    patch('https://github.com/pytorch/pytorch/commit/e921cd222a8fbeabf5a3e74e83e0d8dfb01aa8b5.patch?full_index=1',
-          sha256='0f3ad037a95af9d34b1d085050c1e7771fd00f0b89e5b3a276097b7c9f4fabf8',
-          when='@1.1:1.5')
+    patch(
+        "https://github.com/pytorch/pytorch/commit/e921cd222a8fbeabf5a3e74e83e0d8dfb01aa8b5.patch?full_index=1",
+        sha256="0f3ad037a95af9d34b1d085050c1e7771fd00f0b89e5b3a276097b7c9f4fabf8",
+        when="@1.1:1.5",
+    )
 
     # Removes duplicate definition of getCusparseErrorString
     # https://github.com/pytorch/pytorch/issues/32083
-    patch('cusparseGetErrorString.patch', when='@:1.0^cuda@10.1.243:')
+    patch("cusparseGetErrorString.patch", when="@:1.0^cuda@10.1.243:")
 
     # Fixes 'FindOpenMP.cmake'
     # to detect openmp settings used by Fujitsu compiler.
-    patch('detect_omp_of_fujitsu_compiler.patch', when='%fj')
+    patch("detect_omp_of_fujitsu_compiler.patch", when="%fj")
 
     # Fixes to build with fujitsu-ssl2
-    patch('fj-ssl2_1.11.patch', when='@1.11:^fujitsu-ssl2')
-    patch('fj-ssl2_1.10.patch', when='@1.10^fujitsu-ssl2')
-    patch('fj-ssl2_1.9.patch', when='@1.9^fujitsu-ssl2')
-    patch('fj-ssl2_1.8.patch', when='@1.8^fujitsu-ssl2')
-    patch('fj-ssl2_1.6-1.7.patch', when='@1.6:1.7^fujitsu-ssl2')
-    patch('fj-ssl2_1.3-1.5.patch', when='@1.3:1.5^fujitsu-ssl2')
-    patch('fj-ssl2_1.2.patch', when='@1.2^fujitsu-ssl2')
+    patch("fj-ssl2_1.11.patch", when="@1.11:^fujitsu-ssl2")
+    patch("fj-ssl2_1.10.patch", when="@1.10^fujitsu-ssl2")
+    patch("fj-ssl2_1.9.patch", when="@1.9^fujitsu-ssl2")
+    patch("fj-ssl2_1.8.patch", when="@1.8^fujitsu-ssl2")
+    patch("fj-ssl2_1.6-1.7.patch", when="@1.6:1.7^fujitsu-ssl2")
+    patch("fj-ssl2_1.3-1.5.patch", when="@1.3:1.5^fujitsu-ssl2")
+    patch("fj-ssl2_1.2.patch", when="@1.2^fujitsu-ssl2")
 
     # Fix compilation of +distributed~tensorpipe
     # https://github.com/pytorch/pytorch/issues/68002
-    patch('https://github.com/pytorch/pytorch/commit/c075f0f633fa0136e68f0a455b5b74d7b500865c.patch?full_index=1',
-          sha256='41271e494a3a60a65a8dd45ac053d1a6e4e4d5b42c2dac589ac67524f61ac41e', when='@1.10.0+distributed~tensorpipe')
+    patch(
+        "https://github.com/pytorch/pytorch/commit/c075f0f633fa0136e68f0a455b5b74d7b500865c.patch?full_index=1",
+        sha256="41271e494a3a60a65a8dd45ac053d1a6e4e4d5b42c2dac589ac67524f61ac41e",
+        when="@1.10.0+distributed~tensorpipe",
+    )
 
     # Use patches from IBM's Open CE to enable building on Power systems
     # 03xx - patch temporary to fix a problem that when fixed upstream can be removed
-    patch('https://github.com/open-ce/pytorch-feedstock/raw/main/recipe/0302-cpp-extension.patch',
-          sha256='ecb3973fa7d0f4c8f8ae40433f3ca5622d730a7b16f6cb63325d1e95baff8aa2', when='@1.10.0: arch=ppc64le:')
-
-    patch('https://github.com/open-ce/pytorch-feedstock/raw/main/recipe/0311-PR66085-Remove-unused-dump-method-from-VSX-vec256-methods.patch',
-          sha256='f05db59f3def4c4215db7142d81029c73fe330c660492159b66d65ca5001f4d1', when='@1.10.0: arch=ppc64le:')
-
-    patch('https://github.com/open-ce/pytorch-feedstock/raw/main/recipe/0312-PR67331-Dummpy-VSX-bfloat16-implementation.patch',
-          sha256='860b64afa85f5e6647ebc3c91d5a0bb258784770900c9302c3599c98d5cff1ee', when='@1.10.0: arch=ppc64le:')
-
-    patch('https://github.com/open-ce/pytorch-feedstock/raw/main/recipe/0313-add-missing-vsx-dispatch.patch',
-          sha256='7393c2bc0b6d41ecc813c829a1e517bee864686652e91f174cb7bcdfb10ba451', when='@1.10.0: arch=ppc64le:')
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/0a145060ca8523314ec3893af935c3b140e2d0b0/pytorch-1.10/recipe/0302-cpp-extension.patch",
+        sha256="ecb3973fa7d0f4c8f8ae40433f3ca5622d730a7b16f6cb63325d1e95baff8aa2",
+        when="@1.10:1.11 arch=ppc64le:",
+    )
+
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/0a145060ca8523314ec3893af935c3b140e2d0b0/pytorch-1.10/recipe/0311-PR66085-Remove-unused-dump-method-from-VSX-vec256-methods.patch",
+        sha256="f05db59f3def4c4215db7142d81029c73fe330c660492159b66d65ca5001f4d1",
+        when="@1.10:1.11 arch=ppc64le:",
+    )
+
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/0a145060ca8523314ec3893af935c3b140e2d0b0/pytorch-1.10/recipe/0312-PR67331-Dummpy-VSX-bfloat16-implementation.patch",
+        sha256="860b64afa85f5e6647ebc3c91d5a0bb258784770900c9302c3599c98d5cff1ee",
+        when="@1.10:1.11 arch=ppc64le:",
+    )
+
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/0a145060ca8523314ec3893af935c3b140e2d0b0/pytorch-1.10/recipe/0313-add-missing-vsx-dispatch.patch",
+        sha256="7393c2bc0b6d41ecc813c829a1e517bee864686652e91f174cb7bcdfb10ba451",
+        when="@1.10:1.11 arch=ppc64le:",
+    )
+
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/0a145060ca8523314ec3893af935c3b140e2d0b0/pytorch-1.12/recipe/0302-cpp-extension.patch",
+        sha256="2fac519cca8997f074c263505657ff867e7ba2d6637fc8bda99c70a99be0442a",
+        when="@1.12: arch=ppc64le:",
+    )
 
     # Cherry-pick a patch to allow earlier versions of PyTorch to work with CUDA 11.4
-    patch('https://github.com/pytorch/pytorch/commit/c74c0c571880df886474be297c556562e95c00e0.patch?full_index=1',
-          sha256='8ff7d285e52e4718bad1ca01ceb3bb6471d7828329036bb94222717fcaa237da', when='@:1.9.1 ^cuda@11.4.100:')
-
-    @property
-    def libs(self):
-        # TODO: why doesn't `python_platlib` work here?
-        root = join_path(
-            self.prefix, self.spec['python'].package.platlib, 'torch', 'lib'
-        )
-        return find_libraries('libtorch', root)
+    patch(
+        "https://github.com/pytorch/pytorch/commit/c74c0c571880df886474be297c556562e95c00e0.patch?full_index=1",
+        sha256="8ff7d285e52e4718bad1ca01ceb3bb6471d7828329036bb94222717fcaa237da",
+        when="@:1.9.1 ^cuda@11.4.100:",
+    )
 
-    @property
-    def headers(self):
-        # TODO: why doesn't `python_platlib` work here?
-        root = join_path(
-            self.prefix, self.spec['python'].package.platlib, 'torch', 'include'
-        )
-        headers = find_all_headers(root)
-        headers.directories = [root]
-        return headers
-
-    @when('@1.5.0:')
+    @when("@1.5.0:")
     def patch(self):
         # https://github.com/pytorch/pytorch/issues/52208
-        filter_file('torch_global_deps PROPERTIES LINKER_LANGUAGE C',
-                    'torch_global_deps PROPERTIES LINKER_LANGUAGE CXX',
-                    'caffe2/CMakeLists.txt')
+        filter_file(
+            "torch_global_deps PROPERTIES LINKER_LANGUAGE C",
+            "torch_global_deps PROPERTIES LINKER_LANGUAGE CXX",
+            "caffe2/CMakeLists.txt",
+        )
 
     def setup_build_environment(self, env):
         """Set environment variables used to control the build.
@@ -275,7 +354,8 @@ class PyTorch(PythonPackage, CudaPackage):
         most flags defined in ``CMakeLists.txt`` can be specified as
         environment variables.
         """
-        def enable_or_disable(variant, keyword='USE', var=None, newer=False):
+
+        def enable_or_disable(variant, keyword="USE", var=None, newer=False):
             """Set environment variable to enable or disable support for a
             particular variant.
 
@@ -290,167 +370,185 @@ class PyTorch(PythonPackage, CudaPackage):
 
             # Version 1.1.0 switched from NO_* to USE_* or BUILD_*
             # But some newer variants have always used USE_* or BUILD_*
-            if self.spec.satisfies('@1.1:') or newer:
-                if '+' + variant in self.spec:
-                    env.set(keyword + '_' + var, 'ON')
-                elif '~' + variant in self.spec:
-                    env.set(keyword + '_' + var, 'OFF')
+            if self.spec.satisfies("@1.1:") or newer:
+                if "+" + variant in self.spec:
+                    env.set(keyword + "_" + var, "ON")
+                elif "~" + variant in self.spec:
+                    env.set(keyword + "_" + var, "OFF")
             else:
-                if '+' + variant in self.spec:
-                    env.unset('NO_' + var)
-                elif '~' + variant in self.spec:
-                    env.set('NO_' + var, 'ON')
+                if "+" + variant in self.spec:
+                    env.unset("NO_" + var)
+                elif "~" + variant in self.spec:
+                    env.set("NO_" + var, "ON")
 
         # Build in parallel to speed up build times
-        env.set('MAX_JOBS', make_jobs)
+        env.set("MAX_JOBS", make_jobs)
 
         # Spack logs have trouble handling colored output
-        env.set('COLORIZE_OUTPUT', 'OFF')
+        env.set("COLORIZE_OUTPUT", "OFF")
 
-        enable_or_disable('test', keyword='BUILD')
-        enable_or_disable('caffe2', keyword='BUILD')
+        enable_or_disable("test", keyword="BUILD")
+        enable_or_disable("caffe2", keyword="BUILD")
 
-        enable_or_disable('cuda')
-        if '+cuda' in self.spec:
+        enable_or_disable("cuda")
+        if "+cuda" in self.spec:
             # cmake/public/cuda.cmake
             # cmake/Modules_CUDA_fix/upstream/FindCUDA.cmake
-            env.unset('CUDA_ROOT')
-            torch_cuda_arch = ';'.join('{0:.1f}'.format(float(i) / 10.0) for i
-                                       in
-                                       self.spec.variants['cuda_arch'].value)
-            env.set('TORCH_CUDA_ARCH_LIST', torch_cuda_arch)
-            if self.spec.satisfies('%clang'):
-                for flag in self.spec.compiler_flags['cxxflags']:
-                    if 'gcc-toolchain' in flag:
-                        env.set('CMAKE_CUDA_FLAGS', '=-Xcompiler={0}'.format(flag))
-
-        enable_or_disable('rocm')
-
-        enable_or_disable('cudnn')
-        if '+cudnn' in self.spec:
+            env.unset("CUDA_ROOT")
+            torch_cuda_arch = ";".join(
+                "{0:.1f}".format(float(i) / 10.0) for i in self.spec.variants["cuda_arch"].value
+            )
+            env.set("TORCH_CUDA_ARCH_LIST", torch_cuda_arch)
+            if self.spec.satisfies("%clang"):
+                for flag in self.spec.compiler_flags["cxxflags"]:
+                    if "gcc-toolchain" in flag:
+                        env.set("CMAKE_CUDA_FLAGS", "=-Xcompiler={0}".format(flag))
+
+        enable_or_disable("rocm")
+        if "+rocm" in self.spec:
+            env.set("PYTORCH_ROCM_ARCH", ";".join(self.spec.variants["amdgpu_target"].value))
+            env.set("HSA_PATH", self.spec["hsa-rocr-dev"].prefix)
+            env.set("ROCBLAS_PATH", self.spec["rocblas"].prefix)
+            env.set("ROCFFT_PATH", self.spec["rocfft"].prefix)
+            env.set("HIPFFT_PATH", self.spec["hipfft"].prefix)
+            env.set("HIPSPARSE_PATH", self.spec["hipsparse"].prefix)
+            env.set("HIP_PATH", self.spec["hip"].prefix)
+            env.set("HIPRAND_PATH", self.spec["rocrand"].prefix)
+            env.set("ROCRAND_PATH", self.spec["rocrand"].prefix)
+            env.set("MIOPEN_PATH", self.spec["miopen-hip"].prefix)
+            if "+nccl" in self.spec:
+                env.set("RCCL_PATH", self.spec["rccl"].prefix)
+            env.set("ROCPRIM_PATH", self.spec["rocprim"].prefix)
+            env.set("HIPCUB_PATH", self.spec["hipcub"].prefix)
+            env.set("ROCTHRUST_PATH", self.spec["rocthrust"].prefix)
+            env.set("ROCTRACER_PATH", self.spec["roctracer-dev"].prefix)
+            if self.spec.satisfies("^hip@5.2.0:"):
+                env.set("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
+
+        enable_or_disable("cudnn")
+        if "+cudnn" in self.spec:
             # cmake/Modules_CUDA_fix/FindCUDNN.cmake
-            env.set('CUDNN_INCLUDE_DIR', self.spec['cudnn'].prefix.include)
-            env.set('CUDNN_LIBRARY', self.spec['cudnn'].libs[0])
+            env.set("CUDNN_INCLUDE_DIR", self.spec["cudnn"].prefix.include)
+            env.set("CUDNN_LIBRARY", self.spec["cudnn"].libs[0])
 
-        enable_or_disable('fbgemm')
-        enable_or_disable('kineto')
-        enable_or_disable('magma')
-        enable_or_disable('metal')
-        enable_or_disable('breakpad')
+        enable_or_disable("fbgemm")
+        enable_or_disable("kineto")
+        enable_or_disable("magma")
+        enable_or_disable("metal")
+        enable_or_disable("mps")
+        enable_or_disable("breakpad")
 
-        enable_or_disable('nccl')
-        if '+nccl' in self.spec:
-            env.set('NCCL_LIB_DIR', self.spec['nccl'].libs.directories[0])
-            env.set('NCCL_INCLUDE_DIR', self.spec['nccl'].prefix.include)
+        enable_or_disable("nccl")
+        if "+cuda+nccl" in self.spec:
+            env.set("NCCL_LIB_DIR", self.spec["nccl"].libs.directories[0])
+            env.set("NCCL_INCLUDE_DIR", self.spec["nccl"].prefix.include)
 
         # cmake/External/nnpack.cmake
-        enable_or_disable('nnpack')
+        enable_or_disable("nnpack")
 
-        enable_or_disable('numa')
-        if '+numa' in self.spec:
+        enable_or_disable("numa")
+        if "+numa" in self.spec:
             # cmake/Modules/FindNuma.cmake
-            env.set('NUMA_ROOT_DIR', self.spec['numactl'].prefix)
+            env.set("NUMA_ROOT_DIR", self.spec["numactl"].prefix)
 
         # cmake/Modules/FindNumPy.cmake
-        enable_or_disable('numpy')
+        enable_or_disable("numpy")
         # cmake/Modules/FindOpenMP.cmake
-        enable_or_disable('openmp', newer=True)
-        enable_or_disable('qnnpack')
-        enable_or_disable('qnnpack', var='PYTORCH_QNNPACK')
-        enable_or_disable('valgrind')
-        enable_or_disable('xnnpack')
-        enable_or_disable('mkldnn')
-        enable_or_disable('distributed')
-        enable_or_disable('mpi')
+        enable_or_disable("openmp", newer=True)
+        enable_or_disable("qnnpack")
+        enable_or_disable("qnnpack", var="PYTORCH_QNNPACK")
+        enable_or_disable("valgrind")
+        enable_or_disable("xnnpack")
+        enable_or_disable("mkldnn")
+        enable_or_disable("distributed")
+        enable_or_disable("mpi")
         # cmake/Modules/FindGloo.cmake
-        enable_or_disable('gloo', newer=True)
-        enable_or_disable('tensorpipe')
+        enable_or_disable("gloo", newer=True)
+        enable_or_disable("tensorpipe")
 
-        if '+debug' in self.spec:
-            env.set('DEBUG', 'ON')
+        if "+debug" in self.spec:
+            env.set("DEBUG", "ON")
         else:
-            env.set('DEBUG', 'OFF')
+            env.set("DEBUG", "OFF")
 
-        if '+onnx_ml' in self.spec:
-            env.set('ONNX_ML', 'ON')
-        elif '~onnx_ml' in self.spec:
-            env.set('ONNX_ML', 'OFF')
+        if "+onnx_ml" in self.spec:
+            env.set("ONNX_ML", "ON")
+        elif "~onnx_ml" in self.spec:
+            env.set("ONNX_ML", "OFF")
 
-        if not self.spec.satisfies('@master'):
-            env.set('PYTORCH_BUILD_VERSION', self.version)
-            env.set('PYTORCH_BUILD_NUMBER', 0)
+        if not self.spec.satisfies("@master"):
+            env.set("PYTORCH_BUILD_VERSION", self.version)
+            env.set("PYTORCH_BUILD_NUMBER", 0)
 
         # BLAS to be used by Caffe2
         # Options defined in cmake/Dependencies.cmake and cmake/Modules/FindBLAS.cmake
-        if self.spec['blas'].name == 'atlas':
-            env.set('BLAS', 'ATLAS')
-            env.set('WITH_BLAS', 'atlas')
-        elif self.spec['blas'].name in ['blis', 'amdblis']:
-            env.set('BLAS', 'BLIS')
-            env.set('WITH_BLAS', 'blis')
-        elif self.spec['blas'].name == 'eigen':
-            env.set('BLAS', 'Eigen')
-        elif self.spec['lapack'].name in ['libflame', 'amdlibflame']:
-            env.set('BLAS', 'FLAME')
-            env.set('WITH_BLAS', 'FLAME')
-        elif self.spec['blas'].name in [
-                'intel-mkl', 'intel-parallel-studio', 'intel-oneapi-mkl']:
-            env.set('BLAS', 'MKL')
-            env.set('WITH_BLAS', 'mkl')
+        if self.spec["blas"].name == "atlas":
+            env.set("BLAS", "ATLAS")
+            env.set("WITH_BLAS", "atlas")
+        elif self.spec["blas"].name in ["blis", "amdblis"]:
+            env.set("BLAS", "BLIS")
+            env.set("WITH_BLAS", "blis")
+        elif self.spec["blas"].name == "eigen":
+            env.set("BLAS", "Eigen")
+        elif self.spec["lapack"].name in ["libflame", "amdlibflame"]:
+            env.set("BLAS", "FLAME")
+            env.set("WITH_BLAS", "FLAME")
+        elif self.spec["blas"].name in ["intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"]:
+            env.set("BLAS", "MKL")
+            env.set("WITH_BLAS", "mkl")
             # help find MKL
-            if self.spec['mkl'].name == 'intel-oneapi-mkl':
-                env.set('INTEL_MKL_DIR', self.spec['mkl'].prefix.mkl.latest)
+            if self.spec["mkl"].name == "intel-oneapi-mkl":
+                env.set("INTEL_MKL_DIR", self.spec["mkl"].prefix.mkl.latest)
             else:
-                env.set('INTEL_MKL_DIR', self.spec['mkl'].prefix.mkl)
-        elif self.spec['blas'].name == 'openblas':
-            env.set('BLAS', 'OpenBLAS')
-            env.set('WITH_BLAS', 'open')
-        elif self.spec['blas'].name == 'veclibfort':
-            env.set('BLAS', 'vecLib')
-            env.set('WITH_BLAS', 'veclib')
-        elif self.spec['blas'].name == 'fujitsu-ssl2':
-            env.set('BLAS', 'SSL2')
-            env.set('WITH_BLAS', 'ssl2')
+                env.set("INTEL_MKL_DIR", self.spec["mkl"].prefix.mkl)
+        elif self.spec["blas"].name == "openblas":
+            env.set("BLAS", "OpenBLAS")
+            env.set("WITH_BLAS", "open")
+        elif self.spec["blas"].name == "veclibfort":
+            env.set("BLAS", "vecLib")
+            env.set("WITH_BLAS", "veclib")
+        elif self.spec["blas"].name == "fujitsu-ssl2":
+            env.set("BLAS", "SSL2")
+            env.set("WITH_BLAS", "ssl2")
         else:
-            env.set('BLAS', 'Generic')
-            env.set('WITH_BLAS', 'generic')
+            env.set("BLAS", "Generic")
+            env.set("WITH_BLAS", "generic")
 
         # Don't use vendored third-party libraries when possible
-        env.set('BUILD_CUSTOM_PROTOBUF', 'OFF')
-        env.set('USE_SYSTEM_NCCL', 'ON')
-        env.set('USE_SYSTEM_EIGEN_INSTALL', 'ON')
-        env.set('pybind11_DIR', self.spec['py-pybind11'].prefix)
-        env.set('pybind11_INCLUDE_DIR',
-                self.spec['py-pybind11'].prefix.include)
-        if self.spec.satisfies('@1.10:'):
-            env.set('USE_SYSTEM_PYBIND11', 'ON')
+        env.set("BUILD_CUSTOM_PROTOBUF", "OFF")
+        env.set("USE_SYSTEM_NCCL", "ON")
+        env.set("USE_SYSTEM_EIGEN_INSTALL", "ON")
+        env.set("pybind11_DIR", self.spec["py-pybind11"].prefix)
+        env.set("pybind11_INCLUDE_DIR", self.spec["py-pybind11"].prefix.include)
+        if self.spec.satisfies("@1.10:"):
+            env.set("USE_SYSTEM_PYBIND11", "ON")
         # https://github.com/pytorch/pytorch/issues/60334
-        # if self.spec.satisfies('@1.8:'):
-        #     env.set('USE_SYSTEM_SLEEF', 'ON')
-        if self.spec.satisfies('@1.6:'):
-            # env.set('USE_SYSTEM_LIBS', 'ON')
+        # if self.spec.satisfies("@1.8:"):
+        #     env.set("USE_SYSTEM_SLEEF", "ON")
+        if self.spec.satisfies("@1.6:"):
+            # env.set("USE_SYSTEM_LIBS", "ON")
             # https://github.com/pytorch/pytorch/issues/60329
-            # env.set('USE_SYSTEM_CPUINFO', 'ON')
+            # env.set("USE_SYSTEM_CPUINFO", "ON")
             # https://github.com/pytorch/pytorch/issues/60270
-            # env.set('USE_SYSTEM_GLOO', 'ON')
+            # env.set("USE_SYSTEM_GLOO", "ON")
             # https://github.com/Maratyszcza/FP16/issues/18
-            # env.set('USE_SYSTEM_FP16', 'ON')
-            env.set('USE_SYSTEM_PTHREADPOOL', 'ON')
-            env.set('USE_SYSTEM_PSIMD', 'ON')
-            env.set('USE_SYSTEM_FXDIV', 'ON')
-            env.set('USE_SYSTEM_BENCHMARK', 'ON')
+            # env.set("USE_SYSTEM_FP16", "ON")
+            env.set("USE_SYSTEM_PTHREADPOOL", "ON")
+            env.set("USE_SYSTEM_PSIMD", "ON")
+            env.set("USE_SYSTEM_FXDIV", "ON")
+            env.set("USE_SYSTEM_BENCHMARK", "ON")
             # https://github.com/pytorch/pytorch/issues/60331
-            # env.set('USE_SYSTEM_ONNX', 'ON')
+            # env.set("USE_SYSTEM_ONNX", "ON")
             # https://github.com/pytorch/pytorch/issues/60332
-            # env.set('USE_SYSTEM_XNNPACK', 'ON')
+            # env.set("USE_SYSTEM_XNNPACK", "ON")
 
-    @run_before('install')
+    @run_before("install")
     def build_amd(self):
-        if '+rocm' in self.spec:
-            python(os.path.join('tools', 'amd_build', 'build_amd.py'))
+        if "+rocm" in self.spec:
+            python(os.path.join("tools", "amd_build", "build_amd.py"))
 
-    @run_after('install')
+    @run_after("install")
     @on_package_attributes(run_tests=True)
     def install_test(self):
-        with working_dir('test'):
-            python('run_test.py')
+        with working_dir("test"):
+            python("run_test.py")
diff --git a/packages/r-irkernel/package.py b/packages/r-irkernel/package.py
index d6dd8db386548c6464be1f016487b9f07246969b..145aeeee0dd4c80b1dc76aac17087c4fb1a79a0e 100644
--- a/packages/r-irkernel/package.py
+++ b/packages/r-irkernel/package.py
@@ -1,4 +1,4 @@
-# this package was adapted from Spack upstream v0.18.1, to change the dependency on py-jupyter to py-jupyter-client
+# this package was adapted from Spack upstream v0.19.2, to change the dependency on py-jupyter to py-jupyter-client
 
 # Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
@@ -6,34 +6,38 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 
-from spack import *
+from spack.package import *
 
 
 class RIrkernel(RPackage):
     """Native R Kernel for the 'Jupyter Notebook'.
+
     The R kernel for the 'Jupyter' environment executes R code which the
     front-end ('Jupyter Notebook' or other front-ends) submits to the kernel
     via the network."""
 
     cran = "IRkernel"
 
-    version('1.3', sha256='5a7fcbfd978dfb3cca6702a68a21c147551995fc400084ae8382ffcbbdae1903')
-    version('1.2', sha256='5fb4dbdb741d05043120a8be0eb73f054b607d9854f314bd79cfec08d219ff91')
-    version('0.7',
-            git="https://github.com/IRkernel/IRkernel.git",
-            commit='9cdd284e03eb42d03fab18544b81f486852d5fe0',
-            deprecated=True)
-
-    depends_on('r@3.2.0:', type=('build', 'run'))
-    depends_on('r-repr@0.4.99:', type=('build', 'run'))
-    depends_on('r-evaluate@0.10:', type=('build', 'run'))
-    depends_on('r-irdisplay@0.3.0.9999:', type=('build', 'run'))
-    depends_on('r-pbdzmq@0.2-1:', type=('build', 'run'))
-    depends_on('r-crayon', type=('build', 'run'))
-    depends_on('r-jsonlite@0.9.6:', type=('build', 'run'))
-    depends_on('r-uuid', type=('build', 'run'))
-    depends_on('r-digest', type=('build', 'run'))
-    depends_on('py-jupyter-client', type='run')
-
-    depends_on('r-evaluate@0.5.4:', type=('build', 'run'), when='@0.7')
-    depends_on('r-devtools', type=('build', 'run'), when='@0.7')
+    version("1.3.1", sha256="3186e3a177c7246d45218af55f8b10836540e68a2d106858a0385f7d741b640c")
+    version("1.3", sha256="5a7fcbfd978dfb3cca6702a68a21c147551995fc400084ae8382ffcbbdae1903")
+    version("1.2", sha256="5fb4dbdb741d05043120a8be0eb73f054b607d9854f314bd79cfec08d219ff91")
+    version(
+        "0.7",
+        git="https://github.com/IRkernel/IRkernel.git",
+        commit="9cdd284e03eb42d03fab18544b81f486852d5fe0",
+        deprecated=True,
+    )
+
+    depends_on("r@3.2.0:", type=("build", "run"))
+    depends_on("r-repr@0.4.99:", type=("build", "run"))
+    depends_on("r-evaluate@0.10:", type=("build", "run"))
+    depends_on("r-irdisplay@0.3.0.9999:", type=("build", "run"))
+    depends_on("r-pbdzmq@0.2-1:", type=("build", "run"))
+    depends_on("r-crayon", type=("build", "run"))
+    depends_on("r-jsonlite@0.9.6:", type=("build", "run"))
+    depends_on("r-uuid", type=("build", "run"))
+    depends_on("r-digest", type=("build", "run"))
+    depends_on("py-jupyter-client", type="run")
+
+    depends_on("r-evaluate@0.5.4:", type=("build", "run"), when="@0.7")
+    depends_on("r-devtools", type=("build", "run"), when="@0.7")
diff --git a/packages/sbml/package.py b/packages/sbml/package.py
index 33cec4946b2eec356418599ef6c9b7b7e1913c95..f0112dfd6dcc461259d1b2aaa4b1ba3ec5f03cbe 100644
--- a/packages/sbml/package.py
+++ b/packages/sbml/package.py
@@ -1,73 +1,68 @@
+# this package was adapted from Spack upstream v0.19.2, to fix some issues with finding existing libs/headers
+
 # Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
-from spack import *
+from spack.package import *
 
 
 class Sbml(CMakePackage):
     """Library for the Systems Biology Markup Language"""
 
     homepage = "https://sbml.org"
-    maintainers = ['rblake-llnl']
-
-    version('5.19.0', sha256='a7f0e18be78ff0e064e4cdb1cd86634d08bc33be5250db4a1878bd81eeb8b547')
-    version('5.18.0', sha256='6c01be2306ec0c9656b59cb082eb7b90176c39506dd0f912b02e08298a553360')
-    version('5.17.0', sha256='189216e1472777e4464b791c506b79267d07a5454cb23ac991452711f8e0ed3a')
-    version('5.16.0', sha256='c6855481434dd2a667fef73e1ff2feade509aa2f3a76d4d06e29022975ce1496')
-    version('5.15.0', sha256='c779c2a8a97c5480fe044028099d928a327261fb68cf08657ec8d4f3b3fc0a21')
-    version('5.13.0', sha256='e58430edb1b454d7414bcf1be0549bf6860a6d19d73232eb58211559485c2c05')
-    version('5.12.0', sha256='c637494b19269947fc90ebe479b624d36f80d1cb5569e45cd76ddde81dd28ae4')
-    version('5.11.4', sha256='6429188b689b331b0b8f2c8b55b3f2339196ccd4c93191648fa767e1d02152a3')
-    version('5.11.0', sha256='b21931ca7461494915c617b30d4a9f2cafe831d6ce74989b3e5874e6e3c3f72b')
-    version('5.10.2', sha256='83f32a143cf657672b1050f5f79d3591c418fc59570d180fb1f39b103f4e5286')
-    version('5.10.0', sha256='2cd8b37018ce8b1df869c8c182803addbce6d451512ae25a7f527b49981f0966')
+    maintainers = ["rblake-llnl"]
+
+    version("5.19.0", sha256="a7f0e18be78ff0e064e4cdb1cd86634d08bc33be5250db4a1878bd81eeb8b547")
+    version("5.18.0", sha256="6c01be2306ec0c9656b59cb082eb7b90176c39506dd0f912b02e08298a553360")
+    version("5.17.0", sha256="189216e1472777e4464b791c506b79267d07a5454cb23ac991452711f8e0ed3a")
+    version("5.16.0", sha256="c6855481434dd2a667fef73e1ff2feade509aa2f3a76d4d06e29022975ce1496")
+    version("5.15.0", sha256="c779c2a8a97c5480fe044028099d928a327261fb68cf08657ec8d4f3b3fc0a21")
+    version("5.13.0", sha256="e58430edb1b454d7414bcf1be0549bf6860a6d19d73232eb58211559485c2c05")
+    version("5.12.0", sha256="c637494b19269947fc90ebe479b624d36f80d1cb5569e45cd76ddde81dd28ae4")
+    version("5.11.4", sha256="6429188b689b331b0b8f2c8b55b3f2339196ccd4c93191648fa767e1d02152a3")
+    version("5.11.0", sha256="b21931ca7461494915c617b30d4a9f2cafe831d6ce74989b3e5874e6e3c3f72b")
+    version("5.10.2", sha256="83f32a143cf657672b1050f5f79d3591c418fc59570d180fb1f39b103f4e5286")
+    version("5.10.0", sha256="2cd8b37018ce8b1df869c8c182803addbce6d451512ae25a7f527b49981f0966")
 
     def url_for_version(self, version):
-        url = "https://downloads.sourceforge.net/project/sbml/libsbml/{0}/stable/libSBML-{1}-core-plus-packages-src.tar.gz".format(version, version)
+        url = "https://downloads.sourceforge.net/project/sbml/libsbml/{0}/stable/libSBML-{1}-core-plus-packages-src.tar.gz".format(
+            version, version
+        )
         return url
 
-    variant('python', default=False,
-            description='Build with python support')
-    depends_on('python', when="+python")
+    variant("python", default=False, description="Build with python support")
+    depends_on("python", when="+python")
 
-    variant('perl', default=False,
-            description='Build with perl support')
-    depends_on('perl', when="+perl")
+    variant("perl", default=False, description="Build with perl support")
+    depends_on("perl", when="+perl")
 
-    variant('ruby', default=False,
-            description='Build with ruby support')
-    depends_on('ruby', when="+ruby")
+    variant("ruby", default=False, description="Build with ruby support")
+    depends_on("ruby", when="+ruby")
 
-    variant('r', default=False,
-            description='Build with R support')
-    depends_on('r', when="+r")
+    variant("r", default=False, description="Build with R support")
+    depends_on("r", when="+r")
 
-    variant('octave', default=False,
-            description='Build with octave support')
-    depends_on('octave', when="+octave")
+    variant("octave", default=False, description="Build with octave support")
+    depends_on("octave", when="+octave")
 
-    variant('matlab', default=False,
-            description='Build with matlab support')
-    depends_on('matlab', when="+matlab")
+    variant("matlab", default=False, description="Build with matlab support")
+    depends_on("matlab", when="+matlab")
 
-    variant('java', default=False,
-            description='Build with java support')
-    depends_on('java', when="+java")
+    variant("java", default=False, description="Build with java support")
+    depends_on("java", when="+java")
 
-    variant('mono', default=False,
-            description='Build with mono support')
-    depends_on('mono', when="+mono")
+    variant("mono", default=False, description="Build with mono support")
+    depends_on("mono", when="+mono")
 
-    variant('cpp', default=False,
-            description="All c++ includes should be under a namespace")
+    variant("cpp", default=False, description="All c++ includes should be under a namespace")
 
-    depends_on('swig@2:', type='build')
-    depends_on('cmake', type='build')
-    depends_on('zlib')
-    depends_on('bzip2')
-    depends_on('libxml2')
+    depends_on("swig@2:", type="build")
+    depends_on("cmake", type="build")
+    depends_on("zlib")
+    depends_on("bzip2")
+    depends_on("libxml2")
 
     def cmake_args(self):
         spec = self.spec
@@ -89,48 +84,56 @@ class Sbml(CMakePackage):
             "-DWITH_XERCES:BOOL=OFF",
             "-DWITH_ZLIB:BOOL=ON",
         ]
-        args.append(self.define_from_variant('WITH_CPP_NAMESPACE', 'cpp'))
-        if '+python' in spec:
-            args.extend([
-                "-DWITH_PYTHON:BOOL=ON",
-                "-DWITH_PYTHON_INCLUDE:PATH=%s" % spec['python'].prefix,
-            ])
+        args.append(self.define_from_variant("WITH_CPP_NAMESPACE", "cpp"))
+        if "+python" in spec:
+            args.extend(
+                [
+                    "-DWITH_PYTHON:BOOL=ON",
+                    "-DWITH_PYTHON_INCLUDE:PATH=%s" % spec["python"].prefix,
+                ]
+            )
         else:
-            args.append('-DWITH_PYTHON:BOOL=OFF')
-
-        args.append(self.define_from_variant('WITH_CSHARP', 'mono'))
-
-        if '+java' in spec:
-            args.extend([
-                "-DWITH_JAVA:BOOL=ON",
-                "-DJDK_PATH:STRING=%s" % spec['java'].prefix,
-                "-DJAVA_INCLUDE_PATH:STRING=%s" % spec['java'].prefix,
-            ])
+            args.append("-DWITH_PYTHON:BOOL=OFF")
+
+        args.append(self.define_from_variant("WITH_CSHARP", "mono"))
+
+        if "+java" in spec:
+            args.extend(
+                [
+                    "-DWITH_JAVA:BOOL=ON",
+                    "-DJDK_PATH:STRING=%s" % spec["java"].prefix,
+                    "-DJAVA_INCLUDE_PATH:STRING=%s" % spec["java"].prefix,
+                ]
+            )
         else:
-            args.append('-DWITH_JAVA:BOOL=OFF')
-
-        if '+matlab' in spec:
-            args.extend([
-                "-DWITH_MATLAB:BOOL=ON",
-                "-DMATLAB_ROOT_PATH:PATH=%s" % spec['matlab'].prefix,
-                "-DWITH_MATLAB_MEX:BOOL=ON",
-            ])
+            args.append("-DWITH_JAVA:BOOL=OFF")
+
+        if "+matlab" in spec:
+            args.extend(
+                [
+                    "-DWITH_MATLAB:BOOL=ON",
+                    "-DMATLAB_ROOT_PATH:PATH=%s" % spec["matlab"].prefix,
+                    "-DWITH_MATLAB_MEX:BOOL=ON",
+                ]
+            )
         else:
-            args.append('-DWITH_MATLAB:BOOL=OFF')
+            args.append("-DWITH_MATLAB:BOOL=OFF")
 
         # fix issue with finding existing R libs/headers
-        if '+r' in spec:
-            args.extend([
-                "-DR_LIB=%s" % spec['r'].prefix,
-                "-DR_INCLUDE_DIRS=%s" % spec['r'].prefix.rlib.R.include
-            ])
-
-        args.append(self.define_from_variant('WITH_OCTAVE', 'octave'))
-        args.append(self.define_from_variant('WITH_PERL', 'perl'))
-        args.append(self.define_from_variant('WITH_R', 'r'))
-        args.append(self.define_from_variant('WITH_RUBY', 'ruby'))
+        if "+r" in spec:
+            args.extend(
+                [
+                    "-DR_LIB=%s" % spec["r"].prefix,
+                    "-DR_INCLUDE_DIRS=%s" % spec["r"].prefix.rlib.R.include
+                ]
+            )
+
+        args.append(self.define_from_variant("WITH_OCTAVE", "octave"))
+        args.append(self.define_from_variant("WITH_PERL", "perl"))
+        args.append(self.define_from_variant("WITH_R", "r"))
+        args.append(self.define_from_variant("WITH_RUBY", "ruby"))
 
         # fix issue with finding existing libxml2
-        args.append('-DLIBXML_INCLUDE_DIR=%s' % spec['libxml2'].prefix.include.libxml2)
+        args.append("-DLIBXML_INCLUDE_DIR=%s" % spec["libxml2"].prefix.include.libxml2)
 
         return args