https://pantsbuild.org/ logo
#development
Title
# development
p

proud-dentist-22844

04/10/2023, 11:02 PM
I was just looking at https://github.com/pantsbuild/pants/pull/18253 which documents a shortcoming in using a custom setup.py instead of a generated setup.py. Pants could generate an editable wheel from the
python_distribution
that provides its own
setup.py
and then extract the dependencies from the
.dist-info/METADATA
file. Or better yet, just run the PEP-517 backend method
prepare_metadata_for_build_wheel
(without everything else involved in building a PEP-660 editable wheel), and extract the requirements from there. It'd be a
python_requirements
target that gets its requirements from wheel metadata instead of defining the deps used to build the wheel. I know it's kind of a wild idea. How many people write their own
setup.py
? And would the ability to extract requirements from a
setup.py
be useful? -- Mayor of crazy town, signing off. 😜
h

happy-kitchen-89482

04/10/2023, 11:14 PM
It is kinda backwards from the usual idiom
This seems to be expecting that you define requirements in setup.py/setup.cfg/etc instead of in requirements.txt, right?
That's not really how things work even outside of Pants, no?
p

proud-dentist-22844

04/10/2023, 11:17 PM
Outside of pants: All bets are off with
setup.py
because it's ultimately arbitrary code execution. I've seen some really awful
setup.py
files.
If you write your own
setup.py
then you might have to duplicate reqs in
setup.py
and
requirements.txt
or something. All the awful hacks to avoid that duplication are just that: awful.
h

happy-kitchen-89482

04/10/2023, 11:21 PM
Right, but even in that world the convention is that requirements.txt is canonical and setup.py is the copy, for publishing
p

proud-dentist-22844

04/10/2023, 11:21 PM
Now this is all hypothetical because I don't actually need custom
setup.py
to work well. I look forward to pants generating
pyproject.toml
instead because I want to see
setup.py
just go away. :P
h

happy-kitchen-89482

04/10/2023, 11:21 PM
I think the better solution is the long-awaited feature of partially-generating setup.py/pyproject.toml/whatever
Basically now it's binary - either pants generates it or you author it
p

proud-dentist-22844

04/10/2023, 11:22 PM
Hehe. Exactly
h

happy-kitchen-89482

04/10/2023, 11:22 PM
Unless you write a complicated plugin
but what we really want is for Pants to generate all the data that goes into those files, but lets you augment it/replace it
1
So you can have Pants generate the requirements even if you want to override the sources, say
p

proud-dentist-22844

04/10/2023, 11:24 PM
This was my crazy idea about how pants could introspect a custom
setup.py
. probably not worth it. But an interesting mental exercise.
Right, but even in that world the convention is that requirements.txt is canonical and setup.py is the copy, for publishing
That world doesn't make sense to me. That is the most succinct explanation I've ever seen for why someone might want the two files to differ, but I still think that's confusing and leads to one or the other bitrotting. So, it is conceivable that someone would only have the one file. Luckily the days of
setup.py
are numbered, so my crazy hacky idea shouldn't ever be necessary.
h

happy-kitchen-89482

04/10/2023, 11:41 PM
Oh I definitely agree that having two files is not a good idea, I'm just pushing back gently on the idea that the publish metadata would be canonical, rather than being generated from something else
👍 1