From 69982dee41cd646daa1ede732672d31c3850eff6 Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Wed, 15 Jan 2025 14:36:15 +0100
Subject: [PATCH 1/8] neuron: add latest patch release 8.2.6

---
 packages/neuron/package.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index a429e035..e820eca3 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -16,12 +16,13 @@ class Neuron(CMakePackage):
     """
 
     homepage = "https://www.neuron.yale.edu/"
-    url = "https://github.com/neuronsimulator/nrn/releases/download/8.2.3/full-src-package-8.2.3.tar.gz"
+    url = "https://github.com/neuronsimulator/nrn/releases/download/8.2.6/nrn-full-src-package-8.2.6.tar.gz"
     git = "https://github.com/neuronsimulator/nrn"
 
-    maintainers = ["kumbhar"]
+    maintainers = ["kumbhar", "jcgoran"]
 
     version("develop", branch="master", submodules="True")
+    version("8.2.6", tag="8.2.6", submodules="True")
     version("8.2.3", tag="8.2.3", submodules="True")
     version("8.2.2", tag="8.2.2", submodules="True")
     version("8.1.0", tag="8.1.0", submodules="True")
@@ -41,17 +42,21 @@ class Neuron(CMakePackage):
 
     depends_on("bison", type="build")
     depends_on("flex", type="build")
-    depends_on("py-cython", when="+rx3d", type="build")
+    depends_on("py-cython@<3", when="@<9 +rx3d", type="build")
+    depends_on("py-cython", when="@9: +rx3d", type="build")
 
     depends_on("gettext")
     depends_on("mpi", when="+mpi")
     depends_on("ncurses")
-    depends_on("python@2.7:", when="+python")
+    depends_on("python@2.7:3.11", when="@:8.2.4 +python")
+    depends_on("python@2.7:3.12", when="@8.2.5:<9 +python")
+    depends_on("python@3.9:3.13", when="@9: +python")
     depends_on("py-pytest", when="+python+tests")
     depends_on("py-mpi4py", when="+mpi+python+tests")
     depends_on("readline")
     depends_on("caliper", when="+caliper")
-    depends_on("py-numpy", type=("run","test"))
+    depends_on("py-numpy@<2", when="@<9", type=("run","test"))
+    depends_on("py-numpy", when="@9:", type=("run","test"))
 
     extends('python', when='+python')
 
-- 
GitLab


From 4d16aa65ec991008c4a2977405dbfc8c96af70bd Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Fri, 17 Jan 2025 11:35:44 +0100
Subject: [PATCH 2/8] Fix typos

---
 packages/neuron/package.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index e820eca3..6470a7e8 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -42,7 +42,7 @@ class Neuron(CMakePackage):
 
     depends_on("bison", type="build")
     depends_on("flex", type="build")
-    depends_on("py-cython@<3", when="@<9 +rx3d", type="build")
+    depends_on("py-cython@<3", when="@:<9 +rx3d", type="build")
     depends_on("py-cython", when="@9: +rx3d", type="build")
 
     depends_on("gettext")
@@ -55,7 +55,7 @@ class Neuron(CMakePackage):
     depends_on("py-mpi4py", when="+mpi+python+tests")
     depends_on("readline")
     depends_on("caliper", when="+caliper")
-    depends_on("py-numpy@<2", when="@<9", type=("run","test"))
+    depends_on("py-numpy@<2", when="@:<9", type=("run","test"))
     depends_on("py-numpy", when="@9:", type=("run","test"))
 
     extends('python', when='+python')
-- 
GitLab


From e77c62a63450e28259ba10c36bb882545a278877 Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Fri, 17 Jan 2025 11:39:16 +0100
Subject: [PATCH 3/8] Use `.99999` because Spack

---
 packages/neuron/package.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index 6470a7e8..f5061fa4 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -42,20 +42,20 @@ class Neuron(CMakePackage):
 
     depends_on("bison", type="build")
     depends_on("flex", type="build")
-    depends_on("py-cython@<3", when="@:<9 +rx3d", type="build")
+    depends_on("py-cython@2.999999", when="@:8.999999 +rx3d", type="build")
     depends_on("py-cython", when="@9: +rx3d", type="build")
 
     depends_on("gettext")
     depends_on("mpi", when="+mpi")
     depends_on("ncurses")
     depends_on("python@2.7:3.11", when="@:8.2.4 +python")
-    depends_on("python@2.7:3.12", when="@8.2.5:<9 +python")
+    depends_on("python@2.7:3.12", when="@8.2.5:8.99999 +python")
     depends_on("python@3.9:3.13", when="@9: +python")
     depends_on("py-pytest", when="+python+tests")
     depends_on("py-mpi4py", when="+mpi+python+tests")
     depends_on("readline")
     depends_on("caliper", when="+caliper")
-    depends_on("py-numpy@<2", when="@:<9", type=("run","test"))
+    depends_on("py-numpy@1.999999", when="@:8.9999", type=("run","test"))
     depends_on("py-numpy", when="@9:", type=("run","test"))
 
     extends('python', when='+python')
-- 
GitLab


From 6ad61d82e0051e50124f8c43bef133e6fb7c960e Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Fri, 17 Jan 2025 12:23:27 +0100
Subject: [PATCH 4/8] Fix version specifiers

---
 packages/neuron/package.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index f5061fa4..c3a45d72 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -42,20 +42,20 @@ class Neuron(CMakePackage):
 
     depends_on("bison", type="build")
     depends_on("flex", type="build")
-    depends_on("py-cython@2.999999", when="@:8.999999 +rx3d", type="build")
+    depends_on("py-cython@:2", when="@:8 +rx3d", type="build")
     depends_on("py-cython", when="@9: +rx3d", type="build")
 
     depends_on("gettext")
     depends_on("mpi", when="+mpi")
     depends_on("ncurses")
     depends_on("python@2.7:3.11", when="@:8.2.4 +python")
-    depends_on("python@2.7:3.12", when="@8.2.5:8.99999 +python")
+    depends_on("python@2.7:3.12", when="@8.2.5:8 +python")
     depends_on("python@3.9:3.13", when="@9: +python")
     depends_on("py-pytest", when="+python+tests")
     depends_on("py-mpi4py", when="+mpi+python+tests")
     depends_on("readline")
     depends_on("caliper", when="+caliper")
-    depends_on("py-numpy@1.999999", when="@:8.9999", type=("run","test"))
+    depends_on("py-numpy@:1", when="@:8", type=("run","test"))
     depends_on("py-numpy", when="@9:", type=("run","test"))
 
     extends('python', when='+python')
-- 
GitLab


From 4b86d6cc5d1a047466da4868a32b9f1af4be6922 Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Fri, 17 Jan 2025 12:23:57 +0100
Subject: [PATCH 5/8] Update neuron version in `spack.yaml`

---
 spack.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spack.yaml b/spack.yaml
index b99a8270..60051685 100644
--- a/spack.yaml
+++ b/spack.yaml
@@ -14,7 +14,7 @@ spack:
     - py-biobb-structure-utils@4.1.0
     - hxtorch@10.0-a1
     - nest@3.8 +sonata
-    - neuron@8.2.3 +mpi
+    - neuron@8.2.6 +mpi
     - jaxsnn@10.0-a1
     - py-bluepyefe@2.3.6
     - py-bluepymm@0.8.7
-- 
GitLab


From 3e8a48756186d4d3c589d51fcdabbb3b95dc04e4 Mon Sep 17 00:00:00 2001
From: Eleni Mathioulaki <emathioulaki@athenarc.gr>
Date: Sun, 23 Feb 2025 13:36:23 +0000
Subject: [PATCH 6/8] fix(neuron): fix patch version range

---
 packages/neuron/package.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index c3a45d72..43ded970 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -62,7 +62,7 @@ class Neuron(CMakePackage):
 
     patch("patch-v782-git-cmake-avx512.patch", when="@7.8.2")
     patch("nrn_find_ncurses.patch", when="@8.2.2")
-    patch("install-python-prefix.patch", when="@8:9+python")
+    patch("install-python-prefix.patch", when="@:8.2.3+python")
 
     def cmake_args(self):
         spec = self.spec
-- 
GitLab


From ed189c5a768bebaa8166c64dbef3de3328d1a36c Mon Sep 17 00:00:00 2001
From: Eleni Mathioulaki <emathioulaki@athenarc.gr>
Date: Mon, 24 Feb 2025 11:11:21 +0000
Subject: [PATCH 7/8] fix(neuron): add missing dependencies

---
 packages/neuron/package.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index 43ded970..0a24a120 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -48,6 +48,9 @@ class Neuron(CMakePackage):
     depends_on("gettext")
     depends_on("mpi", when="+mpi")
     depends_on("ncurses")
+    depends_on("py-wheel", when="+python")
+    depends_on("py-setuptools@:59.6", when="@:8.2.1+python")
+    depends_on("py-setuptools@:70.3", when="+python")
     depends_on("python@2.7:3.11", when="@:8.2.4 +python")
     depends_on("python@2.7:3.12", when="@8.2.5:8 +python")
     depends_on("python@3.9:3.13", when="@9: +python")
-- 
GitLab


From 16c5a18bb8d0e13af3f9a184d8d9b83a4ab91c69 Mon Sep 17 00:00:00 2001
From: Goran Jelic-Cizmek <goran.jelic-cizmek@epfl.ch>
Date: Tue, 8 Apr 2025 17:18:08 +0200
Subject: [PATCH 8/8] Try workaround for `lib/python` issue

---
 .../neuron/install-python-prefix-8.2.6.patch  | 38 +++++++++++++++++++
 packages/neuron/package.py                    |  7 ++++
 2 files changed, 45 insertions(+)
 create mode 100644 packages/neuron/install-python-prefix-8.2.6.patch

diff --git a/packages/neuron/install-python-prefix-8.2.6.patch b/packages/neuron/install-python-prefix-8.2.6.patch
new file mode 100644
index 00000000..f0484736
--- /dev/null
+++ b/packages/neuron/install-python-prefix-8.2.6.patch
@@ -0,0 +1,38 @@
+diff --git a/setup.py b/setup.py
+index 0ca138e60..bb85e416d 100644
+--- a/setup.py
++++ b/setup.py
+@@ -487,7 +487,7 @@ def setup_package():
+             extra_link_args=extra_link_args
+             + [
+                 "-Wl,-rpath,{}{}".format(
+-                    REL_RPATH, "/../../" if just_extensions else "/.data/lib/"
++                    REL_RPATH, "/../../../" if just_extensions else "/.data/lib/"
+                 )
+             ],
+             **extension_common_params,
+@@ -518,7 +518,7 @@ def setup_package():
+                 extra_compile_args=extra_compile_args
+                 + ["-O2" if "NRN_BUILD_FOR_UPLOAD" in os.environ else rx3d_opt_level],
+                 extra_link_args=extra_link_args
+-                + ["-Wl,-rpath,{}".format(REL_RPATH + "/../../.data/lib/")],
++                + ["-Wl,-rpath,{}".format(REL_RPATH + "/../../../../../../" if just_extensions else "/../../.data/lib/")],
+             )
+         )
+ 
+diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt
+index 395c9e7d6..d62afce87 100644
+--- a/src/nrnpython/CMakeLists.txt
++++ b/src/nrnpython/CMakeLists.txt
+@@ -231,7 +231,10 @@ if(NRN_ENABLE_MODULE_INSTALL)
+   endforeach(pyexe)
+ 
+   add_dependencies(hoc_module nrniv_lib rxdmath ${nrnpython_lib_list})
+-  install(DIRECTORY ${NRN_PYTHON_BUILD_LIB} DESTINATION lib)
++  if(NOT DEFINED NRN_PYTHON_INSTALL_DIR)
++    set(NRN_PYTHON_INSTALL_DIR "lib")
++  endif()
++  install(DIRECTORY "${NRN_PYTHON_BUILD_LIB}/neuron" DESTINATION "${NRN_PYTHON_INSTALL_DIR}")
+ else()
+   # Make sure this is included in the wheels
+   install(FILES "${PROJECT_BINARY_DIR}/lib/python/neuron/_config_params.py"
diff --git a/packages/neuron/package.py b/packages/neuron/package.py
index 0a24a120..36845c54 100644
--- a/packages/neuron/package.py
+++ b/packages/neuron/package.py
@@ -2,6 +2,7 @@
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import sys
 
 from spack.package import *
 
@@ -66,6 +67,7 @@ class Neuron(CMakePackage):
     patch("patch-v782-git-cmake-avx512.patch", when="@7.8.2")
     patch("nrn_find_ncurses.patch", when="@8.2.2")
     patch("install-python-prefix.patch", when="@:8.2.3+python")
+    patch("install-python-prefix-8.2.6.patch", when="@8.2.6:+python")
 
     def cmake_args(self):
         spec = self.spec
@@ -106,6 +108,11 @@ class Neuron(CMakePackage):
         if "+caliper" in spec:
             args.append("-DCORENRN_CALIPER_PROFILING=ON")
 
+        # workaround for NEURON 8.2.6 installing Python components in `lib/python`
+        if self.version >= Version("8.2.6") and self.version < Version("9.0.0"):
+            py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
+            install_dir = f"lib/python{py_version}/site-packages"
+            args.append(f"-DNRN_PYTHON_INSTALL_DIR={install_dir}")
         return args
 
     @run_after("install")
-- 
GitLab