pyproject.toml 文件可以很简单:[tool.poetry]名称 = '东西'版本 = '1.2.3'[tool.poetry.dependencies]蟒蛇 = '^3.6'SomeLibrary = '~2.2'[构建系统]要求 = ['诗歌核心~=1.0']构建后端 = 'poetry.core.masonry.api'参考文献:https://python-poetry.org/docs/pyproject/立>https://python-poetry.org/docs/dependency-specification/Pip supports the pyproject.toml file but so far all practical usage of the new schema requires a 3rd party tool that auto-generates these files (e.g., poetry and pip). Unlike setup.py which is already human-writeable, pyproject.toml is not (yet).From setuptools docs,[build-system]requires = [ "setuptools >= 40.9.0", "wheel",]build-backend = "setuptools.build_meta"However, this file does not include package dependencies (as outlined in PEP 621). Pip does support installing packages using pyproject.toml but nowhere does pep specify how to write package dependencies in pyproject.toml for the official build system setuptools.How do I write package dependencies in pyproject.toml?Related StackOverflow Questions:How to init the pyproject.toml fileThis question asks for a method to auto-generate pyproject.toml, my question differ because I ask for a human-written pyproject.toml. 解决方案 PEP 621December 2020There is a standard called PEP621 that specifies how a project's metadata, including dependencies, should be laid out in the pyproject.toml file.January 2021pdm seems to have added support for the PEP 621 notation.May 2021More build back-ends have added support for PEP 621, for example:pdmflittrampolimensconsprobably more...The pyproject.toml file is "human-writable" (as well as setup.cfg). I will give an answer here for setuptools and for poetry.But first, it is important to know that in this context setuptools and poetry behave as what are called build back-ends, and there are multiple such back-ends available today, setuptools is just one of them. Other build back-ends include flit, pymsbuild, pdm, and more. Some of them expect their configuration (including dependencies) to be written in pyproject.toml, some expect it in another file.setuptoolsAs of today (October 2020), setuptools does not support writing its configuration in pyproject.toml. You still have to either write a setup.py, or a setup.cfg, or a combination of both.My recommendation is to write as much as possible in setup.cfg, and the setup.py can be as short as:import setuptoolssetuptools.setup()Such a setup.cfg could look like this:[metadata]name = Thingversion = 1.2.3[options]install_requires = SomeLibrary ~= 2.2packages = find:References about the dependencies specifically:https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.htmlhttps://www.python.org/dev/peps/pep-0508/https://www.python.org/dev/peps/pep-0440/As an aside, note that in some cases it is possible to omit the setup.py file entirely, one of the conditions is that the setup.cfg file and a pyproject.toml file are present and contain all the necessary information. Here is an example of pyproject.toml that works well for a setuptools build backend:[build-system]build-backend = 'setuptools.build_meta'requires = [ 'setuptools >= 43.0.0',]Finally, there are plans from the setuptools maintainers, to allow writing the configuration in pyproject.toml (instead of setup.cfg or setup.py), but we are not there yet (October 2020).poetryIn poetry everything is defined in pyproject.toml.This file can be hand-written. As far as I can tell, there is no strict need to ever explicitly install poetry itself (commands such as pip install and pip wheel can get you far enough).The pyproject.toml file can be as simple as:[tool.poetry]name = 'Thing'version = '1.2.3'[tool.poetry.dependencies]python = '^3.6'SomeLibrary = '~2.2'[build-system]requires = ['poetry-core~=1.0']build-backend = 'poetry.core.masonry.api'References:https://python-poetry.org/docs/pyproject/https://python-poetry.org/docs/dependency-specification/ 这篇关于如何编写一个可以安装包的最小工作 pyproject.toml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-29 14:44