[PYTHON] Recommendation of Poetry

Python packaging mechanism

--wheel: Python package format --Files containing Python code and shared libraries (* .whl) --If it depends on other packages, it is written in the metadata

pip install numpy

Semantic Versioning

https://semver.org/lang/ja/

Uses X.Y.Z format versioning

  1. Major version (X) if API changes are incompatible,
  2. If it is backward compatible and functionality is added, the minor version (Y),
  3. If you fix a bug with backward compatibility, increase the patch version (Z).
pip install "numpy==1.15"

--List the packages that depend on the file requirements.txt and install them all together.

pip install -r requirements.txt

Develop multiple projects

You cannot have multiple versions of a package installed on your system at the same time!


venv (virtualenv)

--I want to install a package for each project --Entered the standard from Python 3.3 --There was a package called virtualenv for Python 2.x

python3 -m venv path/to/new/venv  #Create venv
source path/to/new/venv/bin/activate  #activation

--Venv itself will be managed manually --Typically, create a venv directory directly under the project


pyproject.toml

--Official file format for Python project management - PEP(Python Enhancement Proposals) 518 --Integrate packaging settings setup.py, setup.cfg and list of dependent packages requirements.txt --Supported from pip 19.2 --You can pip install from pypoetry.toml without setup.py --You can create a namespace tool. $ {Toolname} for each tool and write your own settings. --You no longer have to create a separate configuration file for each tool


poetry

--A tool that manages projects based on pyproject.toml --poetry init will generate pyproject.toml ――Creates and manages venv without permission --poetry run [shell script] runs the script under venv --There is also an upload function to PyPI

[tool.poetry]
name = "hello"
version = "0.1.0"
description = "Hello Poetry!"

[tool.poetry.dependencies]
python = "^3.7"   #You can also write a version of Python itself (just check if it meets)
numpy = "1.14"    #I will write packages that depend on here

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Recommended Posts

Recommendation of Poetry
Types of recommendation systems
Recommendation of data analysis using MessagePack
Construction of recommendation system using word-of-mouth doc2vec
Poetry begins
poetry uninstall
Recommendation of Altair! Data visualization with Python
Recommendation optimization
Movie Recommendation utilizing collaborative filtering of Spark MLlib
Impressions of receiving LPIC-1. "Recommendation / Difficulty / Study time"
The story of moving from Pipenv to Poetry