setuptools
setuptools copied to clipboard
[FR] Accept dynamic description to come from an attribute.
What's the problem this feature will solve?
It would make it possible to keep the package description in sync with the package docstring.
Describe the solution you'd like
I propose to accept the following directives:
setup.cfg
description = attr: mypackage.__doc__
pyproject.toml
[tool.setuptools.dynamic]
description = {attr = "mypackage.__doc__"}
Alternative Solutions
The current option is either to rely on setup.py or to manually keep the __doc__ and description in sync which is prone to error.
Additional context
I think this feature would be fairly easy to implement, as it is mostly a copy-paste from version. I tried to implement it myself, but I did not find what to do with the generated _validate_pyproject code.
Moreover, this feature is found in flit.
Code of Conduct
- [X] I agree to follow the PSF Code of Conduct
Bumping for this!
[project]
name = "MyLibrary"
dynamic = ["description", "version"]
[tool.setuptools.dynamic]
description = {attr = "MyLibrary.__doc__"}
version = {attr = "MyLibrary.__version__"}
Good!
Would a PR for this issue be accepted? Or is it wise to wait for approval of some sort?
Hi @bittner, yes a PR would be appreciated, thank you very much ❤️.
2 things that might be important to consider are the following:
- It is strongly preferable to parse the AST using
ast, so that the modules are not evaluated in build time[^1] - Docstrings are a bit different than regular attributes. If there is too much branching in the code and increase complexity, maybe we can also consider defining a new kind of directive.
[^1]: Not evaluating the modules in build time is a good thing, because runtime dependencies may not be available...