Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0587070
Import to check traceback.
lgautier Feb 16, 2025
e1799a2
Untabify.
lgautier Feb 16, 2025
1a1f75d
Merge branch 'master' into debug-import-api-win
lgautier Feb 16, 2025
9433148
Add DLL for R.
lgautier Feb 16, 2025
9f32797
Merge branch 'debug-import-api-win' of github.com:rpy2/rpy2 into debu…
lgautier Feb 16, 2025
88afa9b
Add echo markers.
lgautier Feb 16, 2025
c355742
Untabify.
lgautier Feb 16, 2025
eb54bf3
Print env variable for debugging purposes.
lgautier Feb 16, 2025
83d0016
Untabify.
lgautier Feb 16, 2025
330e368
Spurious ")".
lgautier Feb 16, 2025
0e41179
Add dynamic addition of path to R DLL(s) on Windows.
lgautier Feb 16, 2025
d71532d
Fix call to get path to R DLLs.
lgautier Feb 16, 2025
4328e21
Keep mypy happy when function only present on Windows.
lgautier Feb 16, 2025
046af48
Adjust Windows initializatiof of embedded R.
lgautier Feb 16, 2025
55c302e
Adjust callbacks to initialize to attributes of structRstart.
lgautier Feb 16, 2025
a561f94
Try without callbacks.
lgautier Feb 16, 2025
fcbf02a
Split rinterface and robjects tests.
lgautier Feb 16, 2025
78d75dd
Add memory protection when performing promise evaluation.
lgautier Feb 16, 2025
8316373
Comment out test.
lgautier Feb 16, 2025
181ee07
Drop all tests for buffer protocol.
lgautier Feb 16, 2025
cdd3cd9
Use Rf_initialize_R on Windows as well.
lgautier Feb 16, 2025
78b6ae3
RStart build intpo function.
lgautier Feb 16, 2025
f383b02
Syntax errors.
lgautier Feb 16, 2025
edd5ab2
Fix function name.
lgautier Feb 16, 2025
c862bec
Linting.
lgautier Feb 16, 2025
14ff865
cffi-defined objects need protection from GC?
lgautier Feb 16, 2025
302a8ad
Comment out _register_external_symbols().
lgautier Feb 16, 2025
74a2904
Character mode.
lgautier Feb 17, 2025
37f61ba
Add test with only intialization.
lgautier Feb 17, 2025
d9f1a83
Untabify. Create static copy of user home path string on Windows.
lgautier Feb 17, 2025
c30582a
Check if Windows binary can access R objects or eval R function call.
lgautier Feb 23, 2025
640df78
Untabify.
lgautier Feb 23, 2025
625a039
Fix typo in env name.
lgautier Feb 23, 2025
3f56f50
Restore registration of external symbols.
lgautier Feb 23, 2025
06b82b1
Clean cdata protection. Restore additional set for RStart.
lgautier Feb 23, 2025
4beece2
API mode fails quickly with segfault on Windows. Make mode ANY == ABI.
lgautier Feb 23, 2025
8b5257b
Report each test while running it.
lgautier Feb 23, 2025
cc0ce42
Call tests files and drop coverage for them.
lgautier Feb 23, 2025
1b8b8c8
Pytest failing. Try running a demo file.
lgautier Feb 23, 2025
d9a8d09
Add setup Rmainloop on Windows.
lgautier Feb 23, 2025
c4f5439
Do not set callbacks on Windows.
lgautier Feb 23, 2025
4d2387a
Merge branch 'master' into debug-import-api-win
lgautier Mar 16, 2025
278f300
Update embedded_mswin.py
lgautier Mar 16, 2025
8979fc2
Linting.
lgautier Mar 16, 2025
821c5f5
Merge branch 'master' into debug-import-api-win
lgautier Mar 16, 2025
6362455
Merge branch 'master' into debug-import-api-win
lgautier Mar 16, 2025
7037efd
Update embedded_mswin.py
lgautier Mar 16, 2025
7fa2020
Merge branch 'master' into debug-import-api-win
lgautier Mar 16, 2025
187d043
Update embedded_mswin.py
lgautier Mar 16, 2025
8e83dcf
Update embedded_mswin.py
lgautier Mar 16, 2025
e9401c7
Update embedded_mswin.py
lgautier Mar 16, 2025
1f37895
Merge branch 'master' into debug-import-api-win
lgautier Mar 16, 2025
38ca0ed
Update embedded_mswin.py
lgautier Mar 17, 2025
8ac6c62
Update run_test_min_deps.sh
lgautier Mar 17, 2025
ebcd240
Update _rinterface_capi.py
lgautier Mar 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.12"]
r-version: [release]
os: ["windows-latest", ubuntu-latest, macos-14, macos-15]
os: ["windows-latest"]
exclude:
- os: macos-14
python-version: 3.9
Expand Down Expand Up @@ -190,9 +190,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.12"]
r-version: [release]
os: ["windows-latest", ubuntu-latest, macos-14]
os: ["windows-latest"]
exclude:
- os: macos-14
python-version: 3.9
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ jobs:
echo "With dev for rpy2-rinterface."
python3 -m pip install --pre ${{ env.RPY2_ROBJECTS_WHL_DIST }}'[test_minimal]'
${{ env.R_LIBRARY }}
python -c 'from rpy2.rinterface_lib import openrlib; print(openrlib.cffi_mode)'
echo 'initr()'
python -c 'import rpy2.rinterface as ri; ri.initr()'
echo 'print pi'
python -c 'import rpy2.rinterface as ri; ri.initr(); print(ri.baseenv["pi"])'
echo 'print rep'
python -c 'import rpy2.rinterface as ri; ri.initr(); print(ri.baseenv["rep"](1, 2))'
bash -e ./scripts/run_test_min_deps.sh
- name: Test with numpy
run: |
Expand Down
15 changes: 8 additions & 7 deletions rpy2-rinterface/src/rpy2/rinterface_lib/_rinterface_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from _cffi_backend import FFI # type: ignore


logger = logging.getLogger(__name__)
# Preserve cdata allocated by cffi from garbage collection.
__cffi_protected = {}
Expand Down Expand Up @@ -333,12 +332,13 @@ def build_rcall(rfunction,

def _evaluated_promise(function):
def _(*args, **kwargs):
robj = function(*args, **kwargs)
if _TYPEOF(robj) == openrlib.rlib.PROMSXP:
robj = openrlib.rlib.Rf_eval(
robj,
openrlib.rlib.R_GlobalEnv)
return robj
with memorymanagement.rmemory() as rmemory:
robj = rmemory.protect(function(*args, **kwargs))
if _TYPEOF(robj) == openrlib.rlib.PROMSXP:
robj = openrlib.rlib.Rf_eval(
robj,
openrlib.rlib.R_GlobalEnv)
return robj
return _


Expand Down Expand Up @@ -640,6 +640,7 @@ def _register_external_symbols() -> None:
python_callback,
-1],
[ffi.NULL, ffi.NULL, 0]])

openrlib.rlib.R_registerRoutines(
openrlib.rlib.R_getEmbeddingDllInfo(),
ffi.NULL,
Expand Down
12 changes: 5 additions & 7 deletions rpy2-rinterface/src/rpy2/rinterface_lib/embedded.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import typing
import warnings
import rpy2.situation
from rpy2.rinterface_lib import openrlib
from rpy2.rinterface_lib import callbacks
if os.name == 'nt':
Expand All @@ -22,6 +23,8 @@


class Is_RStart(Protocol):
"""Type-checking helper."""

@property
def rhome(self): ...

Expand Down Expand Up @@ -216,7 +219,7 @@ def _setcallback(rlib, rlib_symbol: str,
the new callback function
:param callbacks: Namespace in which to find the callback function.
:param callbacks_symbol: Symbol (name) of the new callback function.
"""
"""
if callback_symbol is None:
new_callback = ffi.NULL
else:
Expand Down Expand Up @@ -263,12 +266,7 @@ def _initr(
_c_stack_limit = _DEFAULT_C_STACK_LIMIT

rlib = openrlib.rlib
ffi_proxy = openrlib.ffi_proxy
if (
ffi_proxy.get_ffi_mode(openrlib._rinterface_cffi)
==
ffi_proxy.InterfaceType.ABI
):
if openrlib.cffi_mode is rpy2.situation.CFFI_MODE.ABI:
callback_funcs = callbacks
else:
callback_funcs = rlib
Expand Down
38 changes: 28 additions & 10 deletions rpy2-rinterface/src/rpy2/rinterface_lib/embedded_mswin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import typing
import rpy2.situation
from rpy2.rinterface_lib import embedded
from rpy2.rinterface_lib import callbacks
from rpy2.rinterface_lib import openrlib
Expand Down Expand Up @@ -28,23 +29,37 @@

def _build_rstart(rhome, interactive, setcallbacks):
rstart = ffi.new('Rstart')
# TODO: Where should rstart be protected?
embedded.rstart = rstart
__cffi_protected['rstart'] = rstart
openrlib.rlib.R_DefParams(rstart)
# TODO: A cleanup / consolidation of "R HOME"
# definition is needed.
print(f'rhome: {rhome}')
rstart.rhome = rhome
userhome = ffi.new("char[]", ffi.string(openrlib.rlib.getRUser()))
__cffi_protected['userhome'] = userhome
rstart.home = userhome
rstart.CharacterMode = openrlib.rlib.LinkDLL
if setcallbacks:
for rstart_name, callback_name in CALLBACK_INIT_PAIRS:
if callback_name is not None:
setattr(rstart, rstart_name,
getattr(callbacks, callback_name))

rstart.R_Quiet = True
rstart.R_Slave = False
rstart.R_Interactive = interactive
# TODO: Force verbose for now.
rstart.R_Verbose = True
rstart.LoadSiteFile = True
rstart.LoadInitFile = True
rstart.RestoreAction = openrlib.rlib.SA_RESTORE
rstart.SaveAction = openrlib.rlib.SA_NOSAVE
rstart.CharacterMode = openrlib.rlib.LinkDLL # 1?
if setcallbacks:
if openrlib.cffi_mode is rpy2.situation.CFFI_MODE.ABI:
callback_funcs = callbacks
else:
callback_funcs = openrlib.rlib

for rstart_symbol, callback_symbol in CALLBACK_INIT_PAIRS:
embedded._setcallback(rstart, rstart_symbol,
callback_funcs, callback_symbol)

rstart.vsize = ffi.cast('size_t', _DEFAULT_VSIZE)
rstart.nsize = ffi.cast('size_t', _DEFAULT_NSIZE)
Expand Down Expand Up @@ -79,11 +94,12 @@ def _initr_win32(
if embedded.isinitialized():
return None

options_c = [ffi.new('char[]', o.encode('ASCII'))
options_c = [ffi.new('char[]', o.encode('utf-8'))
for o in embedded._options]
n_options = len(options_c)
n_options_c = ffi.cast('int', n_options)
status = openrlib.rlib.Rf_initEmbeddedR(n_options_c, options_c)
status = openrlib.rlib.Rf_initEmbeddedR(len(options_c),
ffi.new('char *[]', options_c))
# status = openrlib.rlib.Rf_initialize_R(len(options_c),
# ffi.new('char *[]', options_c))
embedded._setinitialized()

rhome = openrlib.rlib.get_R_HOME()
Expand All @@ -93,5 +109,7 @@ def _initr_win32(

# TODO: still needed ?
openrlib.rlib.R_CStackLimit = ffi.cast('uintptr_t', _c_stack_limit)
# Restore if using Rf_initialize_R ?
# openrlib.rlib.setup_Rmainloop()

return status
1 change: 1 addition & 0 deletions rpy2-rinterface/src/rpy2/rinterface_lib/openrlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
raise ImportError(
f'cffi mode requested invalid: {cffi_mode_request}'
)

ffi = _rinterface_cffi.ffi

lock = threading.Lock()
Expand Down
13 changes: 12 additions & 1 deletion scripts/run_test_min_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
set -e
set -x

# python doc/_static/demos/example01.py

pytest \
--verbose
--cov-report=xml \
--cov-report=term \
--cov=rpy2.rinterface_lib \
--cov=rpy2.rinterface \
--cov=rpy2.rlike \
./rpy2-rinterface/src/rpy2/rinterface/tests

pytest \
--cov-append \
--cov-report=xml \
--cov-report=term \
--cov=rpy2.rinterface_lib \
--cov=rpy2.rinterface \
--cov=rpy2.rlike \
--cov=rpy2.ipython \
--cov=rpy2.robjects \
./rpy2-rinterface/src/rpy2/rinterface/tests \
./rpy2-robjects/src/rpy2/robjects/tests

pytest \
Expand Down
Loading