File: dev-env.sh

package info (click to toggle)
asyncio-dgram 2.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 160 kB
  • sloc: python: 598; makefile: 59; sh: 32
file content (41 lines) | stat: -rwxr-xr-x 882 bytes parent folder | download
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
#!/usr/bin/env bash

cleanup() {
	[ -n "${bashrc}" ] && rm -f "${bashrc}"
}

trap cleanup HUP TERM EXIT

PYTHON=${PYTHON:-python3}

pyversion=$(${PYTHON} --version | awk '{print $2}')
topdir=$(cd "$(dirname "$0")"; pwd -P)
bashrc=$(TMPDIR=${topdir} mktemp .devrc-XXXXXX)
make=$(which gmake 2>/dev/null || which make)

if [ -n "${VIRTUAL_ENV}" ]; then
	virtualenv=${VIRTUAL_ENV}
else
	virtualenv=${topdir}/.venv-${pyversion}
fi

if [ ! -d "${virtualenv}" ]; then
	${PYTHON} -m venv "${virtualenv}" || exit 1
fi

# Instructions to run when entering new shell
cat > "${bashrc}" <<-EOF
	[ -f ~/.bashrc ] && source ~/.bashrc
	source "${virtualenv}"/bin/activate
EOF

# Enter developmet shell
if [ -z "$*" ]; then
	/usr/bin/env bash --rcfile "${bashrc}" -i
else
	source "${bashrc}"
	"$@"
fi

# vim: noet
# -*- indent-tabs-mode: t; tab-width: 8; sh-indentation: 8; sh-basic-offset: 8; -*-