Things between Poetry, pip and pyproject.toml according to my own reviews.
TL;DR
- Projects only have
pyproject.toml
(Nosetup.py
)- Just use
pip >= 19.0
- Just use
pip >= 10.0
starts to support PEP 518pip >= 19.0
starts to support PEP 517
Why not setup.py
anymore?
Accroding to the "Rationale" section of PEP 518
:
Using an executable file to specify build requirements under distutils isn't an issue as distutils is part of Python's standard library. Having the build tool as part of Python means that a setup.py has no external dependency that a project maintainer needs to worry about to build a distribution of their project. There was no need to specify any dependency information as the only dependency is Python.
But when a project chooses to use setuptools, the use of an executable file like setup.py becomes an issue. You can't execute a setup.py file without knowing its dependencies, but currently there is no standard way to know what those dependencies are in an automated fashion without executing the setup.py file where that information is stored. It's a catch-22 of a file not being runnable without knowing its own contents which can't be known programmatically unless you run the file.
Why pyproject.toml
?
- Say goodbye to lots of
requirements.txt
files, you just needpyproject.toml
- Say goodbye to
setup.py
, you just needpyproject.toml
- No need to write the dependencies in both
requirements.txt
andsetup.py
. - Or parsing the
requirements.txt
insetup.py
.
- No need to write the dependencies in both
- There are some tools start to read their config from
pyproject.toml
Poetry
Pros
- It locks the dependency and generates
poetry.lock
file just likepipenv
- The reason why I use
poetry
instead ofpipenv
:- During my last job, we use
pipenv
at first. - One day, we encountered a strange bug which only showed on the production machine.
- It turns out the problem is
pipenv
didn't lock the dependencies properly. - We confirmed the bug is made by
pipenv
. - We just give Poetry a try.
- It fixed the problem.
- During my last job, we use
- Other reasons why you should consider not using
pipenv
in 2020 can be found in this blog post: Pipenv: promises a lot, delivers very little | Chris Warrick - Poetry is not the first package manager accepts
pyproject.toml
.- I use
flit
1.0 back in Apirl, 2018, which supportspyproject.toml
- And that's the time I know
pyproject.toml
flit
is still being developed and it's lastest version is 2.3.0 now.- But, Poetry has more features.
- I use
Cons
This project is young and still developing. So, like other young projects, lots of things are WIP:
- During the time I wrote this blog post. It hasn't support the
platforms
insetup.py
, but it does have theplatforms
metadata in the code. - Some documentations are not so clear, so you need to search GitHub issues and read lots of discussion to find the answer. And it might be changed in the future.
[tool.poetry.scripts]
inpyproject.toml
works likescripts
insetuptools
- while some people think it's a task runner.
[tool.poetry.plugins]
inpyproject.toml
works likeentry_point
insetuptools
- and some people ask "Then why you use the word
plugin
?"
- and some people ask "Then why you use the word
References
Share
Donation
如果覺得這篇文章對你有幫助, 除了留言讓我知道外, 或許也可以考慮請我喝杯咖啡, 不論金額多寡我都會非常感激且能鼓勵我繼續寫出對你有幫助的文章。
If this blog post happens to be helpful to you, besides of leaving a reply, you may consider buy me a cup of coffee to support me. It would help me write more articles helpful to you in the future and I would really appreciate it.
Related Posts
- pip install lxml fail in Mac
- percol - interactive pipe in shell
- No more requirements-test.txt for Flit or Poetry while using Tox running tests
- 嘗試在 Python 中做到 Golang fmt 的效果
- Y2021W50