setuptools icon indicating copy to clipboard operation
setuptools copied to clipboard

[FR] Accept dynamic description to come from an attribute.

Open Lattay opened this issue 2 years ago • 4 comments

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

Lattay avatar Mar 07 '23 16:03 Lattay

Bumping for this!

[project]
name = "MyLibrary"
dynamic = ["description", "version"]

[tool.setuptools.dynamic]
description = {attr = "MyLibrary.__doc__"}
version = {attr = "MyLibrary.__version__"}

jb2170 avatar Aug 08 '23 05:08 jb2170

Good!

ZhaoQi99 avatar Jan 05 '24 04:01 ZhaoQi99

Would a PR for this issue be accepted? Or is it wise to wait for approval of some sort?

bittner avatar Feb 11 '24 23:02 bittner

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...

abravalheri avatar Feb 12 '24 10:02 abravalheri