Introduction to Poetry

shinunjune·2023년 1월 25일
0

Poetry's advantage

  1. Easy to manage packages for eash projects. (in a deterministic way)
  2. Easy to build and package projects.
  3. Easy to publish work.
  4. Easy to check dependencies.

Project init

  • poetry init starts setting up Dependency(for production) interativly.
  • setting saved on pyproject.toml

    Able to set Development dependency seperatly.

    pyproject.toml

Poetry install

  • Activate virtual environment by poetry shell and poetry install to install libraries.
  • To add packages, poetry add <package name> installs package and add dependency in pyproject.tome automatically.

poetry.lock

After installing packages with pyproject.toml, poetry writes packages with exact version on poetry.lock. With poetry.lock's presence, poetry installs packages of the exact version when the lock is generated, preventing unexpected changes in dependencies. It is convenient to share poetry.lock to sync dependencies with project co-workers!

VScode

Since poetry builds venv at home directory not in the project, vscode interpreter can not detect the venv python.
Thus, command
poetry config virtualenvs.in-project true
poetry config virtualenvs.path "./.venv"
And by re-installing venv with poetry install will creat .venv at the root directory (in-project).

profile
HAPPY the cat

0개의 댓글