Unverified Commit b4413a7e authored by Mauricio Collares's avatar Mauricio Collares Committed by GitHub
Browse files

sage, python313Packages.rpy2: unbreak (#441027)

parents b7cdf29c ac85f482
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -82,6 +82,20 @@ stdenv.mkDerivation rec {
      url = "https://github.com/sagemath/sage/commit/d0cbe9d353722580f98a327694f1a361c9b83ccd.patch?full_index=1";
      hash = "sha256-uV2nttxCKDsNqMf1O+lUmuoiDrx7/CfiS00JBb9kiM8=";
    })

    # https://github.com/sagemath/sage/pull/40156, landed in 10.7.beta5
    (fetchpatch2 {
      name = "cython-3.1-update.patch";
      url = "https://github.com/sagemath/sage/commit/5ea8db28977ec113aec3c4c4b208d1783e3937a7.patch?full_index=1";
      hash = "sha256-5DPPxMuidPpVHrjK8j0UVZzuwiVy9vQzFd6hBYwNAok=";
    })

    # https://github.com/sagemath/sage/pull/40175, landed in 10.7.beta8
    (fetchpatch2 {
      name = "rpy2-3.6-update.patch";
      url = "https://github.com/sagemath/sage/commit/db2d8db99d9a7dfa1972d534ecd89e3d2ba5c55b.patch?full_index=1";
      hash = "sha256-6Bk0uGlKFsiDsgv+ljMC1YnmAT+g+he6aFNkpvw2on0=";
    })
  ];

  patches = nixPatches ++ bugfixPatches ++ packageUpgradePatches;
+79 −0
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  buildPythonPackage,
  fetchurl,
  isPyPy,
  R,
  rWrapper,
  xz,
  bzip2,
  zlib,
  zstd,
  icu,
  pytestCheckHook,
  setuptools,
  cffi,
}:

buildPythonPackage rec {
  version = "3.6.3";
  format = "pyproject";
  pname = "rpy2-rinterface";

  disabled = isPyPy;
  src = fetchurl {
    url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${
      builtins.replaceStrings [ "-" ] [ "_" ] pname
    }-${version}.tar.gz";
    hash = "sha256-R3vC9R0AetG4VnxdS6GvD1mVFobufxBXagbQg03ld28=";
  };

  patches = [
    # https://github.com/rpy2/rpy2/pull/1171#issuecomment-3263994962
    ./restore-initr-simple.patch

    # R_LIBS_SITE is used by the nix r package to point to the installed R libraries.
    # This patch sets R_LIBS_SITE when rpy2 is imported.
    ./rpy2-3.x-r-libs-site.patch
  ];

  postPatch = ''
    substituteInPlace 'src/rpy2/rinterface_lib/embedded.py' --replace '@NIX_R_LIBS_SITE@' "$R_LIBS_SITE"
  '';

  buildInputs = [
    xz
    bzip2
    zlib
    zstd
    icu
  ]
  ++ rWrapper.recommendedPackages;

  nativeBuildInputs = [
    R # needed at setup time to detect R_HOME (alternatively set R_HOME explicitly)
  ];

  propagatedBuildInputs = [
    cffi
    setuptools
  ];

  nativeCheckInputs = [ pytestCheckHook ];

  # https://github.com/rpy2/rpy2/issues/1111
  disabledTests = [
    "test_parse_incomplete_error"
    "test_parse_error"
    "test_parse_error_when_evaluting"
  ];

  meta = {
    homepage = "https://rpy2.github.io/";
    description = "Python interface to R";
    license = lib.licenses.gpl2Plus;
    platforms = lib.platforms.unix;
    maintainers = with lib; [ teams.sage ];
  };
}
+20 −0
Original line number Diff line number Diff line
diff --git a/src/rpy2/rinterface/__init__.py b/src/rpy2/rinterface/__init__.py
index 0ba46083..1f4265aa 100644
--- a/src/rpy2/rinterface/__init__.py
+++ b/src/rpy2/rinterface/__init__.py
@@ -1100,6 +1100,15 @@ NA = None
 NA_Real = None
 NA_Complex = None
 
+def initr_simple() -> typing.Optional[int]:
+    """Initialize R's embedded C library."""
+    with openrlib.rlock:
+        status = embedded._initr()
+        atexit.register(endr, 0)
+        _rinterface._register_external_symbols()
+        _post_initr_setup()
+        return status
+
 
 def initr(
         interactive: typing.Optional[bool] = None,
+19 −0
Original line number Diff line number Diff line
diff --git a/rpy2/rinterface_lib/embedded.py b/rpy2/rinterface_lib/embedded.py
index ccd3a315..51fb5da4 100644
--- a/rpy2/rinterface_lib/embedded.py
+++ b/rpy2/rinterface_lib/embedded.py
@@ -276,6 +276,16 @@ def _initr(
                  os.environ.get('LD_LIBRARY_PATH', ''))
                 )
         )
+
diff --git a/src/rpy2/rinterface_lib/embedded.py b/src/rpy2/rinterface_lib/embedded.py
index cc9f7da1..10626f13 100644
--- a/src/rpy2/rinterface_lib/embedded.py b/src/rpy2/rinterface_lib/embedded.py
@@ -328,6 +328,15 @@ def _initr(
             _setinitialized()
             return None
 
+        # path to libraries
+        existing = os.environ.get('R_LIBS_SITE')
+        if existing is not None:
@@ -16,6 +14,6 @@ index ccd3a315..51fb5da4 100644
+        additional = '@NIX_R_LIBS_SITE@'
+        os.environ['R_LIBS_SITE'] = prefix + additional
+
         options_c = [ffi.new('char[]', o.encode('ASCII')) for o in _options]
         n_options = len(options_c)
         n_options_c = ffi.cast('int', n_options)
         # TODO: Setting LD_LIBRARY_PATH after the process has started
         # is too late. Because of this, the line below does not help
         # address issues where calling R from the command line is working
+63 −0
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  buildPythonPackage,
  fetchurl,
  fetchpatch2,
  isPyPy,
  R,
  rpy2-rinterface,
  ipython,
  jinja2,
  numpy,
  pandas,
  tzlocal,
  pytestCheckHook,
}:

buildPythonPackage rec {
  version = "3.6.2";
  format = "pyproject";
  pname = "rpy2-robjects";

  disabled = isPyPy;
  src = fetchurl {
    url = "mirror://pypi/${builtins.substring 0 1 pname}/${pname}/${
      builtins.replaceStrings [ "-" ] [ "_" ] pname
    }-${version}.tar.gz";
    hash = "sha256-rJGvMtXE2iNrBaPNaNr7JM2PWogPAHhim48r8CUFQjs=";
  };

  patches = [
    # https://github.com/rpy2/rpy2/pull/1171#issuecomment-3263994962
    (fetchpatch2 {
      url = "https://github.com/rpy2/rpy2/commit/524546eef9b8f7f3d61aeb76d7e7fa7beeabd2d2.patch?full_index=1";
      hash = "sha256-aR44E8wIBlD7UpQKm7B+aMn2p3FQ8dwBwLwkibIpcuM=";
      relative = "rpy2-robjects";
      revert = true;
    })
  ];

  nativeBuildInputs = [
    R # needed at setup time to detect R_HOME (alternatively set R_HOME explicitly)
  ];

  propagatedBuildInputs = [
    ipython
    jinja2
    numpy
    pandas
    rpy2-rinterface
    tzlocal
  ];

  nativeCheckInputs = [ pytestCheckHook ];

  meta = {
    homepage = "https://rpy2.github.io/";
    description = "Python interface to R";
    license = lib.licenses.gpl2Plus;
    platforms = lib.platforms.unix;
    maintainers = with lib.maintainers; [ joelmo ];
  };
}
Loading