Python Poetry for a Noob - Getting started

🍉 ⋆ 🍫 🎀 𝕊𝕦𝕞𝕞𝕒𝕣𝕪 🎀 🍫 ⋆ 🍉
Managing packages and dependencies in Python can be overwhelming and resource intensive. Poetry will help with starting new projects, maintaining existing ones and provide centralized dependency management. Like most Python projects, it relies on external packages. The maintenance work falls on the developer to make sure each version of each package is updated and working after each update. By leveraging Poetry, a dependency manager, we can specify, install and resolve external packages in one source location known as out project file. This way we can ensure we always have the right dependencies,lol versions and configurations, and dependencies of dependencies, with the added value of central management.
🍉 ⋆ 🍫 🎀 𝔽𝕚𝕝𝕖𝕤 𝕒𝕟𝕕 𝕄𝕠𝕣𝕖 𝔽𝕚𝕝𝕖𝕤 🎀 🍫 ⋆ 🍉
Typically with a python project we have to track setup.py, requirements.txt, setup.cfg, MANIFEST.in and a pipfile. Let's take a look at them below.
setup.py - Is a python file that indicates the modules/packages you are about to install. Simply calling "pip install setup.py" and our modules will be installed.
requirements.txt - is a file that lists all dependencies for a specific Python project. It can also specify specific versions.
setup.cfg - Contains options for the setup.py
MANIFEST.in - Specifies metadata for accompanying files
Pipfile - Dedicated file for project dependencies
🍉 ⋆ 🍫 🎀 𝕎𝕙𝕒𝕥 𝕡𝕠𝕖𝕥𝕣𝕪 𝕕𝕠𝕖𝕤 𝕗𝕠𝕣 𝕞𝕖? 🎀 🍫 ⋆ 🍉
After implementing Poetry, you will have 2 new files.
pyproject.toml - List the details of packages added to the poetry tree
poetry.lock - Basic overview packages in the poetry tree
🍉 ⋆ 🍫 🎀 ℂ𝕣𝕖𝕒𝕥𝕚𝕟𝕘 𝕒 𝕟𝕖𝕨 𝕡𝕠𝕖𝕥𝕣𝕪 𝕡𝕒𝕔𝕜𝕒𝕘𝕖 🎀 🍫 ⋆ 🍉
Creating our first poetry package is very simple.
$poetry new dolphin-poetry-project
A folder will be created "rp-poetry". Poetry will normalize packages for you automatically. The Poetry file structure is formatted as below.
dolphin-poetry-project
├── dolphin-poetry-project
│ └── __init__.py
├── tests/
│ ├── __init__.py
│ └── test_dolphin-poetry-project.py

├── README.md
└── pyproject.toml
A toml and a lock file will be created to track all our packages, dependencies and version. See examples below.
------------------------------------------------------------------------------------------------------------
🍉 ⋆ 🍫 🎀pyproject.toml - This file will display our packages
[tool.poetry]
name = "dolphin-poetry-project"
version = "0.1.5"
description = "Dolphin test project"
authors = ["Dolphin dolphin@example.com"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
pytest = "^4.6"
invoke = "^1.8"
pycrypto = "^4.3"
strings = "^4.1"
[tool.strings]
remove-empty-directories = true
[build-system]
requires = ["poetry=0.12"]
build-backend = "poetry.masonry.api"
[tool.poetry.scripts]
run = "wsgi:main"
[tool.poetry.urls]
issues = "github.com/hackersandslackers..."
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
🍉 ⋆ 🍫 🎀poetry-project/poetry.lock
[[package]]name = "pytest"
version = "0.17.2"
description = "Python graph [network] package"
category = "dev"
optional = false
python-versions = "*"[[package]]
name = "attrs"
version = "20.3.0"
description = ""
category = "dev"
optional = false
python-versions = "=2.7, !
[package.dependencies]
pytesting = "=1.1.0"
[package.extras]
[[package]]name = "invoke"
version = "0.17.2"
description = "Python graph [network] package"
category = "dev"
optional = false
python-versions = "*"[[package]]
name = "attrs"
version = "20.3.0"
description = ""
category = "dev"
optional = false
[package.dependencies]
[package.extras]
------------------------------------------------------------------------------------------------------------
🍉 ⋆ 🍫 🎀 The workflow
This can be allot to take in, so lets look at the workflow.
1. Install Poetry
2. Create a Poetry package
3. Add a package
4. Update the packages
5. Track/list the packages
6. Build the package
7. Install the package
🍉 ⋆ 🍫 🎀 Workflow specifics
1. Installing on linux
A. curl -sSL raw.githubusercontent.com/pyt... | python3
B. Check version with - poetry --version
C. Set environment variable - export PATH="$HOME/.poetry/bin:${PATH}"
2. Create a Poetry package
poetry new mypoetryproject
3. Adding packages
poetry add "package name"
4. Update the packages
Poetry update
5. Track/list the packages
poetry show --tree
6. Build the packages
Poetry build
7. Publishing Packages
poetry publish
8. Publishing Packages
poetry publish
References:
python-poetry.org/
github.com/python-poetry/poetry
python-poetry.org/docs/
hackersandslackers.com/python...
Music:- ASHUTOSH - Chile
Watch:- • ASHUTOSH - Chile
www.ashutoshmusic.com/music

Пікірлер: 2

  • @yashwal6789
    @yashwal6789 Жыл бұрын

    Informative video. Clarity could have been improved .

  • @HopliteSecurity

    @HopliteSecurity

    Жыл бұрын

    Thank you for the feedback :)