Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Poetry, the Package Manager
Search
fx-kirin
January 07, 2020
Programming
590
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Poetry, the Package Manager
fx-kirin
January 07, 2020
More Decks by fx-kirin
See All by fx-kirin
Jupyter add Timestamp to Default Name
fxkirin
0
490
Call Python/Numpy Function within Metatrader 4
fxkirin
0
1.9k
Other Decks in Programming
See All in Programming
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
370
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.8k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
280
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
170
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
120
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
660
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
940
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
今さら聞けない .NET CLI
htkym
0
190
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
450
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
Featured
See All Featured
The agentic SEO stack - context over prompts
schlessera
0
860
Side Projects
sachag
455
43k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
200
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
370
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
210
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Speed Design
sergeychernyshev
33
2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
660
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
470
Transcript
Osaka Python User Group #2 2020-01-17 1/28
About me Name : Yoshiaki Ono Job : Self-employed Python
Programmer Twitter : fx_kirin 2/28
What is OPUG Share programming knowledge and help each other.
3/28
Poetry The Package Manager Yoshiaki Ono 4/28
Agenda Poetry hands on Introduction of python package management Packaging
history Manual way of packaging Poetry is great 5/28
Before the talk Just give it a try. 6/28
Install Poetry Linux / Mac Users Windows Users Anaconda(Not recommended)
curl -sSL | python https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py (Invoke-WebRequest -Uri -UseBasicParsing).Content | python https://raw.githubusercontent.com/python-poetry/poetry/master/get- poetry.py conda install -c conda-forge poetry 7/28
Create new package $ poetry new my-package Created package my_package
in my-package my-package ├── my_package │ └── __init__.py ├── pyproject.toml ├── README.rst └── tests ├── __init__.py └── test_my_package.py 8/28
Add dependencies $ cd my-package $ poetry add requests Using
version ^2.22.0 for requests Updating dependencies Resolving dependencies... (2.8s) Writing lock file Package operations: 5 installs, 0 updates, 0 removals - Installing certifi (2019.11.28) - Installing chardet (3.0.4) - Installing idna (2.8) - Installing urllib3 (1.25.7) - Installing requests (2.22.0) 9/28
Implement the module ./my_package/__init__.py 01 __version__ = "0.1.0" 02 03
import requests 04 05 06 def foo(): 07 requests.get("https://www.google.com") 08 print("Log from my_package") 10/28
Build the package $ poetry build Building my-package (0.1.0) -
Building sdist - Built my-package-0.1.0.tar.gz - Building wheel - Built my_package-0.1.0-py3-none-any.whl 11/28
Install to global python $ cd dist $ pip install
my_package-0.1.0-py3-none-any.whl Requirement already satisfied: my-package==0.1.0 from file:///tmp/my-package/dist/my_pac Requirement already satisfied: logzero<2.0.0,>=1.5.0 in /home/zenbook/.pyenv/versions/mi Requirement already satisfied: requests<3.0.0,>=2.22.0 in /home/zenbook/.pyenv/versions/ Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/zenbook/.pyenv/versions/mi Requirement already satisfied: idna<2.9,>=2.5 in /home/zenbook/.pyenv/versions/miniconda Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/zenbook/ Requirement already satisfied: certifi>=2017.4.17 in /home/zenbook/.pyenv/versions/minic 12/28
Test the package $ ipython Python 3.6.7 |Anaconda, Inc.| (default,
Oct 23 2018, 19:16:44) Type 'copyright', 'credits' or 'license' for more information IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import my_package In [2]: my_package.foo() Log from my_package 13/28
Upload to PyPI $ poetry publish Publishing my-package (0.1.0) to
PyPI Username: test Password: - Uploading my-package-0.1.0.tar.gz 100% ... 14/28
Super Easy! 15/28
Packaging 16/28
What it looks like in Python Module: a file containing
Python code Package: a directory of Python module Distribution: an archived module/package (tar, whl, zip) package_name ├── dist │ └── package_name-0.1.0.tar.gz ├── package_name │ └── __init__.py └── setup.py 17/28
Python's packaging history 2000: Distutils 2003: PyPI 2004: Setuptools 2007:
Virtualenv 2008: Pip 2011: Python Packaging Authority(PyPA) 2013: Wheel 2016: Pyproject.toml 2017: Pipenv 2018: Poetry 18/28
Python Packaging was so complicated. 19/28
PyPA packaging tutorial https://packaging.python.org/ 20/28
1. Manually create a project structure packaging_tutorial/ example_pkg/ __init__.py setup.py
LICENSE README.md 21/28
2. Manually write setup.py import setuptools with open("README.md", "r") as
fh: long_description = fh.read() setuptools.setup( name="example-pkg-your-username", version="0.0.1", author="Example Author", author_email="
[email protected]
", description="A small example package", long_description=long_description, ..., python_requires='>=3.6', ) 22/28
3. Build distribution with setuptools $ pip install setuptools wheel
$ python3 setup.py sdist bdist_wheel $ ls dist dist/ example_pkg-0.0.1-py3-none-any.whl example_pkg-0.0.1.tar.gz 23/28
4. Use tool called twine to upload $ pip install
twine $ python -m twine upload dist/* Uploading distributions... Enter your username: [your username] Enter your password: ... uploaded 24/28
Poetry does all of them. 25/28
setup.py generated by poetry 01 # -*- coding: utf-8 -*-
02 from setuptools import setup 03 04 packages = \ 05 ['my_package'] 06 07 package_data = \ 08 {'': ['*']} 09 10 install_requires = \ 11 ['requests>=2.22.0,<3.0.0'] 12 13 setup_kwargs = { 14 'name': 'my-package', 15 'version': '0.1.0', 16 'description': '', 17 'long_description': None, 26/28
What you can't do with Poetry C-Extension libraries. 27/28
Let's start using Poetry and make your life easier! 28/28