Disclaimer: This is a work in progress and we do not have prebuilt wheels for google libs and psycopg2 so there is a bit of extra work involved for now, especially on ARM hardware.
Poetry brings with it lots of benefits for deterministic deploys, etc. For now, we're only leveraging it for local development, but we may in the future update our dockerfile to leverage it therein.
We will still run dependencies (postgres, redis, etc.) locally with docker compose.
You will need to have the following installed. Be sure to follow prompts and put appropriate things on your PATH and in your .zshrc/.zprofile., brew, pyenv, and the appropriate python version (3.7.9 at time of writing) via pyenv installed if you don't already:
curl https://pyenv.run | bashAppropriate python version via Pyenv (3.7.9 at time of writing)
pyenv install 3.7.9It may not be possible to install the python version above.
pyenv install 3.7.12to check installed version of python through pyenv run;
pyenv versionsBefore continuing, it is necessary to ensure your python version is correct and use pyenv. Run the following commands in the root of your directory.
which pythonThis will check if you are running pyenv; you should see /Users/<name>/.pyenv/shims/python
python --versionThis will check the version of python you are running. You should see python set to 3.7.9 or 3.7.12, respectively; if not, set to one of the two versions. You need to run one of the following commands.
pyenv local 3.7.12
pyenv local 3.7.9curl -sSL https://install.python-poetry.org | python3 -if the install above does't work, or if you just want more information about poetry you can visit [https://python-poetry.org/docs/]
Tell poetry to honor your pyenv version:
poetry config virtualenvs.prefer-active-python trueWhen using the appropriate version of python you can run the following command which will create a virtual env via poetry for you.
poetry install(Optional) To get into a shell for this virtual environment, just run:
poetry shellOnce your poetry environment is all set up, you can set your IDE's python interpreter to the virtual environment that Poetry created. Instructions will vary per IDE.
To run postgres and redis, run the following separately:
docker-compose up -d redis postgres
⚠️ NEVER MANUALLY CHANGE poetry.lock, and try to avoid manually changingtool.poetrysections in pyproject.toml To update, remove and install dependencies, use the poetry CLI add and remove If it is a development-only dependency, ensure you use--dev!
We have pre-commit hooks which execute inside of the poetry environment for consistency. If you'd like to enable them, just run:
pre-commit installIf for any reason you run into issues with these that you can't sort out, getting around them is as easy as:
pre-commit uninstallSince we don't have prebuilt wheels, you'll have a few extra steps to get up and running.
Ensure the following environment variables are set (~/.zshrc probably):
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1Some of the google libs require a rust compiler.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shPsycopg2 requires some other host dependencies:
brew install postgresql
brew install openssl
brew link opensslAs always, follow any prompts/instructions from the output of those commands above.
Once of all that is done (and your active shell reflects the changes), you should be all ready poetry install!
In case of an emergency and you need to start fresh, follow these steps
deactivatePOETRY_LOCATION=`poetry env info -p`
echo "Poetry is $POETRY_LOCATION"
rm -rf "$POETRY_LOCATION"poetry shellpoetry install