Skip to content

ANaka/poetry-monorepo-template

Repository files navigation

poetry-monorepo-template

A template with some preferences for a poetry monorepo.

Installation

Set up poetry and pyenv

Install Pyenv (macOS and Linux):

curl https://pyenv.run | bash

Follow the instructions to add the following to the end of your shell configuration (~/.zshrc or ~/.bashrc):

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Restart your terminal.

Install Python 3.10 and set as local default:

pyenv install 3.10
pyenv local 3.10

Install Poetry (macOS and Linux)

curl -sSL https://install.python-poetry.org | python -

Follow the instructions to add .local/bin to your path, or just add the following to the end of your shell configuration (~/.zshrc or ~/.bashrc) (make sure to add the full path to your home directory):

export PATH="$HOME/.local/bin:$PATH"

Restart terminal or run

source ~/.bashrc
# or source ~/.zshrc depending on your shell

Check poetry version - should show 1.2.0 or higher

poetry --version

Clone repo

# Clone monorepo to your machine
git clone <repo-url>

# Change into monorepo directory
cd <repo-name>

# Install base package (just for pre-commit hooks)
poetry install

# Install pre-commit hooks
poetry run pre-commit install

Git LFS

Git LFS to store large files in the repo. To install Git LFS, follow the instructions for your OS:

# linux:
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs

# homebrew:
brew install git-lfs

# initialize git lfs
git lfs install

.gitattributes file should take care of the rest.

Installing a subpackage

# Change into package directory
cd projects/test_project # for example

# Set python version
poetry env use 3.11  # for example

# Create virtual env and install dependencies
poetry install # automatically does editable install of current package

# Inspect installed packages and see destination of virtualenv
poetry show -v

Running scripts in poetry

Two options:

  • use poetry run e.g. poetry run python <script.py>
  • use poetry shell to enter virtualenv and run scripts from there

running jupyter kernels in VSCode

Update your VSCode setting python.venvPath to include your poetry virtualenvs path e.g. ~/.cache/pypoetry/virtualenvs. You can find this path by running poetry env info in your terminal.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages