Skip to content

Commit

Permalink
Remove rpy2 (#9886)
Browse files Browse the repository at this point in the history
* Remove rpy2

* Add TODO comment

* Remove unused import

* Fix filename
  • Loading branch information
nwalters512 committed May 23, 2024
1 parent 483b5ce commit a831ebe
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 120 deletions.
4 changes: 2 additions & 2 deletions apps/prairielearn/python/zygote.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@
prairielearn.get_unit_registry()


# We want to conditionally allow/block importing specific modules, namely `rpy2`.
# We want to conditionally allow/block importing specific modules.
# This custom importer will allow us to do so, and throw a custom error message.
#
# While this won't prevent anything more complex than an `import` statement, it
# will make it clear to the user that they're not allowed to use `rpy2`. If they
# will make it clear to the user that they're not allowed to use. If they
# try to bypass the block, it's up to them to deal with the consequences.
class ForbidModuleMetaPathFinder(MetaPathFinder):
def __init__(self) -> None:
Expand Down
9 changes: 1 addition & 8 deletions apps/prairielearn/src/lib/code-caller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as Sentry from '@prairielearn/sentry';

import * as chunks from '../chunks.js';
import { config } from '../config.js';
import { features } from '../features/index.js';
import * as load from '../load.js';

import { CodeCallerContainer, init as initCodeCallerDocker } from './code-caller-container.js';
Expand Down Expand Up @@ -197,12 +196,6 @@ export async function withCodeCaller(course, fn) {
});
}

// Determine if this course is allowed to use `rpy2`.
const allowRpy2 = await features.enabled('allow-rpy2', {
institution_id: course.institution_id,
course_id: course.id,
});

const jobUuid = uuidv4();
load.startJob('python_callback_waiting', jobUuid);

Expand All @@ -212,7 +205,7 @@ export async function withCodeCaller(course, fn) {
const coursePath = chunks.getRuntimeDirectoryForCourse(course);
await codeCaller.prepareForCourse({
coursePath,
forbiddenModules: allowRpy2 ? [] : ['rpy2'],
forbiddenModules: [],
});
} catch (err) {
// If we fail to prepare for a course, assume that the code caller is
Expand Down
1 change: 0 additions & 1 deletion apps/prairielearn/src/lib/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const featureNames = [
// Can only be applied to courses/institutions.
'process-questions-in-worker',
'question-sharing',
'allow-rpy2',
// Can only be applied to institutions.
'lti13',
'terms-clickthrough',
Expand Down
56 changes: 0 additions & 56 deletions apps/prairielearn/src/tests/rpy2.test.ts

This file was deleted.

38 changes: 5 additions & 33 deletions images/plbase/plbase-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,17 @@ echo "setting up postgres..."
mkdir /var/postgres && chown postgres:postgres /var/postgres
su postgres -c "initdb -D /var/postgres"

# TODO: use standard OS Python installation? The only reason we switched to Conda
# was to support R and `rpy2`, but now that we've removed those, we might not
# get any benefit from Conda.
echo "setting up conda..."
cd /
arch=`uname -m`
curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${arch}.sh
bash Miniforge3-Linux-${arch}.sh -b -p /usr/local -f

# If R package installation is specifically disabled, we'll avoid installing anything R-related.
if [[ "${SKIP_R_PACKAGES}" != "yes" ]]; then
echo "installing R..."
conda install --channel r r-base r-essentials

echo "installing Python packages..."
python3 -m pip install --no-cache-dir -r /python-requirements.txt
else
echo "R package installation is disabled"
sed '/rpy2/d' /python-requirements.txt > /py_req_no_r.txt # Remove rpy2 package.
echo "installing Python packages..."
python3 -m pip install --no-cache-dir -r /py_req_no_r.txt
fi

# `pyarrow` and `rpy2` conflict in a horrible way:
#
# - `pyarrow` will load `/usr/lib64/libstdc++.so.6.0.29`
# - `rpy2` will load `/usr/local/lib/libstdc++.so.6.0.32`
#
# `pyarrow` gets autoloaded by `pandas`, which we in turn load in the zygote.
# If someone then tries to load `rpy2` in question code, it will fail to load
# with the following error:
#
# cannot load library '/usr/local/lib/R/lib/libR.so': /lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found
#
# This is because `rpy2` needs a version of `libstdc++` that supports libstd++ 3.4.30,
# but `pyarrow` has already loaded a version of `libstdc++` that only supports up to 3.4.29.
#
# We work around that by setting up a symlink to the newer version of `libstdc++`.
#
# TODO: We can probably undo this change once we're removed R and `rpy2`.
# TODO: We could also probably remove this when Amazon Linux picks up a newer version of the `gcc` suite.
ln -sf /usr/local/lib/libstdc++.so.6 /usr/lib64/libstdc++.so.6
echo "installing Python packages..."
python3 -m pip install --no-cache-dir -r /python-requirements.txt

# Clear various caches to minimize the final image size.
dnf clean all
Expand Down
1 change: 0 additions & 1 deletion images/plbase/python-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pytest-repeat==0.9.3
pytest==8.2.0
recommonmark==0.7.1
regex==2024.4.28
rpy2==3.5.12
ruff==0.4.0
schemdraw==0.19
scikit-learn==1.4.2
Expand Down
6 changes: 0 additions & 6 deletions testCourse/questions/rpy2/info.json

This file was deleted.

7 changes: 0 additions & 7 deletions testCourse/questions/rpy2/question.html

This file was deleted.

6 changes: 0 additions & 6 deletions testCourse/questions/rpy2/server.py

This file was deleted.

0 comments on commit a831ebe

Please sign in to comment.