-
-
Save jtibbertsma/3a1d2cdae03c5f030e466a9e6711dee9 to your computer and use it in GitHub Desktop.
Launch a Python repl with whatever libraries you want
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # p – launch an IPython REPL under uvx | |
| # p → <default version> + ipython | |
| # p sympy numpy → <default version> + ipython + sympy + numpy | |
| # p -v 3.12 pandas → 3.12 + ipython + pandas | |
| # p --version=3.14a1t → 3.14a1t + ipython | |
| p() { | |
| local python_version="3.13t" # default when user doesn't specify one | |
| local with_flags=() | |
| # -------- parse options -------- | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| -v|--version) python_version="$2"; shift 2 ;; | |
| --version=*) python_version="${1#*=}"; shift ;; | |
| --) shift; break ;; # stop option parsing | |
| -*) | |
| printf 'p: unknown option %s\n' "$1" >&2 | |
| return 1 | |
| ;; | |
| *) with_flags+=( --with "$1" ); shift ;; | |
| esac | |
| done | |
| # any leftover args (after “--”) are packages, too | |
| for pkg in "$@"; do with_flags+=( --with "$pkg" ); done | |
| # -------- launch IPython -------- | |
| uvx --python "$python_version" -q \ | |
| --with ipython "${with_flags[@]}" \ | |
| ipython --no-banner --no-confirm-exit | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment