Skip to content

Commit

Permalink
Install pre-commit for cccl devcontainers (rapidsai#266)
Browse files Browse the repository at this point in the history
* Install pre-commit for cccl devcontainers

* bump cccl-dev feature version

---------

Co-authored-by: ptaylor <[email protected]>
  • Loading branch information
miscco and trxcllnt authored Apr 16, 2024
1 parent bcf50e2 commit 90c88a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
9 changes: 9 additions & 0 deletions features/src/cccl-dev/.bashrc
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export LIT_VERSION="${LIT_VERSION}";

if [ -f "${USERHOME}/.local/share/venvs/cccl/bin/activate" ] \
&& [ -z "${VIRTUAL_ENV:-}" -o "${VIRTUAL_ENV}" != "${USERHOME}/.local/share/venvs/cccl" ]; then
. "${USERHOME}/.local/share/venvs/cccl/bin/activate";
elif [ -n "${VIRTUAL_ENV_PROMPT:-}" ]; then
if ! echo "${PS1:-}" | grep -qF "${VIRTUAL_ENV_PROMPT}"; then
export PS1="${VIRTUAL_ENV_PROMPT}${PS1:-}";
fi
fi
2 changes: 1 addition & 1 deletion features/src/cccl-dev/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "NVIDIA CCCL development utilities",
"id": "cccl-dev",
"version": "24.6.0",
"version": "24.6.1",
"description": "A feature to install NVIDIA CCCL development utilities",
"options": {
"litVersion": {
Expand Down
46 changes: 30 additions & 16 deletions features/src/cccl-dev/install.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#! /usr/bin/env bash
set -e
set -ex

LIT_VERSION="${LITVERSION:-latest}";

if [ "$LIT_VERSION" -neq "latest" ]; then
LIT_VERSION_TO_INSTALL="lit==$LIT_VERSION"
else
if [ "$LIT_VERSION" = "latest" ]; then
LIT_VERSION_TO_INSTALL="lit"
else
LIT_VERSION_TO_INSTALL="lit==$LIT_VERSION"
fi;

# Ensure we're in this feature's directory during build
Expand All @@ -29,25 +29,39 @@ if [[ "$(uname -p)" != "x86_64" ]]; then
if ! type g++ >/dev/null 2>&1; then PKG_TO_REMOVE+=("g++"); fi
fi

check_packages ${PKG[@]} ${PKG_TO_REMOVE[@]};
check_packages "${PKG[@]}" "${PKG_TO_REMOVE[@]}";

source /etc/lsb-release;
# Find the non-root user
find_non_root_user;
USERNAME="${USERNAME:-root}";
USERHOME="$(bash -c "echo ~${USERNAME-}")";

if [[ ! "23.04" > "${DISTRIB_RELEASE}" ]]; then
BREAK_PACKAGES="--break-system-packages"
fi
# shellcheck disable=SC2174
mkdir -p -m 0755 \
"${USERHOME}/.local" \
"${USERHOME}/.local/share" \
"${USERHOME}/.local/share/venvs" \
"${USERHOME}/.local/share/venvs/cccl" \
;

python -m venv "${USERHOME}/.local/share/venvs/cccl";
# shellcheck disable=SC1091
. "${USERHOME}/.local/share/venvs/cccl/bin/activate";
CC=gcc CXX=g++ python -m pip install -U pip;
CC=gcc CXX=g++ python -m pip install -U wheel setuptools;
CC=gcc CXX=g++ python -m pip install -U psutil "${LIT_VERSION_TO_INSTALL}" pre-commit;

CC=gcc CXX=g++ python -m pip install $BREAK_PACKAGES --upgrade pip
CC=gcc CXX=g++ python -m pip install $BREAK_PACKAGES wheel setuptools;
CC=gcc CXX=g++ python -m pip install $BREAK_PACKAGES psutil $LIT_VERSION_TO_INSTALL;
# Ensure the user owns their homedir
chown -R "${USERNAME}:${USERNAME}" "${USERHOME}";

export USERHOME;
export LIT_VERSION="$(lit --version | grep -o -e '[0-9].*')";

# export envvars in bashrc files
append_to_etc_bashrc "$(cat .bashrc | envsubst '$LIT_VERSION')";
append_to_all_bashrcs "$(cat .bashrc | envsubst '$LIT_VERSION')";
append_to_etc_bashrc "$(cat .bashrc | envsubst '$LIT_VERSION $USERHOME')";
append_to_all_bashrcs "$(cat .bashrc | envsubst '$LIT_VERSION $USERHOME')";
# export envvars in /etc/profile.d
add_etc_profile_d_script cccl-dev "$(cat .bashrc | envsubst '$LIT_VERSION')";
add_etc_profile_d_script cccl-dev "$(cat .bashrc | envsubst '$LIT_VERSION $USERHOME')";

# Clean up
# rm -rf /tmp/*;
Expand All @@ -56,6 +70,6 @@ rm -rf /var/cache/apt/*;
rm -rf /var/lib/apt/lists/*;

if [[ ${#PKG_TO_REMOVE[@]} -gt 0 ]]; then
DEBIAN_FRONTEND=noninteractive apt-get -y remove ${PKG_TO_REMOVE[@]};
DEBIAN_FRONTEND=noninteractive apt-get -y remove "${PKG_TO_REMOVE[@]}";
DEBIAN_FRONTEND=noninteractive apt-get -y autoremove;
fi
2 changes: 1 addition & 1 deletion features/src/utils/.bashrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dont prepend an empty string to sys.path in interactive Python REPLs
# Don't prepend an empty string to sys.path in interactive Python REPLs
# https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONSAFEPATH
export PYTHONSAFEPATH="${PYTHONSAFEPATH:-1}";

Expand Down

0 comments on commit 90c88a9

Please sign in to comment.