pulumi/sdk/python/dist/pulumi-resource-pulumi-python
Justin Van Patten b77ec919d4
Install and use dependencies automatically for new Python projects (#4775)
Automatically create a virtual environment and install dependencies in it with `pulumi new` and `pulumi policy new` for Python templates.

This will save a new `virtualenv` runtime option in `Pulumi.yaml` (`PulumiPolicy.yaml` for policy packs):

```yaml
runtime:
  name: python
  options:
    virtualenv: venv
```

`virtualenv` is the path to a virtual environment that Pulumi will use when running `python` commands.

Existing projects are unaffected and can opt-in to using this by setting `virtualenv`, otherwise, they'll continue to work as-is.
2020-06-09 16:42:53 -07:00

32 lines
990 B
Bash
Executable file

#!/bin/sh
if [ -n "${PULUMI_RUNTIME_VIRTUALENV:-}" ] ; then
# Remove trailing slash.
PULUMI_RUNTIME_VIRTUALENV=${PULUMI_RUNTIME_VIRTUALENV%/}
# Make the path absolute (if not already).
case $PULUMI_RUNTIME_VIRTUALENV in
/*) : ;;
*) PULUMI_RUNTIME_VIRTUALENV=$PWD/$PULUMI_RUNTIME_VIRTUALENV;;
esac
# If python exists in the virtual environment, set PATH and run it.
if [ -f "$PULUMI_RUNTIME_VIRTUALENV/bin/python" ]; then
# Update PATH and unset PYTHONHOME.
PATH="$PULUMI_RUNTIME_VIRTUALENV/bin:$PATH"
export PATH
if [ -n "${PYTHONHOME:-}" ] ; then
unset PYTHONHOME
fi
# Run python from the virtual environment.
"$PULUMI_RUNTIME_VIRTUALENV/bin/python" -u -m pulumi.dynamic $@
else
echo "\"$PULUMI_RUNTIME_VIRTUALENV\" doesn't appear to be a virtual environment"
exit 1
fi
else
# Otherwise, just run python3.
python3 -u -m pulumi.dynamic $@
fi