python new workflow with pyproject.toml with poetry
Newer python development workflow use pyproject.toml. To get started let's install poetry.
pip install poetry
Then we create a project with the modern project settings.
poetry new my-python-app
And it creates this
my-python-app/
├── pyproject.toml
├── README.md
├── src/my-python-app # Source code
│ └── __init__.py
├── tests/ # Tests (Automatically created!)
│ └── __init__.py
And to add dependencies, run the followings
poetry add --group dev pytest pytest-cov
To run tests
poetry run pytest
To package your app, run
poetry build
To remove dependencies
poetry remove --group dev pytest
To create a different group, we can use
poetry add --group linting black flake8
And then run black to format your python code
poetry run black src
To install specific dependencies
# Install main + dev + linting
poetry install --with linting
# Install ONLY main (no dev, no linting)
poetry install --only main
To verifying your projects
# Show all installed packages
poetry show
# Show only dev dependencies
poetry show --with dev
# Check dependency tree
poetry show --tree
Comments