Dynamically modifiy requirements through plugin #4712
Unanswered
staley-arlut
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What is the correct way to have a setuptools
distutils.commandsplugin dynamically add requirements and optional requirements?I have a hack of a solution that involves manipulating the
install_requiresandextras_requireattributes on thedistribution/distribution.metadataobjects during my custom command'sfinalize_optionsstep. This seems to work as far back as setuptools v39.2.0, but has recently stopped working as of v75.2.0.For context, my use case is due to Google Protocol Buffers(protobuf):
The plugin command runs the protobuf compiler (protoc) at build time in order to generate python source modules. Unfortunately, using protobuf makes packaging python wheels difficult due to needing to match the runtime package
protobufversion with the version of the protobuf compiler (protoc) used at build time.I try to keep my source code compatible with as wide a range of versions as I can. For instance, I've written package code that can work with
protobufversions 3.5 through 5.x. However whenprotocgenerates it's python modules, it inherently reduces the versions of theprotobufpackage my wheel is compatible with. It even seems like for now (pre-2025), the protobuf developers want you to match the versions of the generator and runtime library exactly (see (cross-version-runtime-guarantee)[https://protobuf.dev/support/cross-version-runtime-guarantee]).So, my solution to this has been to have my setuptools plugin dynamically lock the version requirement of the
protobufruntime package based on the version ofprotocit used to generate the wheel. I don't love this solution, because it means you cannot install two wheels that were built with differentprotocversions to the same environment, but I'm not sure how else to solve this problem.Beta Was this translation helpful? Give feedback.
All reactions