-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinder_poetry_to_requirements.sh
executable file
·51 lines (40 loc) · 1.4 KB
/
binder_poetry_to_requirements.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/zsh
# export poetry dependencies to requirements.txt
# binderhub requires
echo "This script will export poetry dependencies into requirements.txt used in binder."
echo "A new temporary virtual environment will be created and subsequently deleted. "
VENV_DIR='./.venv-poetry-to-requirements'
POETRY_FILE="./pyproject.toml"
REQ_FILE='./requirements.txt'
if [[ ! -f $POETRY_FILE ]]; then
echo "-- $POETRY_FILE not found. Exited."
exit 1;
fi
if [[ -f $REQ_FILE ]]; then
printf "-- $REQ_FILE exist. Replace? (y/n): "
read x
[[ $x != 'y' ]] && echo "Exited." && exit 0
rm -rf $REQ_FILE
fi
if [[ -d $VENV_DIR ]]; then
printf "-- Virtual environment $VENV_DIR already exists. Replace(y/n)? "
read x
[[ $x != 'y' ]] && echo "Exited." && exit 0
rm -rf $VENV_DIR
fi
echo "++ Building new temporary virtual env at $VENV_DIR... "
python3 -m venv $VENV_DIR
echo "++ Activating virtual env..."
source $VENV_DIR/bin/activate
which python3
echo "++ Installing dependencies..."
pip install --upgrade pip
pip install poetry
poetry install --without dev # note no extras are installed. (e.g. apple dependencies.)
echo "++ Exporting poetry dependencies to $REQ_FILE..."
poetry export --without-hashes --without dev --format=requirements.txt > $REQ_FILE
echo "++ Cleaning up..."
rm -rf $VENV_DIR
echo "++ Done."
echo "++ To test on binder, please commit and push $REQ_FILE so binder docker container is updated."
exit 0