Is `setup.cfg` deprecated?

别说谁变了你拦得住时间么 提交于 2019-12-21 04:04:48

问题


It's not completely clear to me, what is the status of setup.cfg. I am looking for solutions for my other question about PEP 508 environment markers, and I became totally confused.

To me it seems that setup.cfg is an improvement over setup.py, because it's declarative, does not involve running arbitrary code to make package installable, makes it harder to distribute malicious Python packages, makes it easier to run Python package registries etc.

So, here in setuptools docs it's mentioned that setuptools got support for setup.cfg in 30.3.0 (8 Dec 2016) version, which is quite recent. So, this has to be a new thing, right?

Not quite. distutils had support for setup.cfg for a long time, at least since 2.6. It's been 9 years already.

At the same time, here in wheel docs it's been said that setup.cfg is now deprecated, and it's preferred to provide environment markers via extras_require parameter. And it mentions setuptools, so it isn't about possibly-deprecated distutils flavor of setup.cfg.

So, what is actually going on? Is setup.cfg deprecated, or the most recent way to do things?


回答1:


Nope, setup.cfg it is not deprecated and the documentation you mention is misleading.

There were serious reasons like security related to the fact that setup.py needed execution and that's the main reason of moving away from it.

Here is the dirty trick for extras:

[options.extras_require]
pdf = ReportLab>=1.2; RXP
rest = docutils>=0.3; pack ==1.1, ==1.3



回答2:


I'd like to add a few notes on recent developments:

PEP 518 is still in provisional status, but I'm interpreting it as an invitation to use pyproject.toml instead of setup.cfg. Quoting from the PEP:

There are two issues with setup.cfg used by setuptools as a general format. One is that they are .ini files which have issues as mentioned in the configparser discussion above. The other is that the schema for that file has never been rigorously defined and thus it's unknown which format would be safe to use going forward without potentially confusing setuptools installations.

From black's documentation:

PEP 518 defines pyproject.toml as a configuration file to store build system requirements for Python projects. With the help of tools like Poetry or Flit it can fully replace the need for setup.py and setup.cfg files.

pip 19.0 implemented PEP 517 to allow projects to specify a build backend via pyproject.toml.

setuptools has an open issue titled "Merge setup.cfg spec with pyproject.toml one and deprecate setup.py and setup.cfg". However, setuptools guys have not yet decided on this. There is an open discussion on how to proceed.

Disclaimer: I feel totally lost in Python's packaging jungle myself.



来源:https://stackoverflow.com/questions/44878600/is-setup-cfg-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!