Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blooalien/0168dce1c95005c492c8e6bf5df98727 to your computer and use it in GitHub Desktop.
Save blooalien/0168dce1c95005c492c8e6bf5df98727 to your computer and use it in GitHub Desktop.
Python Poetry Cheatsheet

Create a new project

poetry new <project-name>

Add a new lib

potry add <library>

Remove a lib

poetry remove <library>

Update a lib

poetry update <library>

Get venv path

poetry run which python

Run app

poetry run python app.py

Run tests

poetry run python -m unittest discover

Show dependencies

poetry show

Create script

1 - Edit pyproject.toml:

[tool.poetry.scripts]
test = 'scripts:test'

2 - Create a scripts.py file on the root directory of your project:

import subprocess

def test():
    """
    Run all unittests. Equivalent to:
    `poetry run python -u -m unittest discover`
    """
    subprocess.run(
        ['python', '-u', '-m', 'unittest', 'discover']
    )

3 - Run script:

poetry run test

Disable virtual environment creation

poetry config virtualenvs.create false

List configuratiom

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