在pyproject.toml中添加system_platform限定符报错,如何解决?
问题:pyproject.toml中PEP508依赖限定符验证失败
我在空目录中有一个基础的pyproject.toml文件,内容如下:
[build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "test-virtualenvwrapper" version = "0.1.0" dependencies = [ 'virtualenvwrapper ; system_platform == "linux"', 'virtualenvwrapper-win ; system_platform == "win32"', ]
运行pip install -e .时出现如下错误:
(dev38) go|c:\srv\tmp\pyprojplat> pip install -e . Looking in indexes: https://pypi.org/simple, http://pypi.norsktest.xyz Obtaining file:///C:/srv/tmp/pyprojplat Installing build dependencies ... done Checking if build backend supports build_editable ... done Getting requirements to build editable ... error error: subprocess-exited-with-error × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> [48 lines of output] configuration error: `project.dependencies[{data__dependencies_x}]` must be pep508 DESCRIPTION: Project dependency specification according to PEP 508 GIVEN VALUE: "virtualenvwrapper ; system_platform == \"linux\"" OFFENDING RULE: 'format' DEFINITION: { "$id": "#/definitions/dependency", "title": "Dependency", "type": "string", "format": "pep508" } Traceback (most recent call last): File "C:\srv\venv\dev38\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\srv\venv\dev38\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\srv\venv\dev38\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 132, in get_requires_for_build_editable return hook(config_settings) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\build_meta.py", line 447, in get_requires_for_build_editable return self.get_requires_for_build_wheel(config_settings) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires self.run_setup() File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup exec(code, locals()) File "<string>", line 1, in <module> File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\__init__.py", line 108, in setup return distutils.core.setup(**attrs) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 159, in setup dist.parse_config_files() File "C:\srv\venv\dev38\lib\site-packages\_virtualenv.py", line 21, in parse_config_files result = old_parse_config_files(self, *args, **kwargs) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\dist.py", line 885, in parse_config_files pyprojecttoml.apply_configuration(self, filename, ignore_option_errors) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\config\pyprojecttoml.py", line 62, in apply_configuration config = read_configuration(filepath, True, ignore_option_errors, dist) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\config\pyprojecttoml.py", line 126, in read_configuration validate(subset, filepath) File "C:\Users\me\AppData\Local\Temp\pip-build-env-2lncmkj6\overlay\Lib\site-packages\setuptools\config\pyprojecttoml.py", line 51, in validate raise ValueError(f"{error}\n{summary}") from None ValueError: invalid pyproject.toml config: `project.dependencies[{data__dependencies_x}]`. configuration error: `project.dependencies[{data__dependencies_x}]` must be pep508 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build editable did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip. (dev38) go|c:\srv\tmp\pyprojplat>
我认为自己的system_platform限定符写法符合PEP508规范,请问问题出在哪里?
解答
问题出在依赖声明中分号前的空格。PEP508规范要求分号和前面的包名之间不能有多余空格,必须紧挨着写。
修改后的pyproject.toml依赖部分应该是这样:
dependencies = [ 'virtualenvwrapper; system_platform == "linux"', 'virtualenvwrapper-win; system_platform == "win32"', ]
去掉分号前的所有空格后,setuptools的PEP508验证就能通过了。
内容的提问来源于stack exchange,提问作者thebjorn
相关产品推荐
相关产品推荐

