Poetry reached 1.0.0 at the end of last year on 12/12/2019, so I tried it.
Poetry is a packaging and dependency management tool for Python.
As a similar tool There are setuptools and Pipenv, but Poetry can cover both functions with this one.
** I'm attracted to the fact that "one toml file is all you need" **. Or rather, I thought it was ** wonderful **.
poetry v1.0.5 (latest as of May 11, 2020)
https://python-poetry.org/docs/basic-usage/ https://python-poetry.org/docs/cli/#new
$ poetry new <project name>
After execution, the following folders will be created.
<project name>
├── pyproject.toml
├── README.rst
├── poetry_demo
│ └── __init__.py
└── tests
├── __init__.py
└── test_poetry_demo.py
The pyproject.toml contained in the created folder is the poetry configuration file.
It is a file that replaces setup.py / setup.cfg / Pipfile, and the contents written in each file can be described in pyproject.toml.
If you look it up, it will be replaced, so if you are interested, please see the link on the official page.
https://python-poetry.org/docs/pyproject/
pyproject.tml
[tool.poetry]
name = "<project name>"
version = "0.1.0"
description = ""
authors = ["Sébastien Eustace <[email protected]>"]
[tool.poetry.dependencies]
python = "*"
[tool.poetry.dev-dependencies]
pytest = "^3.4"
https://python-poetry.org/docs/cli/#add
#Add dependent library
$ poetry add requests
#Addition of dependent libraries for development
$ poetry add --dev requests
Of course you can also specify the version. It doesn't seem to be much different from requirements.txt / setup.py / Pipfile.
https://python-poetry.org/docs/dependency-specification/
https://python-poetry.org/docs/cli/#install
$ poetry install
https://python-poetry.org/docs/cli/#run https://python-poetry.org/docs/cli/#shell
#Run in a single shot
$ poetry run python -m pip list
#Run in shell
$ poetry shell
It seems that you can do something like npm-scripts by specifying the Python module you want to execute in pyproject.toml.
pyproject.tml
[tool.poetry.scripts]
my-script = "my_module:main"
$ poetry run my-script
https://python-poetry.org/docs/cli/#build
$ poetry build
By default, both sdist / wheel are created.
You can use either one with the --format option.
https://python-poetry.org/docs/cli/#export
$ poetry export -f requirements.txt > requirements.txt
It seems that v1.0.2 only supports the format of requirements.txt.
PyCharm (2019.03) recognized pyproject.toml and detected the virtual environment.
Visual Studio Code doesn't recognize it automatically.
It's a hassle, but either of the following is required.
settings.json.venv folder that automatically recognizes it (* I personally prefer this)https://github.com/microsoft/vscode-python/issues/8372#issuecomment-549924849
settings.jsonThis is an example on Mac.
settings.json
{
"python.venvPath": "~/Library/Caches/pypoetry/virtualenvs"
}
.venv folder#Delete the Python environment that was created once
$ poetry env list
$ poetry env remove <Environment name>
# .Change settings to save in venv--> poetry.Output to toml.
$ poetry config virutalenv.local true --local
#Create virtual environment--> .Output to the venv folder.
$ poetry install
After that, if you reload the Python Interpreter settings of Visual Studio Code and look at it, you can select the .venv folder.