Skip to content

Instantly share code, notes, and snippets.

@brianthelion
Last active February 17, 2019 13:44
Show Gist options
  • Save brianthelion/64cfa2bd9e91e78dc74f6ddcba0b42e1 to your computer and use it in GitHub Desktop.
Save brianthelion/64cfa2bd9e91e78dc74f6ddcba0b42e1 to your computer and use it in GitHub Desktop.
Example of using constraints.txt with local dependencies in "editable" mode
#! /bin/bash
set -e
random-string() {
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w ${1:-32} | head -n 1
}
BASENAME=$(basename "$0")
TMP_DIR=$(mktemp -d -t ${BASENAME}-XXXXX)
VENV_DIR=${TMP_DIR}/_venv3
NS=ns$(random-string 10)
PKGX=py$(random-string 10)
PKGY=py$(random-string 10)
PKGZ=py$(random-string 10)
echo ${TMP_DIR}
python3 -m venv ${VENV_DIR}
source ${VENV_DIR}/bin/activate
pip install --upgrade pip
pip install pyscaffold
cd ${TMP_DIR} && \
putup ${PKGX} --no-skeleton --tox &&
putup ${PKGY} --namespace ${NS} --no-skeleton --tox && \
putup ${PKGZ} --namespace ${NS} --no-skeleton --tox
# tree ${PKGX}
# tree ${PKGY}
sed -i.bak s/"# install_requires = numpy; scipy"/"install_requires = ${NS}.${PKGY}"/g ${PKGX}/setup.cfg
sed -i.bak s/"# install_requires = numpy; scipy"/"install_requires = ${NS}.${PKGZ}"/g ${PKGY}/setup.cfg
sed -i.bak s/"name = ${PKGY}"/"name = ${NS}.${PKGY}"/g ${PKGY}/setup.cfg
sed -i.bak s/"name = ${PKGZ}"/"name = ${NS}.${PKGZ}"/g ${PKGZ}/setup.cfg
cat <<EOF > constraints.txt
-e file://${TMP_DIR}/${PKGX}#egg=${PKGX}
-e file://${TMP_DIR}/${PKGY}#egg=${NS}.${PKGY}
-e file://${TMP_DIR}/${PKGZ}#egg=${NS}.${PKGZ}
EOF
cat <<EOF > requirements.txt
${PKGX}
EOF
pip install -r requirements.txt -c constraints.txt
python -c "import ${PKGX}"
cat <<EOF >> ${PKGX}/src/${PKGX}/__init__.py
import ${NS}.${PKGY} as y
print(y)
EOF
python -c "import ${PKGX}"
cat <<EOF >> ${PKGY}/src/${NS}/${PKGY}/__init__.py
import ${NS}.${PKGZ} as z
print(z)
EOF
cat <<EOF >> ${PKGZ}/src/${NS}/${PKGZ}/__init__.py
raise NotImplementedError("It worked!")
EOF
python -c "import ${PKGX}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment