dri*_*ols 5 python pip python-packaging python-poetry pyproject.toml
我有一个用诗歌创作的旧项目。诗歌创建的pyproject.toml如下:
\n[tool.poetry]\nname = "Dota2Learning"\nversion = "0.3.0"\ndescription = "Statistics and Machine Learning for your Dota2 Games."\nlicense = "MIT"\nreadme = "README.md"\nhomepage = "Coming soon..."\nrepository = "https://github.com/drigols/dota2learning/"\ndocumentation = "Coming soon..."\ninclude = ["CHANGELOG.md"]\nauthors = [\n "drigols <drigols.creative@gmail.com>",\n]\nmaintainers = [\n "drigols <drigols.creative@gmail.com>",\n]\nkeywords = [\n "dota2",\n "statistics",\n "machine Learning",\n "deep learning",\n]\n\n[tool.poetry.scripts]\ndota2learning = "dota2learning.cli.main:app"\n\n[tool.poetry.dependencies]\npython = "^3.10"\nrequests = "^2.27.1"\ntyper = {extras = ["all"], version = "^0.4.1"}\ninstall = "^1.3.5"\nSQLAlchemy = "^1.4.39"\nPyMySQL = "^1.0.2"\ncryptography = "^37.0.4"\npydantic = "^1.9.1"\nrich = "^12.5.1"\nfastapi = "^0.79.0"\nuvicorn = "^0.18.2"\n\n[tool.poetry.dev-dependencies]\nblack = {extras = ["jupyter"], version = "^22.3.0"}\npre-commit = "^2.19.0"\nflake8 = "^4.0.1"\nreorder-python-imports = "^3.1.0"\npyupgrade = "^2.34.0"\ncoverage = "^6.4.1"\n\n[tool.black]\nline-length = 79\ninclude = '\\.pyi?$' # All Python files\nexclude = '''\n/(\n \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | _build\n | buck-out\n | build\n | dist\n)/\n'''\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\n\n[tool.poetry.urls]\n"Bug Tracker" = "https://github.com/drigols/dota2learning/issues"\nRun Code Online (Sandbox Code Playgroud)\n如果运行“pip install”。它对我有用,但是,现在我想遵循没有诗歌的新方法来管理项目和依赖项。然后我创建了一个新的 pyproject.toml (手动):
\n[project]\nname = "Dota2Learning"\nversion = "2.0.0"\ndescription = "Statistics and Machine Learning for your Dota2 Games."\nlicense = "MIT"\nreadme = "README.md"\nhomepage = ""\nrequires-python = ">=3.10"\nrepository = "https://github.com/drigols/dota2learning/"\ndocumentation = ""\ninclude = ["CHANGELOG.md"]\nauthors = [\n "drigols <drigols.creative@gmail.com>",\n]\nmaintainers = [\n "drigols <drigols.creative@gmail.com>",\n]\nkeywords = [\n "dota2",\n "statistics",\n "machine Learning",\n "deep learning",\n]\n\ndependencies = [\n "requests>=2.27.1",\n "typer>=0.4.1",\n "SQLAlchemy>=1.4.39",\n "PyMySQL>=1.0.2",\n "cryptography>=37.0.4",\n "pydantic>=1.9.1",\n "rich>=12.5.1",\n "fastapi>=0.79.0",\n "uvicorn>=0.18.2",\n]\n\n[project.optional-dependencies]\n# Dev dependencies.\ndev = [\n "black>=22.3.0",\n "pre-commit>=2.19.0",\n "flake8>=4.0.1",\n "reorder-python-imports>=3.1.0",\n "pyupgrade>=2.34.0",\n]\n# Testing dependencies.\ntest = [\n "coverage>=6.4.1",\n]\n# Docs dependencies.\ndoc = []\n\n[project.scripts]\ndota2learning = "dota2learning.cli.main:app"\n\n[tool.black]\nline-length = 79\ninclude = '\\.pyi?$' # All Python files\nexclude = '''\n/(\n \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | _build\n | buck-out\n | build\n | dist\n)/\n'''\nRun Code Online (Sandbox Code Playgroud)\n现在的问题是 pip 命令“pip install”。不工作:
\n Installing build dependencies ... done\n Getting requirements to build wheel ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 Getting requirements to build wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [89 lines of output]\n configuration error: `project.license` must be valid exactly by one definition (2 matches found):\n \n - keys:\n 'file': {type: string}\n required: ['file']\n - keys:\n 'text': {type: string}\n required: ['text']\n \n DESCRIPTION:\n `Project license <https://www.python.org/dev/peps/pep-0621/#license>`_.\n \n GIVEN VALUE:\n "MIT"\n \n OFFENDING RULE: 'oneOf'\n \n DEFINITION:\n {\n "oneOf": [\n {\n "properties": {\n "file": {\n "type": "string",\n "$$description": [\n "Relative path to the file (UTF-8) which contains the license for the",\n "project."\n ]\n }\n },\n "required": [\n "file"\n ]\n },\n {\n "properties": {\n "text": {\n "type": "string",\n "$$description": [\n "The license of the project whose meaning is that of the",\n "`License field from the core metadata",\n "<https://packaging.python.org/specifications/core-metadata/#license>`_."\n ]\n }\n },\n "required": [\n "text"\n ]\n }\n ]\n }\n Traceback (most recent call last):\n File "/home/drigols/Workspace/dota2learning/environment/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in <module>\n main()\n File "/home/drigols/Workspace/dota2learning/environment/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main\n json_out['return_val'] = hook(**hook_input['kwargs'])\n File "/home/drigols/Workspace/dota2learning/environment/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 118, in get_requires_for_build_wheel\n return hook(config_settings)\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel\n return self._get_build_requires(config_settings, requirements=['wheel'])\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires\n self.run_setup()\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 484, in run_setup\n super(_BuildMetaLegacyBackend,\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup\n exec(code, locals())\n File "<string>", line 1, in <module>\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 87, in setup\n return distutils.core.setup(**attrs)\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 159, in setup\n dist.parse_config_files()\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 867, in parse_config_files\n pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 62, in apply_configuration\n config = read_configuration(filepath, True, ignore_option_errors, dist)\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 126, in read_configuration\n validate(subset, filepath)\n File "/tmp/pip-build-env-up7_m__d/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 51, in validate\n raise ValueError(f"{error}\\n{summary}") from None\n ValueError: invalid pyproject.toml config: `project.license`.\n configuration error: `project.license` must be valid exactly by one definition (2 matches found):\n \n - keys:\n 'file': {type: string}\n required: ['file']\n - keys:\n 'text': {type: string}\n required: ['text']\n \n [end of output]\n \n note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: subprocess-exited-with-error\n\n\xc3\x97 Getting requirements to build wheel did not run successfully.\n\xe2\x94\x82 exit code: 1\n\xe2\x95\xb0\xe2\x94\x80> See above for output.\n\nnote: This error originates from a subprocess, and is likely not a problem with pip.\nRun Code Online (Sandbox Code Playgroud)\n就像 pip 不知道如何从 pyproject.toml 安装依赖项,这与诗歌的方法不同,我不明白为什么。
\n问题解决了!\nA 将 pyproject.toml 编辑为:
\n[build-system]\n# Minimum requirements for the build system to execute.\nrequires = ["setuptools", "wheel"] # PEP 508 specifications.\nbuild-backend = "setuptools.build_meta"\n\n# Ignore flat-layout.\n[tool.setuptools]\npy-modules = []\n\n[project]\nname = "Dota2Learning"\nversion = "2.0.0"\ndescription = "Statistics and Machine Learning for your Dota2 Games."\nlicense = {file = "LICENSE.md"}\nreadme = "README.md"\nrequires-python = ">=3.10.0"\nauthors = [\n { name = "Rodrigo Leite", email = "drigols.creative@gmail.com" },\n]\nmaintainers = [\n { name = "Rodrigo Leite", email = "drigols.creative@gmail.com" },\n]\nkeywords = [\n "dota2",\n "statistics",\n "machine Learning",\n "deep learning",\n]\n\ndependencies = [\n "requests>=2.27.1",\n "typer>=0.4.1",\n "SQLAlchemy>=1.4.39",\n "PyMySQL>=1.0.2",\n "cryptography>=37.0.4",\n "pydantic>=1.9.1",\n "rich>=12.5.1",\n "fastapi>=0.79.0",\n "uvicorn>=0.18.2",\n]\n\n[project.optional-dependencies]\n# Dev dependencies.\ndev = [\n "black>=22.3.0",\n "pre-commit>=2.19.0",\n "flake8>=4.0.1",\n "reorder-python-imports>=3.1.0",\n "pyupgrade>=2.34.0",\n]\n# Test dependencies.\ntest = [\n "coverage>=6.4.1",\n]\n# Doc dependencies.\ndoc = []\n\n[project.scripts]\n# dota2learning = "dota2learning.cli.main:app"\n\n[tool.black]\nline-length = 79\ninclude = '\\.pyi?$' # All Python files\nexclude = '''\n/(\n \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | _build\n | buck-out\n | build\n | dist\n)/\n'''\nRun Code Online (Sandbox Code Playgroud)\n
多个问题:
1.license正如错误消息明确指出的那样,该部分下的密钥存在问题[project]。它的值应该是一个表。参见规格。
2.您向我们展示的新pyproject.toml文件缺少该[build-system]部分。如果此部分不存在,则构建前端(例如 pip)将假定该项目的构建后端是setuptools(请参阅PEP 517和PEP 518),而不是poetry/poetry-core这可能是您想要的。
3.截至今天,Poetry 与这个新的[project]部分pyproject.toml。Poetry 尚未实现这些PEP 621更改,因此无论如何都不会起作用,除非该项目将其构建后端从 Poetry 更改为另一个构建后端。
| 归档时间: |
|
| 查看次数: |
9683 次 |
| 最近记录: |