-
Notifications
You must be signed in to change notification settings - Fork 0
/
dust
executable file
·94 lines (88 loc) · 2.33 KB
/
dust
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/env sh
# POSIX-compliant script for setting up your shell
thisdir=$(realpath $(dirname $0))
DUSTDIR=${thisdir}/dustenv
PYENVDIR=${DUSTDIR}/pyenv
. ${DUSTDIR}/pyenv-source.sh
. ${DUSTDIR}/common.sh
# setup_pypackages() {
# export PYTHONPATH="$(pyenv prefix)/lib:$PYTHONPATH"
# }
# backup status of installed packages for later
# pypackages_before=$(ls -lR ${thisdir}/__pypackages__/ 2>/dev/null)
pyenv_before=$(ls -lR $(pyenv prefix)/lib/ 2>/dev/null)
# special command: add
if test "$1" = "add"
then
# setup_pypackages
pyenv exec pdm add --no-sync "${@:2}"
dust_sync
check_changes=0
elif test "$1" = "remove"
then
# setup_pypackages
pyenv exec pdm remove --no-sync "${@:2}"
dust_sync
check_changes=0
elif test "$1" = "update"
then
# setup_pypackages
pyenv exec pdm update --no-sync "${@:2}"
dust_sync
check_changes=0
elif test "$1" = "sync"
then
dust_sync "${@:2}"
check_changes=0
elif test "$1" = "pdm"
then
pyenv exec pdm "${@:2}"
dust_sync
check_changes=0
elif test "$1" = "exec"
then
pyenv exec "${@:2}"
check_changes=1
elif test "$1" = "shell"
then
shell=$(cat /proc/$PPID/comm)
# removing link (e.g. sh -> /usr/bin/bash)
shell=$(basename $(realpath $(which $shell)))
# shell_command=$(cat /proc/$PPID/cmdline)
# setup_pypackages $mode
if test "$shell" = "fish"
then
pyenv exec $shell -C "source ${DUSTDIR}/pyenv-source.fish $PYENVDIR"
elif test "$shell" = "bash"
then
# <() is not posix-compliant, need to use a named pipe here
pipe_name=temp_pipe.$$
mkfifo $pipe_name
echo "source ${DUSTDIR}/pyenv-source.sh" > $pipe_name & pyenv exec $shell --init-file $pipe_name
rm $pipe_name
else
echo "Sorry, we cannot spawn your shell: only fish and bash supported."
fi
else
# setup_pypackages
pyenv exec python "$@"
check_changes=1
fi
# check if some package was modified
if [ "$check_changes" = "1" ]
then
pyenv_after=$(ls -lR $(pyenv prefix)/lib/ 2>/dev/null)
if [ "$pyenv_after" != "$pyenv_before" ]; then
if ask_yn "DUST MESSAGE: Detected changes, do you want that we update requirements.txt and pyproject.toml? This will produce a very long and meaningless pyproject.toml! [y/n]"
then
dust_pip_export
dust_pdm_import
dust_pip_install
fi
fi
fi
if test $ERROR
then
echo "Some error happened! Have you run 'install.sh'?"
exit 1
fi