Search code examples
bashshellvirtualenvpipenv

Run pipenv shell as part of a bash script


I created a bash script to scaffold boilerplates for several apps (React, Next.js, django, etc).

In part of my django_install() function, I run the following (reduced here):

mkdir "$app_name"
cd ./"$app_name" || exit 0
gh repo clone <my-repo-boilerplate> .
rm -rf .git
pipenv install
pipenv install --dev
exit 0

I would also like to execute pipenv shell and some commands that need to run inside that virtual environment, as my boilerplate has some custom scripts that I'd like to run to automatise the script completely.

I understand I cannot just run pipenv shell or python manage.py [etc...] in my bash script.

How could I achieve it?


Solution

  • I think you can use pipenv run for that. E.g.:

    pipenv run python manage.py [etc...]
    

    Which will run python manage.py within the virtual environment created by pipenv.

    https://pipenv.pypa.io/en/latest/cli.html#run