Python's Poetry

Prerequisites

install pip tools

py -m pip install pip-tools

# upgrade pip
pip install --upgrade pip

install pipx

py -m pip install --user pipx

# adds executables to global path so you can call them without py -m ...
py -m pipx ensurepath

install poetry through pipx

py -m pipx install poetry

Usage

Init a project & add dependencies

Go to your project’s folder and set up poetry

# this creates a `.toml` file with configuration
poetry init

# if problems on init
poetry config virtualenvs.use-poetry-python true

add dependencies

poetry add {package_name}

Virtual envs

create virtual env for the project

# you need to have a README.md on the project's root
poetry install

enter into virtual env

poetry env activate

# activate or create new virtualenv for current project
poetry env use {other_env}

see active env

poetry env info

Build and run

build project

poetry build

install and run a project through poetry

# this works through pyproject.toml's conf
poetry install

there you need something like this, where this ‘hello’ is the one you use to run the project

[tool.poetry.scripts]
hello = "PromptEngineering:main"

execute

poetry run hello

Use poetry env from Visual Studio

Do the following & copy the result

poetry env info --path

Click on python’s version button > Agregar entorno… > Entorno existente > Entorno * > Personalizado

Pegar allí la ruta previa que has copiado y seleccionar el correspondiente.
Añadirle descripción (que será el nombre para identificarlo)
Seleccionar ese y darle a Run (F5)
Con eso ya VS debería coger y funcionar con las dependencias instaladas por poetry

Install script globally

# only the first time we install something 
pipx ensurepath
# close and open terminal again

# build, install and run to make sure it works
poetry build
poetry run
poetry install

# install localy with pipx
pipx install .

# now we're able to run it from anywhere
file-converter

in this case we invoke it as file-converter as the .toml declares it as such

[tool.poetry.scripts]
file-converter = "FileConverter:main"