Skip to content

Instantly share code, notes, and snippets.

@Jim-Holmstroem
Last active December 10, 2020 22:18
Show Gist options
  • Save Jim-Holmstroem/f191905eb2e52ecad4858f8323548fce to your computer and use it in GitHub Desktop.
Save Jim-Holmstroem/f191905eb2e52ecad4858f8323548fce to your computer and use it in GitHub Desktop.
poetry entrypoint to be able to just run a command within the poetry shell (like pytest in CI or something similar). Makes `poetry shell` actually behave like a shell and can be used as ENTRYPOINT in a docker container and it wil behave like a bash entrypoint
#!/usr/bin/env bash
COMMAND=$@
set -x
command -v poetry > /dev/null || (echo missing poetry && exit 3)
if [[ -v ${COMMAND} ]]; then
poetry shell
else
bash -c ". .venv/bin/activate && $(printf ' %q' "$@")"
fi
@Jim-Holmstroem
Copy link
Author

NOTE. Just realized that you can use poetry run for the case you use a command
and for docker you can even use

ENTRYPOINT [ "/usr/bin/poetry", "run", "bash", "-c" ]
CMD [ "bash" ]

to get it to behave like poetry_entrypoint.sh above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment