Repository: spack/spack

Issue:
Fixes and improvements to py-pyprecice
This PR contains several fixes and improvements of the Spack package for `py-pyprecice`. I would need some *feedback* on how to handle the installation when one uses Spack with a pre-installed Python version available on a system.

The initial reason for my work was to make `py-pyprecice` usable when Spack uses Python provided by the system (see also https://github.com/precice/python-bindings/issues/86 and https://github.com/precice/python-bindings/issues/87). With the current changes it is possible to install `py-pyprecice@.2.2.0.1:` using the current `develop` of Spack while using the system's preinstalled Python 3 environment.  

For older versions, i.e. `py-pyprecice@:2.1.1.2`, it still results in an unusable package when a preinstalled Python is used with Spack. `py-pyprecice` is compiled and installed, but the resulting files seem to be put into a wrong directory. The files end up in `<prefix>/lib/python3.8/site-packages/` while Spack seems to expect it at `<prefix>/lib/python3/dist-packages/`. I am not sure if this is due to the unusual installation procedure of `py-precice@:2.1.1.2` which makes it necessary to overwrite Spack's installation and building flags for the package. Feedback on this would be appreciated.

I tested this on Ubuntu 20.04 with Python@3.8.10 which was detected by `spack external find`.

**Changes:**
- Fixing the installation process for the bindings v2.0.0.1. The `setup.py` differed from other versions up to v2.1.1.2. Thus, application of the patch `deactivate-version-check-via-pip.patch` failed. I added an additional patch `setup-v2.0.0.1.patch` that updates the `setup.py` such that `deactivate-version-check-via-pip.patch` can be applied to v2.0.0.1.
- The patch `deactivate-version-check-via-pip.patch` was not applied to v2.1.1.2 in the previous Spack package such that the installation would fail.
- v2.2.0.1 introduced a new installation routine that is much closer to standard Python packages. However, this made the Spack package a bit more complicated. I added a new patch `setup-v2-versioneer.patch`which adapts the `setup.py` which allows to simplify the Spack package again. This change is also reported upstream https://github.com/precice/python-bindings/pull/113



Discussion:
  @BenjaminRodenberg @IshaanDesai can you review this PR?

  This PR modifies the following package(s), for which you are listed as a maintainer:

  * py-pyprecice


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-pyprecice/package.py b/var/spack/repos/builtin/packages/py-pyprecice/package.py
--- a/var/spack/repos/builtin/packages/py-pyprecice/package.py
+++ b/var/spack/repos/builtin/packages/py-pyprecice/package.py
@@ -30,11 +30,6 @@ class PyPyprecice(PythonPackage):
     version("2.0.0.2", sha256="5f055d809d65ec2e81f4d001812a250f50418de59990b47d6bcb12b88da5f5d7")
     version("2.0.0.1", sha256="96eafdf421ec61ad6fcf0ab1d3cf210831a815272984c470b2aea57d4d0c9e0e")
 
-    # Older versions of the bindings checked versions via pip. This patch
-    # removes the pip dependency.
-    # See also https://github.com/spack/spack/pull/19558
-    patch("deactivate-version-check-via-pip.patch", when="@:2.1.1.1")
-
     depends_on("precice@develop", when="@develop")
     depends_on("precice@2.2.1", when="@2.2.1.1:2.2.1.99")
     depends_on("precice@2.2.0", when="@2.2.0.1:2.2.0.99")
@@ -44,22 +39,16 @@ class PyPyprecice(PythonPackage):
     depends_on("precice@2.0.1", when="@2.0.1.1:2.0.1.99")
     depends_on("precice@2.0.0", when="@2.0.0.1:2.0.0.99")
 
-    depends_on("python@3:", type=("build", "run"))
+    depends_on("python@3:", type=("build", "link", "run"))
     depends_on("py-setuptools", type="build")
-    depends_on("py-numpy", type=("build", "run"))
+    depends_on("py-numpy", type=("build", "link", "run"))
     depends_on("py-mpi4py", type=("build", "run"))
-    depends_on("py-cython@0.29:", type=("build"))
-
-    phases = ['install_lib', 'build_ext', 'install']
-
-    def build_ext_args(self, spec, prefix):
-        return [
-            "--include-dirs=" + spec["precice"].headers.directories[0],
-            "--library-dirs=" + spec["precice"].libs.directories[0]
-        ]
-
-    def install(self, spec, prefix):
-        # Older versions of the bindings had a non-standard installation routine
-        # See also https://github.com/spack/spack/pull/19558#discussion_r513123239
-        if self.version <= Version("2.1.1.1"):
-            self.setup_py("install", "--prefix={0}".format(prefix))
+    depends_on("py-cython@0.29:", type="build")
+    depends_on("py-packaging", when="@:2.1", type="build")
+    depends_on("py-pip", when="@:2.1", type="build")
+
+    @when("@:2.1")
+    def patch(self):
+        filter_file(
+            "distutils.command.install", "setuptools.command.install", "setup.py"
+        )


Test patch: