Skip to content

Instantly share code, notes, and snippets.

@birkin
Last active January 2, 2024 00:57
Show Gist options
  • Save birkin/773c8eaaee978d2ace1f93ab6e1545cf to your computer and use it in GitHub Desktop.
Save birkin/773c8eaaee978d2ace1f93ab6e1545cf to your computer and use it in GitHub Desktop.
hack to get djanto to work with ancient version of sqlite. don't do this at home.
#!/bin/bash
function usage() {
echo "Usage: $(basename "${0}") <full path to repo directory>"
echo
echo "Example: $(basename "${0}") /path/to/github_project_dir"
exit
}
function sourceVirtEnv() {
# changing to app (repo) directory, not outside "stuff" directory
if ! cd "${appDir}"; then
echo "Exiting. ${appDir} does not exist"; echo
exit
elif [[ ! -L ../env ]]; then
echo "Exiting. Missing 'env' Symlink, please fix and re-run the script"; echo
exit
fi
if source "${appDir}/../env/bin/activate"; then
echo "Sourcing virtual environment for: ${appDir}"
else
echo "Exiting. Unable to source virtual environment"
exit
fi
}
function fixTests() {
# configure virtual environment to use pysqlite3 to circumvent rhel sqlite3 version issue
sourceVirtEnv
# The following only needs to be run for Django Projects, skip if django is not installed
if pip freeze | grep -i django; then
pip install pysqlite3 # used in place of the system sqlite version (which is severely outdated)
pip install pysqlite3-binary # needed, otherwise I had to export LD_LIBRARY_PATH
# pip install responses # used by BDR in most projects
# Change library 'from sqlite3' to 'from pysqlite3'
sed -i 's/from sqlite3 import/from pysqlite3 import/g' "${appDir}/../env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py"
# echo "Fixed tests by replacing sqlite with pysqlite3... deactivating virtual environment: ${VIRTUAL_ENV}"
fi
deactivate
}
main () { echo; } ## main () ##
ARGS=( $@ )
[[ ${#ARGS[@]} -lt 1 ]] && usage
appDir="$1"
sourceVirtEnv
fixTests
echo "project's django package has been updated to able to use sqlite."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment