1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- alias py='python'
- alias pyfind='find . -name "*.py"'
- function pyclean() {
- ZSH_PYCLEAN_PLACES=${*:-'.'}
- find ${ZSH_PYCLEAN_PLACES} -type f -name "*.py[co]" -delete
- find ${ZSH_PYCLEAN_PLACES} -type d -name "__pycache__" -delete
- find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".mypy_cache" -exec rm -r "{}" +
- find ${ZSH_PYCLEAN_PLACES} -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
- }
- function pyuserpaths() {
- local targets=("python2" "python3")
-
-
- local interps=()
- for target in $targets; do
- [ `command -v $target` ] && interps+=($target)
- done
-
- local user_base="${HOME}/.local"
- [ $PYTHONUSERBASE ] && user_base=$PYTHONUSERBASE
-
-
-
- for interp in $interps; do
-
- local ver=`$interp -V 2>&1`
- ver=`echo ${ver:7} | cut -d '.' -f 1,2`
-
- local site_pkgs="${user_base}/lib/python${ver}/site-packages"
- [[ -d $site_pkgs && ! $PYTHONPATH =~ $site_pkgs ]] && export PYTHONPATH=${site_pkgs}:$PYTHONPATH
- done
- }
- alias pygrep='grep -nr --include="*.py"'
- alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
- alias pyserver="python -m http.server"
- function vrun() {
- local name="${1:-venv}"
- local venvpath="${name:P}"
- if [[ ! -d "$venvpath" ]]; then
- echo >&2 "Error: no such venv in current directory: $name"
- return 1
- fi
- if [[ ! -f "${venvpath}/bin/activate" ]]; then
- echo >&2 "Error: '${name}' is not a proper virtual environment"
- return 1
- fi
- . "${venvpath}/bin/activate" || return $?
- echo "Activated virtual environment ${name}"
- }
- function mkv() {
- local name="${1:-venv}"
- local venvpath="${name:P}"
- python3 -m venv "${name}" || return
- echo >&2 "Created venv in '${venvpath}'"
- vrun "${name}"
- }
|